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