diff options
| author | jsing <> | 2014-05-15 14:14:56 +0000 |
|---|---|---|
| committer | jsing <> | 2014-05-15 14:14:56 +0000 |
| commit | b115738274236129c97a787d577da5cbff4c828e (patch) | |
| tree | d1545fae6b44d7a9d7d6aa80a89b700911a313f3 /src/lib/libcrypto/evp | |
| parent | 331e9a2412038c63b968d43c57141df1425f9d43 (diff) | |
| download | openbsd-b115738274236129c97a787d577da5cbff4c828e.tar.gz openbsd-b115738274236129c97a787d577da5cbff4c828e.tar.bz2 openbsd-b115738274236129c97a787d577da5cbff4c828e.zip | |
KNF.
Diffstat (limited to 'src/lib/libcrypto/evp')
| -rw-r--r-- | src/lib/libcrypto/evp/e_aes.c | 21 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/evp_aead.c | 128 |
2 files changed, 75 insertions, 74 deletions
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c index e4d9457c96..4da61b8f62 100644 --- a/src/lib/libcrypto/evp/e_aes.c +++ b/src/lib/libcrypto/evp/e_aes.c | |||
| @@ -658,7 +658,8 @@ aes_gcm_cleanup(EVP_CIPHER_CTX *c) | |||
| 658 | 658 | ||
| 659 | /* increment counter (64-bit int) by 1 */ | 659 | /* increment counter (64-bit int) by 1 */ |
| 660 | static void | 660 | static void |
| 661 | ctr64_inc(unsigned char *counter) { | 661 | ctr64_inc(unsigned char *counter) |
| 662 | { | ||
| 662 | int n = 8; | 663 | int n = 8; |
| 663 | unsigned char c; | 664 | unsigned char c; |
| 664 | 665 | ||
| @@ -991,11 +992,11 @@ aes_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
| 991 | | EVP_CIPH_CUSTOM_IV | EVP_CIPH_FLAG_CUSTOM_CIPHER \ | 992 | | EVP_CIPH_CUSTOM_IV | EVP_CIPH_FLAG_CUSTOM_CIPHER \ |
| 992 | | EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CTRL_INIT) | 993 | | EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CTRL_INIT) |
| 993 | 994 | ||
| 994 | BLOCK_CIPHER_custom(NID_aes, 128, 1,12, gcm, GCM, | 995 | BLOCK_CIPHER_custom(NID_aes, 128, 1, 12, gcm, GCM, |
| 995 | EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_AEAD_CIPHER|CUSTOM_FLAGS) | 996 | EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_AEAD_CIPHER|CUSTOM_FLAGS) |
| 996 | BLOCK_CIPHER_custom(NID_aes, 192, 1,12, gcm, GCM, | 997 | BLOCK_CIPHER_custom(NID_aes, 192, 1, 12, gcm, GCM, |
| 997 | EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_AEAD_CIPHER|CUSTOM_FLAGS) | 998 | EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_AEAD_CIPHER|CUSTOM_FLAGS) |
| 998 | BLOCK_CIPHER_custom(NID_aes, 256, 1,12, gcm, GCM, | 999 | BLOCK_CIPHER_custom(NID_aes, 256, 1, 12, gcm, GCM, |
| 999 | EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_AEAD_CIPHER|CUSTOM_FLAGS) | 1000 | EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_AEAD_CIPHER|CUSTOM_FLAGS) |
| 1000 | 1001 | ||
| 1001 | static int | 1002 | static int |
| @@ -1104,8 +1105,8 @@ aes_xts_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
| 1104 | #define XTS_FLAGS (EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CUSTOM_IV \ | 1105 | #define XTS_FLAGS (EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_CUSTOM_IV \ |
| 1105 | | EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CTRL_INIT) | 1106 | | EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CTRL_INIT) |
| 1106 | 1107 | ||
| 1107 | BLOCK_CIPHER_custom(NID_aes, 128, 1,16, xts, XTS, EVP_CIPH_FLAG_FIPS|XTS_FLAGS) | 1108 | BLOCK_CIPHER_custom(NID_aes, 128, 1, 16, xts, XTS, EVP_CIPH_FLAG_FIPS|XTS_FLAGS) |
| 1108 | BLOCK_CIPHER_custom(NID_aes, 256, 1,16, xts, XTS, EVP_CIPH_FLAG_FIPS|XTS_FLAGS) | 1109 | BLOCK_CIPHER_custom(NID_aes, 256, 1, 16, xts, XTS, EVP_CIPH_FLAG_FIPS|XTS_FLAGS) |
| 1109 | 1110 | ||
| 1110 | static int | 1111 | static int |
| 1111 | aes_ccm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) | 1112 | aes_ccm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) |
| @@ -1254,11 +1255,11 @@ aes_ccm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
| 1254 | 1255 | ||
| 1255 | #define aes_ccm_cleanup NULL | 1256 | #define aes_ccm_cleanup NULL |
| 1256 | 1257 | ||
| 1257 | BLOCK_CIPHER_custom(NID_aes, 128, 1,12, ccm, CCM, | 1258 | BLOCK_CIPHER_custom(NID_aes, 128, 1, 12, ccm, CCM, |
| 1258 | EVP_CIPH_FLAG_FIPS|CUSTOM_FLAGS) | 1259 | EVP_CIPH_FLAG_FIPS|CUSTOM_FLAGS) |
| 1259 | BLOCK_CIPHER_custom(NID_aes, 192, 1,12, ccm, CCM, | 1260 | BLOCK_CIPHER_custom(NID_aes, 192, 1, 12, ccm, CCM, |
| 1260 | EVP_CIPH_FLAG_FIPS|CUSTOM_FLAGS) | 1261 | EVP_CIPH_FLAG_FIPS|CUSTOM_FLAGS) |
| 1261 | BLOCK_CIPHER_custom(NID_aes, 256, 1,12, ccm, CCM, | 1262 | BLOCK_CIPHER_custom(NID_aes, 256, 1, 12, ccm, CCM, |
| 1262 | EVP_CIPH_FLAG_FIPS|CUSTOM_FLAGS) | 1263 | EVP_CIPH_FLAG_FIPS|CUSTOM_FLAGS) |
| 1263 | 1264 | ||
| 1264 | #define EVP_AEAD_AES_GCM_TAG_LEN 16 | 1265 | #define EVP_AEAD_AES_GCM_TAG_LEN 16 |
| @@ -1390,7 +1391,7 @@ aead_aes_gcm_open(const EVP_AEAD_CTX *ctx, unsigned char *out, | |||
| 1390 | 1391 | ||
| 1391 | if (gcm_ctx->ctr) { | 1392 | if (gcm_ctx->ctr) { |
| 1392 | if (CRYPTO_gcm128_decrypt_ctr32(&gcm, in + bulk, out + bulk, | 1393 | if (CRYPTO_gcm128_decrypt_ctr32(&gcm, in + bulk, out + bulk, |
| 1393 | in_len-bulk-gcm_ctx->tag_len, gcm_ctx->ctr)) | 1394 | in_len - bulk - gcm_ctx->tag_len, gcm_ctx->ctr)) |
| 1394 | return -1; | 1395 | return -1; |
| 1395 | } else { | 1396 | } else { |
| 1396 | if (CRYPTO_gcm128_decrypt(&gcm, in + bulk, out + bulk, | 1397 | if (CRYPTO_gcm128_decrypt(&gcm, in + bulk, out + bulk, |
diff --git a/src/lib/libcrypto/evp/evp_aead.c b/src/lib/libcrypto/evp/evp_aead.c index 137e3dd05b..c8ba1df54a 100644 --- a/src/lib/libcrypto/evp/evp_aead.c +++ b/src/lib/libcrypto/evp/evp_aead.c | |||
| @@ -4,21 +4,21 @@ | |||
| 4 | * This package is an SSL implementation written | 4 | * This package is an SSL implementation written |
| 5 | * by Eric Young (eay@cryptsoft.com). | 5 | * by Eric Young (eay@cryptsoft.com). |
| 6 | * The implementation was written so as to conform with Netscapes SSL. | 6 | * The implementation was written so as to conform with Netscapes SSL. |
| 7 | * | 7 | * |
| 8 | * This library is free for commercial and non-commercial use as long as | 8 | * This library is free for commercial and non-commercial use as long as |
| 9 | * the following conditions are aheared to. The following conditions | 9 | * the following conditions are aheared to. The following conditions |
| 10 | * apply to all code found in this distribution, be it the RC4, RSA, | 10 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 11 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 11 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 12 | * included with this distribution is covered by the same copyright terms | 12 | * included with this distribution is covered by the same copyright terms |
| 13 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 13 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 14 | * | 14 | * |
| 15 | * Copyright remains Eric Young's, and as such any Copyright notices in | 15 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 16 | * the code are not to be removed. | 16 | * the code are not to be removed. |
| 17 | * If this package is used in a product, Eric Young should be given attribution | 17 | * If this package is used in a product, Eric Young should be given attribution |
| 18 | * as the author of the parts of the library used. | 18 | * as the author of the parts of the library used. |
| 19 | * This can be in the form of a textual message at program startup or | 19 | * This can be in the form of a textual message at program startup or |
| 20 | * in documentation (online or textual) provided with the package. | 20 | * in documentation (online or textual) provided with the package. |
| 21 | * | 21 | * |
| 22 | * Redistribution and use in source and binary forms, with or without | 22 | * Redistribution and use in source and binary forms, with or without |
| 23 | * modification, are permitted provided that the following conditions | 23 | * modification, are permitted provided that the following conditions |
| 24 | * are met: | 24 | * are met: |
| @@ -33,10 +33,10 @@ | |||
| 33 | * Eric Young (eay@cryptsoft.com)" | 33 | * Eric Young (eay@cryptsoft.com)" |
| 34 | * The word 'cryptographic' can be left out if the rouines from the library | 34 | * The word 'cryptographic' can be left out if the rouines from the library |
| 35 | * being used are not cryptographic related :-). | 35 | * being used are not cryptographic related :-). |
| 36 | * 4. If you include any Windows specific code (or a derivative thereof) from | 36 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 37 | * the apps directory (application code) you must include an acknowledgement: | 37 | * the apps directory (application code) you must include an acknowledgement: |
| 38 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 38 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 39 | * | 39 | * |
| 40 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 40 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 41 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 41 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| @@ -48,7 +48,7 @@ | |||
| 48 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 48 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 49 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 49 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 50 | * SUCH DAMAGE. | 50 | * SUCH DAMAGE. |
| 51 | * | 51 | * |
| 52 | * The licence and distribution terms for any publically available version or | 52 | * The licence and distribution terms for any publically available version or |
| 53 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 53 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 54 | * copied and put under another distribution licence | 54 | * copied and put under another distribution licence |
| @@ -63,46 +63,50 @@ | |||
| 63 | 63 | ||
| 64 | #include "evp_locl.h" | 64 | #include "evp_locl.h" |
| 65 | 65 | ||
| 66 | size_t EVP_AEAD_key_length(const EVP_AEAD *aead) | 66 | size_t |
| 67 | { | 67 | EVP_AEAD_key_length(const EVP_AEAD *aead) |
| 68 | { | ||
| 68 | return aead->key_len; | 69 | return aead->key_len; |
| 69 | } | 70 | } |
| 70 | 71 | ||
| 71 | size_t EVP_AEAD_nonce_length(const EVP_AEAD *aead) | 72 | size_t |
| 72 | { | 73 | EVP_AEAD_nonce_length(const EVP_AEAD *aead) |
| 74 | { | ||
| 73 | return aead->nonce_len; | 75 | return aead->nonce_len; |
| 74 | } | 76 | } |
| 75 | 77 | ||
| 76 | size_t EVP_AEAD_max_overhead(const EVP_AEAD *aead) | 78 | size_t |
| 77 | { | 79 | EVP_AEAD_max_overhead(const EVP_AEAD *aead) |
| 80 | { | ||
| 78 | return aead->overhead; | 81 | return aead->overhead; |
| 79 | } | 82 | } |
| 80 | 83 | ||
| 81 | size_t EVP_AEAD_max_tag_len(const EVP_AEAD *aead) | 84 | size_t |
| 82 | { | 85 | EVP_AEAD_max_tag_len(const EVP_AEAD *aead) |
| 86 | { | ||
| 83 | return aead->max_tag_len; | 87 | return aead->max_tag_len; |
| 84 | } | 88 | } |
| 85 | 89 | ||
| 86 | int EVP_AEAD_CTX_init(EVP_AEAD_CTX *ctx, const EVP_AEAD *aead, | 90 | int |
| 87 | const unsigned char *key, size_t key_len, | 91 | EVP_AEAD_CTX_init(EVP_AEAD_CTX *ctx, const EVP_AEAD *aead, |
| 88 | size_t tag_len, ENGINE *impl) | 92 | const unsigned char *key, size_t key_len, size_t tag_len, ENGINE *impl) |
| 89 | { | 93 | { |
| 90 | ctx->aead = aead; | 94 | ctx->aead = aead; |
| 91 | if (key_len != aead->key_len) | 95 | if (key_len != aead->key_len) { |
| 92 | { | 96 | EVPerr(EVP_F_EVP_AEAD_CTX_INIT, EVP_R_UNSUPPORTED_KEY_SIZE); |
| 93 | EVPerr(EVP_F_EVP_AEAD_CTX_INIT,EVP_R_UNSUPPORTED_KEY_SIZE); | ||
| 94 | return 0; | 97 | return 0; |
| 95 | } | ||
| 96 | return aead->init(ctx, key, key_len, tag_len); | ||
| 97 | } | 98 | } |
| 99 | return aead->init(ctx, key, key_len, tag_len); | ||
| 100 | } | ||
| 98 | 101 | ||
| 99 | void EVP_AEAD_CTX_cleanup(EVP_AEAD_CTX *ctx) | 102 | void |
| 100 | { | 103 | EVP_AEAD_CTX_cleanup(EVP_AEAD_CTX *ctx) |
| 104 | { | ||
| 101 | if (ctx->aead == NULL) | 105 | if (ctx->aead == NULL) |
| 102 | return; | 106 | return; |
| 103 | ctx->aead->cleanup(ctx); | 107 | ctx->aead->cleanup(ctx); |
| 104 | ctx->aead = NULL; | 108 | ctx->aead = NULL; |
| 105 | } | 109 | } |
| 106 | 110 | ||
| 107 | /* check_alias returns 0 if out points within the buffer determined by in | 111 | /* check_alias returns 0 if out points within the buffer determined by in |
| 108 | * and in_len and 1 otherwise. | 112 | * and in_len and 1 otherwise. |
| @@ -112,41 +116,39 @@ void EVP_AEAD_CTX_cleanup(EVP_AEAD_CTX *ctx) | |||
| 112 | * stomp input that hasn't been read yet. | 116 | * stomp input that hasn't been read yet. |
| 113 | * | 117 | * |
| 114 | * This function checks for that case. */ | 118 | * This function checks for that case. */ |
| 115 | static int check_alias(const unsigned char *in, size_t in_len, | 119 | static int |
| 116 | const unsigned char *out) | 120 | check_alias(const unsigned char *in, size_t in_len, const unsigned char *out) |
| 117 | { | 121 | { |
| 118 | if (out <= in) | 122 | if (out <= in) |
| 119 | return 1; | 123 | return 1; |
| 120 | if (in + in_len <= out) | 124 | if (in + in_len <= out) |
| 121 | return 1; | 125 | return 1; |
| 122 | return 0; | 126 | return 0; |
| 123 | } | 127 | } |
| 124 | 128 | ||
| 125 | ssize_t EVP_AEAD_CTX_seal(const EVP_AEAD_CTX *ctx, | 129 | ssize_t |
| 126 | unsigned char *out, size_t max_out_len, | 130 | EVP_AEAD_CTX_seal(const EVP_AEAD_CTX *ctx, unsigned char *out, |
| 127 | const unsigned char *nonce, size_t nonce_len, | 131 | size_t max_out_len, const unsigned char *nonce, size_t nonce_len, |
| 128 | const unsigned char *in, size_t in_len, | 132 | const unsigned char *in, size_t in_len, const unsigned char *ad, |
| 129 | const unsigned char *ad, size_t ad_len) | 133 | size_t ad_len) |
| 130 | { | 134 | { |
| 131 | size_t possible_out_len = in_len + ctx->aead->overhead; | 135 | size_t possible_out_len = in_len + ctx->aead->overhead; |
| 132 | ssize_t r; | 136 | ssize_t r; |
| 133 | 137 | ||
| 134 | if (possible_out_len < in_len /* overflow */ || | 138 | if (possible_out_len < in_len /* overflow */ || |
| 135 | possible_out_len > SSIZE_MAX /* return value cannot be | 139 | possible_out_len > SSIZE_MAX /* return value cannot be |
| 136 | represented */) | 140 | represented */) { |
| 137 | { | ||
| 138 | EVPerr(EVP_F_EVP_AEAD_CTX_SEAL, EVP_R_TOO_LARGE); | 141 | EVPerr(EVP_F_EVP_AEAD_CTX_SEAL, EVP_R_TOO_LARGE); |
| 139 | goto error; | 142 | goto error; |
| 140 | } | 143 | } |
| 141 | 144 | ||
| 142 | if (!check_alias(in, in_len, out)) | 145 | if (!check_alias(in, in_len, out)) { |
| 143 | { | ||
| 144 | EVPerr(EVP_F_EVP_AEAD_CTX_SEAL, EVP_R_OUTPUT_ALIASES_INPUT); | 146 | EVPerr(EVP_F_EVP_AEAD_CTX_SEAL, EVP_R_OUTPUT_ALIASES_INPUT); |
| 145 | goto error; | 147 | goto error; |
| 146 | } | 148 | } |
| 147 | 149 | ||
| 148 | r = ctx->aead->seal(ctx, out, max_out_len, nonce, nonce_len, | 150 | r = ctx->aead->seal(ctx, out, max_out_len, nonce, nonce_len, |
| 149 | in, in_len, ad, ad_len); | 151 | in, in_len, ad, ad_len); |
| 150 | if (r >= 0) | 152 | if (r >= 0) |
| 151 | return r; | 153 | return r; |
| 152 | 154 | ||
| @@ -155,30 +157,28 @@ error: | |||
| 155 | * that doesn't check the return value doesn't send raw data. */ | 157 | * that doesn't check the return value doesn't send raw data. */ |
| 156 | memset(out, 0, max_out_len); | 158 | memset(out, 0, max_out_len); |
| 157 | return -1; | 159 | return -1; |
| 158 | } | 160 | } |
| 159 | 161 | ||
| 160 | ssize_t EVP_AEAD_CTX_open(const EVP_AEAD_CTX *ctx, | 162 | ssize_t |
| 161 | unsigned char *out, size_t max_out_len, | 163 | EVP_AEAD_CTX_open(const EVP_AEAD_CTX *ctx, unsigned char *out, |
| 162 | const unsigned char *nonce, size_t nonce_len, | 164 | size_t max_out_len, const unsigned char *nonce, size_t nonce_len, |
| 163 | const unsigned char *in, size_t in_len, | 165 | const unsigned char *in, size_t in_len, const unsigned char *ad, |
| 164 | const unsigned char *ad, size_t ad_len) | 166 | size_t ad_len) |
| 165 | { | 167 | { |
| 166 | ssize_t r; | 168 | ssize_t r; |
| 167 | 169 | ||
| 168 | if (in_len > SSIZE_MAX) | 170 | if (in_len > SSIZE_MAX) { |
| 169 | { | ||
| 170 | EVPerr(EVP_F_EVP_AEAD_CTX_OPEN, EVP_R_TOO_LARGE); | 171 | EVPerr(EVP_F_EVP_AEAD_CTX_OPEN, EVP_R_TOO_LARGE); |
| 171 | goto error; /* may not be able to represent return value. */ | 172 | goto error; /* may not be able to represent return value. */ |
| 172 | } | 173 | } |
| 173 | 174 | ||
| 174 | if (!check_alias(in, in_len, out)) | 175 | if (!check_alias(in, in_len, out)) { |
| 175 | { | ||
| 176 | EVPerr(EVP_F_EVP_AEAD_CTX_OPEN, EVP_R_OUTPUT_ALIASES_INPUT); | 176 | EVPerr(EVP_F_EVP_AEAD_CTX_OPEN, EVP_R_OUTPUT_ALIASES_INPUT); |
| 177 | goto error; | 177 | goto error; |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | r = ctx->aead->open(ctx, out, max_out_len, nonce, nonce_len, | 180 | r = ctx->aead->open(ctx, out, max_out_len, nonce, nonce_len, |
| 181 | in, in_len, ad, ad_len); | 181 | in, in_len, ad, ad_len); |
| 182 | 182 | ||
| 183 | if (r >= 0) | 183 | if (r >= 0) |
| 184 | return r; | 184 | return r; |
| @@ -189,4 +189,4 @@ error: | |||
| 189 | * data. */ | 189 | * data. */ |
| 190 | memset(out, 0, max_out_len); | 190 | memset(out, 0, max_out_len); |
| 191 | return -1; | 191 | return -1; |
| 192 | } | 192 | } |
