| 1 | /*	$NetBSD: digest.h,v 1.2 2018/04/06 18:59:00 christos Exp $	*/ | 
| 2 | /* $OpenBSD: digest.h,v 1.8 2017/05/08 22:57:38 djm Exp $ */ | 
| 3 | /* | 
| 4 |  * Copyright (c) 2013 Damien Miller <djm@mindrot.org> | 
| 5 |  * | 
| 6 |  * Permission to use, copy, modify, and distribute this software for any | 
| 7 |  * purpose with or without fee is hereby granted, provided that the above | 
| 8 |  * copyright notice and this permission notice appear in all copies. | 
| 9 |  * | 
| 10 |  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 
| 11 |  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 
| 12 |  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 
| 13 |  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 
| 14 |  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 
| 15 |  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 
| 16 |  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 
| 17 |  */ | 
| 18 |  | 
| 19 | #ifndef _DIGEST_H | 
| 20 | #define _DIGEST_H | 
| 21 |  | 
| 22 | /* Maximum digest output length */ | 
| 23 | #define SSH_DIGEST_MAX_LENGTH	64 | 
| 24 |  | 
| 25 | /* Digest algorithms */ | 
| 26 | #define SSH_DIGEST_MD5		0 | 
| 27 | #define SSH_DIGEST_SHA1		1 | 
| 28 | #define SSH_DIGEST_SHA256	2 | 
| 29 | #define SSH_DIGEST_SHA384	3 | 
| 30 | #define SSH_DIGEST_SHA512	4 | 
| 31 | #define SSH_DIGEST_MAX		5 | 
| 32 |  | 
| 33 | struct sshbuf; | 
| 34 | struct ssh_digest_ctx; | 
| 35 |  | 
| 36 | /* Looks up a digest algorithm by name */ | 
| 37 | int ssh_digest_alg_by_name(const char *name); | 
| 38 |  | 
| 39 | /* Returns the algorithm name for a digest identifier */ | 
| 40 | const char *ssh_digest_alg_name(int alg); | 
| 41 |  | 
| 42 | /* Returns the algorithm's digest length in bytes or 0 for invalid algorithm */ | 
| 43 | size_t ssh_digest_bytes(int alg); | 
| 44 |  | 
| 45 | /* Returns the block size of the digest, e.g. for implementing HMAC */ | 
| 46 | size_t ssh_digest_blocksize(struct ssh_digest_ctx *ctx); | 
| 47 |  | 
| 48 | /* Copies internal state of digest of 'from' to 'to' */ | 
| 49 | int ssh_digest_copy_state(struct ssh_digest_ctx *from, | 
| 50 |     struct ssh_digest_ctx *to); | 
| 51 |  | 
| 52 | /* One-shot API */ | 
| 53 | int ssh_digest_memory(int alg, const void *m, size_t mlen, | 
| 54 |     u_char *d, size_t dlen) | 
| 55 | 	__attribute__((__bounded__(__buffer__, 2, 3))) | 
| 56 | 	__attribute__((__bounded__(__buffer__, 4, 5))); | 
| 57 | int ssh_digest_buffer(int alg, const struct sshbuf *b, u_char *d, size_t dlen) | 
| 58 | 	__attribute__((__bounded__(__buffer__, 3, 4))); | 
| 59 |  | 
| 60 | /* Update API */ | 
| 61 | struct ssh_digest_ctx *ssh_digest_start(int alg); | 
| 62 | int ssh_digest_update(struct ssh_digest_ctx *ctx, const void *m, size_t mlen) | 
| 63 | 	__attribute__((__bounded__(__buffer__, 2, 3))); | 
| 64 | int ssh_digest_update_buffer(struct ssh_digest_ctx *ctx, | 
| 65 |     const struct sshbuf *b); | 
| 66 | int ssh_digest_final(struct ssh_digest_ctx *ctx, u_char *d, size_t dlen) | 
| 67 | 	__attribute__((__bounded__(__buffer__, 2, 3))); | 
| 68 | void ssh_digest_free(struct ssh_digest_ctx *ctx); | 
| 69 |  | 
| 70 | #endif /* _DIGEST_H */ | 
| 71 |  | 
| 72 |  |