Damien Miller | b3051d0 | 2014-01-10 10:58:53 +1100 | [diff] [blame] | 1 | /* $OpenBSD: ssh-rsa.c,v 1.50 2014/01/09 23:20:00 djm Exp $ */ |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 2 | /* |
Darren Tucker | a251f80 | 2003-06-22 20:45:15 +1000 | [diff] [blame] | 3 | * Copyright (c) 2000, 2003 Markus Friedl <markus@openbsd.org> |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 4 | * |
Darren Tucker | a251f80 | 2003-06-22 20:45:15 +1000 | [diff] [blame] | 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. |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 8 | * |
Darren Tucker | a251f80 | 2003-06-22 20:45:15 +1000 | [diff] [blame] | 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. |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 16 | */ |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 17 | |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 18 | #include "includes.h" |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 19 | |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 20 | #include <sys/types.h> |
| 21 | |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 22 | #include <openssl/evp.h> |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 23 | #include <openssl/err.h> |
| 24 | |
Damien Miller | ded319c | 2006-09-01 15:38:36 +1000 | [diff] [blame] | 25 | #include <stdarg.h> |
Damien Miller | e3476ed | 2006-07-24 14:13:33 +1000 | [diff] [blame] | 26 | #include <string.h> |
| 27 | |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 28 | #include "xmalloc.h" |
| 29 | #include "log.h" |
| 30 | #include "buffer.h" |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 31 | #include "key.h" |
Ben Lindstrom | 60a4381 | 2001-03-29 00:32:56 +0000 | [diff] [blame] | 32 | #include "compat.h" |
Damien Miller | 8a0268f | 2010-07-16 13:57:51 +1000 | [diff] [blame] | 33 | #include "misc.h" |
Ben Lindstrom | 03f3932 | 2002-04-02 20:43:11 +0000 | [diff] [blame] | 34 | #include "ssh.h" |
Damien Miller | b3051d0 | 2014-01-10 10:58:53 +1100 | [diff] [blame] | 35 | #include "digest.h" |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 36 | |
Ben Lindstrom | 93576d9 | 2002-12-23 02:06:19 +0000 | [diff] [blame] | 37 | static int openssh_RSA_verify(int, u_char *, u_int, u_char *, u_int, RSA *); |
Ben Lindstrom | 0deb5d9 | 2002-08-20 18:40:03 +0000 | [diff] [blame] | 38 | |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 39 | /* RSASSA-PKCS1-v1_5 (PKCS #1 v2.0 signature) with SHA1 */ |
| 40 | int |
Damien Miller | f58b58c | 2003-11-17 21:18:23 +1100 | [diff] [blame] | 41 | ssh_rsa_sign(const Key *key, u_char **sigp, u_int *lenp, |
| 42 | const u_char *data, u_int datalen) |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 43 | { |
Damien Miller | b3051d0 | 2014-01-10 10:58:53 +1100 | [diff] [blame] | 44 | int hash_alg; |
| 45 | u_char digest[SSH_DIGEST_MAX_LENGTH], *sig; |
Ben Lindstrom | 46c1622 | 2000-12-22 01:43:59 +0000 | [diff] [blame] | 46 | u_int slen, dlen, len; |
Ben Lindstrom | 425fb02 | 2001-03-29 00:31:20 +0000 | [diff] [blame] | 47 | int ok, nid; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 48 | Buffer b; |
| 49 | |
Damien Miller | 3e19295 | 2013-12-29 17:47:50 +1100 | [diff] [blame] | 50 | if (key == NULL || key_type_plain(key->type) != KEY_RSA || |
| 51 | key->rsa == NULL) { |
| 52 | error("%s: no RSA key", __func__); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 53 | return -1; |
| 54 | } |
Damien Miller | 3e19295 | 2013-12-29 17:47:50 +1100 | [diff] [blame] | 55 | |
Damien Miller | b3051d0 | 2014-01-10 10:58:53 +1100 | [diff] [blame] | 56 | /* hash the data */ |
| 57 | hash_alg = SSH_DIGEST_SHA1; |
Damien Miller | 324541e | 2013-12-31 12:25:40 +1100 | [diff] [blame] | 58 | nid = NID_sha1; |
Damien Miller | b3051d0 | 2014-01-10 10:58:53 +1100 | [diff] [blame] | 59 | if ((dlen = ssh_digest_bytes(hash_alg)) == 0) { |
| 60 | error("%s: bad hash algorithm %d", __func__, hash_alg); |
Ben Lindstrom | 425fb02 | 2001-03-29 00:31:20 +0000 | [diff] [blame] | 61 | return -1; |
| 62 | } |
Damien Miller | b3051d0 | 2014-01-10 10:58:53 +1100 | [diff] [blame] | 63 | if (ssh_digest_memory(hash_alg, data, datalen, |
| 64 | digest, sizeof(digest)) != 0) { |
| 65 | error("%s: ssh_digest_memory failed", __func__); |
| 66 | return -1; |
| 67 | } |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 68 | |
Ben Lindstrom | 425fb02 | 2001-03-29 00:31:20 +0000 | [diff] [blame] | 69 | slen = RSA_size(key->rsa); |
| 70 | sig = xmalloc(slen); |
| 71 | |
| 72 | ok = RSA_sign(nid, digest, dlen, sig, &len, key->rsa); |
Damien Miller | c516e92 | 2002-02-05 11:53:43 +1100 | [diff] [blame] | 73 | memset(digest, 'd', sizeof(digest)); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 74 | |
| 75 | if (ok != 1) { |
| 76 | int ecode = ERR_get_error(); |
Damien Miller | 9096740 | 2006-03-26 14:07:26 +1100 | [diff] [blame] | 77 | |
Damien Miller | 3e19295 | 2013-12-29 17:47:50 +1100 | [diff] [blame] | 78 | error("%s: RSA_sign failed: %s", __func__, |
Ben Lindstrom | 5c38552 | 2002-06-23 21:23:20 +0000 | [diff] [blame] | 79 | ERR_error_string(ecode, NULL)); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 80 | free(sig); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 81 | return -1; |
| 82 | } |
| 83 | if (len < slen) { |
Ben Lindstrom | 0e50d84 | 2002-08-20 18:39:14 +0000 | [diff] [blame] | 84 | u_int diff = slen - len; |
Ben Lindstrom | 5c38552 | 2002-06-23 21:23:20 +0000 | [diff] [blame] | 85 | debug("slen %u > len %u", slen, len); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 86 | memmove(sig + diff, sig, len); |
| 87 | memset(sig, 0, diff); |
| 88 | } else if (len > slen) { |
Damien Miller | 3e19295 | 2013-12-29 17:47:50 +1100 | [diff] [blame] | 89 | error("%s: slen %u slen2 %u", __func__, slen, len); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 90 | free(sig); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 91 | return -1; |
| 92 | } |
| 93 | /* encode signature */ |
| 94 | buffer_init(&b); |
| 95 | buffer_put_cstring(&b, "ssh-rsa"); |
| 96 | buffer_put_string(&b, sig, slen); |
| 97 | len = buffer_len(&b); |
Ben Lindstrom | 2bf759c | 2002-07-07 22:13:31 +0000 | [diff] [blame] | 98 | if (lenp != NULL) |
| 99 | *lenp = len; |
| 100 | if (sigp != NULL) { |
| 101 | *sigp = xmalloc(len); |
| 102 | memcpy(*sigp, buffer_ptr(&b), len); |
| 103 | } |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 104 | buffer_free(&b); |
| 105 | memset(sig, 's', slen); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 106 | free(sig); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 107 | |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | int |
Damien Miller | f58b58c | 2003-11-17 21:18:23 +1100 | [diff] [blame] | 112 | ssh_rsa_verify(const Key *key, const u_char *signature, u_int signaturelen, |
| 113 | const u_char *data, u_int datalen) |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 114 | { |
| 115 | Buffer b; |
Damien Miller | b3051d0 | 2014-01-10 10:58:53 +1100 | [diff] [blame] | 116 | int hash_alg; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 117 | char *ktype; |
Damien Miller | b3051d0 | 2014-01-10 10:58:53 +1100 | [diff] [blame] | 118 | u_char digest[SSH_DIGEST_MAX_LENGTH], *sigblob; |
Ben Lindstrom | ceae9d1 | 2002-06-06 20:55:04 +0000 | [diff] [blame] | 119 | u_int len, dlen, modlen; |
Damien Miller | b3051d0 | 2014-01-10 10:58:53 +1100 | [diff] [blame] | 120 | int rlen, ret; |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 121 | |
Damien Miller | 3e19295 | 2013-12-29 17:47:50 +1100 | [diff] [blame] | 122 | if (key == NULL || key_type_plain(key->type) != KEY_RSA || |
| 123 | key->rsa == NULL) { |
| 124 | error("%s: no RSA key", __func__); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 125 | return -1; |
| 126 | } |
Damien Miller | 3e19295 | 2013-12-29 17:47:50 +1100 | [diff] [blame] | 127 | |
Ben Lindstrom | 03f3932 | 2002-04-02 20:43:11 +0000 | [diff] [blame] | 128 | if (BN_num_bits(key->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) { |
Damien Miller | 3e19295 | 2013-12-29 17:47:50 +1100 | [diff] [blame] | 129 | error("%s: RSA modulus too small: %d < minimum %d bits", |
| 130 | __func__, BN_num_bits(key->rsa->n), |
| 131 | SSH_RSA_MINIMUM_MODULUS_SIZE); |
Ben Lindstrom | bf555ba | 2001-01-18 02:04:35 +0000 | [diff] [blame] | 132 | return -1; |
| 133 | } |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 134 | buffer_init(&b); |
Ben Lindstrom | 9e0ddd4 | 2001-09-18 05:41:19 +0000 | [diff] [blame] | 135 | buffer_append(&b, signature, signaturelen); |
Damien Miller | da108ec | 2010-08-31 22:36:39 +1000 | [diff] [blame] | 136 | ktype = buffer_get_cstring(&b, NULL); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 137 | if (strcmp("ssh-rsa", ktype) != 0) { |
Damien Miller | 3e19295 | 2013-12-29 17:47:50 +1100 | [diff] [blame] | 138 | error("%s: cannot handle type %s", __func__, ktype); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 139 | buffer_free(&b); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 140 | free(ktype); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 141 | return -1; |
| 142 | } |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 143 | free(ktype); |
Ben Lindstrom | 9e0ddd4 | 2001-09-18 05:41:19 +0000 | [diff] [blame] | 144 | sigblob = buffer_get_string(&b, &len); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 145 | rlen = buffer_len(&b); |
| 146 | buffer_free(&b); |
Ben Lindstrom | 1c37c6a | 2001-12-06 18:00:18 +0000 | [diff] [blame] | 147 | if (rlen != 0) { |
Damien Miller | 3e19295 | 2013-12-29 17:47:50 +1100 | [diff] [blame] | 148 | error("%s: remaining bytes in signature %d", __func__, rlen); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 149 | free(sigblob); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 150 | return -1; |
| 151 | } |
Ben Lindstrom | ceae9d1 | 2002-06-06 20:55:04 +0000 | [diff] [blame] | 152 | /* RSA_verify expects a signature of RSA_size */ |
| 153 | modlen = RSA_size(key->rsa); |
| 154 | if (len > modlen) { |
Damien Miller | 3e19295 | 2013-12-29 17:47:50 +1100 | [diff] [blame] | 155 | error("%s: len %u > modlen %u", __func__, len, modlen); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 156 | free(sigblob); |
Ben Lindstrom | ceae9d1 | 2002-06-06 20:55:04 +0000 | [diff] [blame] | 157 | return -1; |
| 158 | } else if (len < modlen) { |
Ben Lindstrom | 0e50d84 | 2002-08-20 18:39:14 +0000 | [diff] [blame] | 159 | u_int diff = modlen - len; |
Damien Miller | 3e19295 | 2013-12-29 17:47:50 +1100 | [diff] [blame] | 160 | debug("%s: add padding: modlen %u > len %u", __func__, |
Ben Lindstrom | ceae9d1 | 2002-06-06 20:55:04 +0000 | [diff] [blame] | 161 | modlen, len); |
Damien Miller | 3681209 | 2006-03-26 14:22:47 +1100 | [diff] [blame] | 162 | sigblob = xrealloc(sigblob, 1, modlen); |
Ben Lindstrom | ceae9d1 | 2002-06-06 20:55:04 +0000 | [diff] [blame] | 163 | memmove(sigblob + diff, sigblob, len); |
| 164 | memset(sigblob, 0, diff); |
| 165 | len = modlen; |
| 166 | } |
Damien Miller | b3051d0 | 2014-01-10 10:58:53 +1100 | [diff] [blame] | 167 | /* hash the data */ |
| 168 | hash_alg = SSH_DIGEST_SHA1; |
| 169 | if ((dlen = ssh_digest_bytes(hash_alg)) == 0) { |
| 170 | error("%s: bad hash algorithm %d", __func__, hash_alg); |
Ben Lindstrom | 425fb02 | 2001-03-29 00:31:20 +0000 | [diff] [blame] | 171 | return -1; |
| 172 | } |
Damien Miller | b3051d0 | 2014-01-10 10:58:53 +1100 | [diff] [blame] | 173 | if (ssh_digest_memory(hash_alg, data, datalen, |
| 174 | digest, sizeof(digest)) != 0) { |
| 175 | error("%s: ssh_digest_memory failed", __func__); |
| 176 | return -1; |
| 177 | } |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 178 | |
Damien Miller | b3051d0 | 2014-01-10 10:58:53 +1100 | [diff] [blame] | 179 | ret = openssh_RSA_verify(hash_alg, digest, dlen, sigblob, len, |
| 180 | key->rsa); |
Damien Miller | c516e92 | 2002-02-05 11:53:43 +1100 | [diff] [blame] | 181 | memset(digest, 'd', sizeof(digest)); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 182 | memset(sigblob, 's', len); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 183 | free(sigblob); |
Damien Miller | 3e19295 | 2013-12-29 17:47:50 +1100 | [diff] [blame] | 184 | debug("%s: signature %scorrect", __func__, (ret == 0) ? "in" : ""); |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 185 | return ret; |
| 186 | } |
Ben Lindstrom | 0deb5d9 | 2002-08-20 18:40:03 +0000 | [diff] [blame] | 187 | |
| 188 | /* |
| 189 | * See: |
| 190 | * http://www.rsasecurity.com/rsalabs/pkcs/pkcs-1/ |
| 191 | * ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2-1.asn |
| 192 | */ |
| 193 | /* |
| 194 | * id-sha1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) |
| 195 | * oiw(14) secsig(3) algorithms(2) 26 } |
| 196 | */ |
| 197 | static const u_char id_sha1[] = { |
| 198 | 0x30, 0x21, /* type Sequence, length 0x21 (33) */ |
| 199 | 0x30, 0x09, /* type Sequence, length 0x09 */ |
| 200 | 0x06, 0x05, /* type OID, length 0x05 */ |
| 201 | 0x2b, 0x0e, 0x03, 0x02, 0x1a, /* id-sha1 OID */ |
| 202 | 0x05, 0x00, /* NULL */ |
| 203 | 0x04, 0x14 /* Octet string, length 0x14 (20), followed by sha1 hash */ |
| 204 | }; |
Ben Lindstrom | 0deb5d9 | 2002-08-20 18:40:03 +0000 | [diff] [blame] | 205 | |
| 206 | static int |
Damien Miller | b3051d0 | 2014-01-10 10:58:53 +1100 | [diff] [blame] | 207 | openssh_RSA_verify(int hash_alg, u_char *hash, u_int hashlen, |
Ben Lindstrom | 0deb5d9 | 2002-08-20 18:40:03 +0000 | [diff] [blame] | 208 | u_char *sigbuf, u_int siglen, RSA *rsa) |
| 209 | { |
Damien Miller | f7c2391 | 2002-09-04 16:39:48 +1000 | [diff] [blame] | 210 | u_int ret, rsasize, oidlen = 0, hlen = 0; |
Damien Miller | 4e8285e | 2010-08-03 16:04:03 +1000 | [diff] [blame] | 211 | int len, oidmatch, hashmatch; |
Ben Lindstrom | 0deb5d9 | 2002-08-20 18:40:03 +0000 | [diff] [blame] | 212 | const u_char *oid = NULL; |
| 213 | u_char *decrypted = NULL; |
| 214 | |
| 215 | ret = 0; |
Damien Miller | b3051d0 | 2014-01-10 10:58:53 +1100 | [diff] [blame] | 216 | switch (hash_alg) { |
| 217 | case SSH_DIGEST_SHA1: |
Ben Lindstrom | 0deb5d9 | 2002-08-20 18:40:03 +0000 | [diff] [blame] | 218 | oid = id_sha1; |
| 219 | oidlen = sizeof(id_sha1); |
| 220 | hlen = 20; |
| 221 | break; |
Ben Lindstrom | 0deb5d9 | 2002-08-20 18:40:03 +0000 | [diff] [blame] | 222 | default: |
| 223 | goto done; |
Ben Lindstrom | 0deb5d9 | 2002-08-20 18:40:03 +0000 | [diff] [blame] | 224 | } |
| 225 | if (hashlen != hlen) { |
| 226 | error("bad hashlen"); |
| 227 | goto done; |
| 228 | } |
| 229 | rsasize = RSA_size(rsa); |
| 230 | if (siglen == 0 || siglen > rsasize) { |
| 231 | error("bad siglen"); |
| 232 | goto done; |
| 233 | } |
| 234 | decrypted = xmalloc(rsasize); |
| 235 | if ((len = RSA_public_decrypt(siglen, sigbuf, decrypted, rsa, |
| 236 | RSA_PKCS1_PADDING)) < 0) { |
| 237 | error("RSA_public_decrypt failed: %s", |
| 238 | ERR_error_string(ERR_get_error(), NULL)); |
| 239 | goto done; |
| 240 | } |
Damien Miller | eccb9de | 2005-06-17 12:59:34 +1000 | [diff] [blame] | 241 | if (len < 0 || (u_int)len != hlen + oidlen) { |
Darren Tucker | a251f80 | 2003-06-22 20:45:15 +1000 | [diff] [blame] | 242 | error("bad decrypted len: %d != %d + %d", len, hlen, oidlen); |
Ben Lindstrom | 0deb5d9 | 2002-08-20 18:40:03 +0000 | [diff] [blame] | 243 | goto done; |
| 244 | } |
Damien Miller | 4e8285e | 2010-08-03 16:04:03 +1000 | [diff] [blame] | 245 | oidmatch = timingsafe_bcmp(decrypted, oid, oidlen) == 0; |
| 246 | hashmatch = timingsafe_bcmp(decrypted + oidlen, hash, hlen) == 0; |
| 247 | if (!oidmatch) { |
Ben Lindstrom | 0deb5d9 | 2002-08-20 18:40:03 +0000 | [diff] [blame] | 248 | error("oid mismatch"); |
| 249 | goto done; |
| 250 | } |
Damien Miller | 4e8285e | 2010-08-03 16:04:03 +1000 | [diff] [blame] | 251 | if (!hashmatch) { |
Ben Lindstrom | 0deb5d9 | 2002-08-20 18:40:03 +0000 | [diff] [blame] | 252 | error("hash mismatch"); |
| 253 | goto done; |
| 254 | } |
| 255 | ret = 1; |
| 256 | done: |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 257 | free(decrypted); |
Ben Lindstrom | 0deb5d9 | 2002-08-20 18:40:03 +0000 | [diff] [blame] | 258 | return ret; |
| 259 | } |