xref: /dflybsd-src/crypto/openssh/hmac.h (revision 36e94dc5bac047676e52d6d94a07db1b31c653e3)
1*36e94dc5SPeter Avalos /* $OpenBSD: hmac.h,v 1.9 2014/06/24 01:13:21 djm Exp $ */
2*36e94dc5SPeter Avalos /*
3*36e94dc5SPeter Avalos  * Copyright (c) 2014 Markus Friedl.  All rights reserved.
4*36e94dc5SPeter Avalos  *
5*36e94dc5SPeter Avalos  * Permission to use, copy, modify, and distribute this software for any
6*36e94dc5SPeter Avalos  * purpose with or without fee is hereby granted, provided that the above
7*36e94dc5SPeter Avalos  * copyright notice and this permission notice appear in all copies.
8*36e94dc5SPeter Avalos  *
9*36e94dc5SPeter Avalos  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*36e94dc5SPeter Avalos  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*36e94dc5SPeter Avalos  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*36e94dc5SPeter Avalos  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*36e94dc5SPeter Avalos  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*36e94dc5SPeter Avalos  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*36e94dc5SPeter Avalos  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*36e94dc5SPeter Avalos  */
17*36e94dc5SPeter Avalos 
18*36e94dc5SPeter Avalos #ifndef _HMAC_H
19*36e94dc5SPeter Avalos #define _HMAC_H
20*36e94dc5SPeter Avalos 
21*36e94dc5SPeter Avalos /* Returns the algorithm's digest length in bytes or 0 for invalid algorithm */
22*36e94dc5SPeter Avalos size_t ssh_hmac_bytes(int alg);
23*36e94dc5SPeter Avalos 
24*36e94dc5SPeter Avalos struct sshbuf;
25*36e94dc5SPeter Avalos struct ssh_hmac_ctx;
26*36e94dc5SPeter Avalos struct ssh_hmac_ctx *ssh_hmac_start(int alg);
27*36e94dc5SPeter Avalos 
28*36e94dc5SPeter Avalos /* Sets the state of the HMAC or resets the state if key == NULL */
29*36e94dc5SPeter Avalos int ssh_hmac_init(struct ssh_hmac_ctx *ctx, const void *key, size_t klen)
30*36e94dc5SPeter Avalos 	__attribute__((__bounded__(__buffer__, 2, 3)));
31*36e94dc5SPeter Avalos int ssh_hmac_update(struct ssh_hmac_ctx *ctx, const void *m, size_t mlen)
32*36e94dc5SPeter Avalos 	__attribute__((__bounded__(__buffer__, 2, 3)));
33*36e94dc5SPeter Avalos int ssh_hmac_update_buffer(struct ssh_hmac_ctx *ctx, const struct sshbuf *b);
34*36e94dc5SPeter Avalos int ssh_hmac_final(struct ssh_hmac_ctx *ctx, u_char *d, size_t dlen)
35*36e94dc5SPeter Avalos 	__attribute__((__bounded__(__buffer__, 2, 3)));
36*36e94dc5SPeter Avalos void ssh_hmac_free(struct ssh_hmac_ctx *ctx);
37*36e94dc5SPeter Avalos 
38*36e94dc5SPeter Avalos #endif /* _HMAC_H */
39