diff options
Diffstat (limited to 'digest-libc.c')
-rw-r--r-- | digest-libc.c | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/digest-libc.c b/digest-libc.c index 1b4423a05..a216e784e 100644 --- a/digest-libc.c +++ b/digest-libc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: digest-libc.c,v 1.3 2014/06/24 01:13:21 djm Exp $ */ | 1 | /* $OpenBSD: digest-libc.c,v 1.4 2014/12/21 22:27:56 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2013 Damien Miller <djm@mindrot.org> | 3 | * Copyright (c) 2013 Damien Miller <djm@mindrot.org> |
4 | * Copyright (c) 2014 Markus Friedl. All rights reserved. | 4 | * Copyright (c) 2014 Markus Friedl. All rights reserved. |
@@ -18,15 +18,19 @@ | |||
18 | 18 | ||
19 | #include "includes.h" | 19 | #include "includes.h" |
20 | 20 | ||
21 | #ifndef WITH_OPENSSL | ||
22 | |||
21 | #include <sys/types.h> | 23 | #include <sys/types.h> |
22 | #include <limits.h> | 24 | #include <limits.h> |
23 | #include <stdlib.h> | 25 | #include <stdlib.h> |
24 | #include <string.h> | 26 | #include <string.h> |
25 | 27 | ||
28 | #if 0 | ||
26 | #include <md5.h> | 29 | #include <md5.h> |
27 | #include <rmd160.h> | 30 | #include <rmd160.h> |
28 | #include <sha1.h> | 31 | #include <sha1.h> |
29 | #include <sha2.h> | 32 | #include <sha2.h> |
33 | #endif | ||
30 | 34 | ||
31 | #include "ssherr.h" | 35 | #include "ssherr.h" |
32 | #include "sshbuf.h" | 36 | #include "sshbuf.h" |
@@ -89,30 +93,30 @@ const struct ssh_digest digests[SSH_DIGEST_MAX] = { | |||
89 | "SHA256", | 93 | "SHA256", |
90 | SHA256_BLOCK_LENGTH, | 94 | SHA256_BLOCK_LENGTH, |
91 | SHA256_DIGEST_LENGTH, | 95 | SHA256_DIGEST_LENGTH, |
92 | sizeof(SHA2_CTX), | 96 | sizeof(SHA256_CTX), |
93 | (md_init_fn *) SHA256Init, | 97 | (md_init_fn *) SHA256_Init, |
94 | (md_update_fn *) SHA256Update, | 98 | (md_update_fn *) SHA256_Update, |
95 | (md_final_fn *) SHA256Final | 99 | (md_final_fn *) SHA256_Final |
96 | }, | 100 | }, |
97 | { | 101 | { |
98 | SSH_DIGEST_SHA384, | 102 | SSH_DIGEST_SHA384, |
99 | "SHA384", | 103 | "SHA384", |
100 | SHA384_BLOCK_LENGTH, | 104 | SHA384_BLOCK_LENGTH, |
101 | SHA384_DIGEST_LENGTH, | 105 | SHA384_DIGEST_LENGTH, |
102 | sizeof(SHA2_CTX), | 106 | sizeof(SHA384_CTX), |
103 | (md_init_fn *) SHA384Init, | 107 | (md_init_fn *) SHA384_Init, |
104 | (md_update_fn *) SHA384Update, | 108 | (md_update_fn *) SHA384_Update, |
105 | (md_final_fn *) SHA384Final | 109 | (md_final_fn *) SHA384_Final |
106 | }, | 110 | }, |
107 | { | 111 | { |
108 | SSH_DIGEST_SHA512, | 112 | SSH_DIGEST_SHA512, |
109 | "SHA512", | 113 | "SHA512", |
110 | SHA512_BLOCK_LENGTH, | 114 | SHA512_BLOCK_LENGTH, |
111 | SHA512_DIGEST_LENGTH, | 115 | SHA512_DIGEST_LENGTH, |
112 | sizeof(SHA2_CTX), | 116 | sizeof(SHA512_CTX), |
113 | (md_init_fn *) SHA512Init, | 117 | (md_init_fn *) SHA512_Init, |
114 | (md_update_fn *) SHA512Update, | 118 | (md_update_fn *) SHA512_Update, |
115 | (md_final_fn *) SHA512Final | 119 | (md_final_fn *) SHA512_Final |
116 | } | 120 | } |
117 | }; | 121 | }; |
118 | 122 | ||
@@ -126,6 +130,26 @@ ssh_digest_by_alg(int alg) | |||
126 | return &(digests[alg]); | 130 | return &(digests[alg]); |
127 | } | 131 | } |
128 | 132 | ||
133 | int | ||
134 | ssh_digest_alg_by_name(const char *name) | ||
135 | { | ||
136 | int alg; | ||
137 | |||
138 | for (alg = 0; alg < SSH_DIGEST_MAX; alg++) { | ||
139 | if (strcasecmp(name, digests[alg].name) == 0) | ||
140 | return digests[alg].id; | ||
141 | } | ||
142 | return -1; | ||
143 | } | ||
144 | |||
145 | const char * | ||
146 | ssh_digest_alg_name(int alg) | ||
147 | { | ||
148 | const struct ssh_digest *digest = ssh_digest_by_alg(alg); | ||
149 | |||
150 | return digest == NULL ? NULL : digest->name; | ||
151 | } | ||
152 | |||
129 | size_t | 153 | size_t |
130 | ssh_digest_bytes(int alg) | 154 | ssh_digest_bytes(int alg) |
131 | { | 155 | { |
@@ -237,3 +261,4 @@ ssh_digest_buffer(int alg, const struct sshbuf *b, u_char *d, size_t dlen) | |||
237 | { | 261 | { |
238 | return ssh_digest_memory(alg, sshbuf_ptr(b), sshbuf_len(b), d, dlen); | 262 | return ssh_digest_memory(alg, sshbuf_ptr(b), sshbuf_len(b), d, dlen); |
239 | } | 263 | } |
264 | #endif /* !WITH_OPENSSL */ | ||