Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/evp/e_aria.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3 | * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4 | * | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6 | * this file except in compliance with the License. You can obtain a copy | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7 | * in the file LICENSE in the source distribution or at | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
8 | * https://www.openssl.org/source/license.html | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
9 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
10 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
11 | #include "internal/cryptlib.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
12 | #ifndef OPENSSL_NO_ARIA | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
13 | # include <openssl/evp.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
14 | # include <openssl/modes.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
15 | # include <openssl/rand.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
16 | # include <openssl/rand_drbg.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
17 | # include "internal/aria.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
18 | # include "internal/evp_int.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
19 | # include "modes_lcl.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
20 | # include "evp_locl.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
21 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
22 | /* ARIA subkey Structure */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
23 | typedef struct { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
24 | ARIA_KEY ks; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
25 | } EVP_ARIA_KEY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
26 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
27 | /* ARIA GCM context */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
28 | typedef struct { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
29 | union { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
30 | double align; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
31 | ARIA_KEY ks; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
32 | } ks; /* ARIA subkey to use */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33 | int key_set; /* Set if key initialised */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
34 | int iv_set; /* Set if an iv is set */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
35 | GCM128_CONTEXT gcm; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
36 | unsigned char *iv; /* Temporary IV store */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
37 | int ivlen; /* IV length */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
38 | int taglen; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
39 | int iv_gen; /* It is OK to generate IVs */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
40 | int tls_aad_len; /* TLS AAD length */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
41 | } EVP_ARIA_GCM_CTX; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
42 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
43 | /* ARIA CCM context */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
44 | typedef struct { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
45 | union { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
46 | double align; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
47 | ARIA_KEY ks; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
48 | } ks; /* ARIA key schedule to use */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
49 | int key_set; /* Set if key initialised */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
50 | int iv_set; /* Set if an iv is set */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
51 | int tag_set; /* Set if tag is valid */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
52 | int len_set; /* Set if message length set */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
53 | int L, M; /* L and M parameters from RFC3610 */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
54 | int tls_aad_len; /* TLS AAD length */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
55 | CCM128_CONTEXT ccm; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
56 | ccm128_f str; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
57 | } EVP_ARIA_CCM_CTX; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
58 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
59 | /* The subkey for ARIA is generated. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
60 | static int aria_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
61 | const unsigned char *iv, int enc) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
62 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
63 | int ret; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
64 | int mode = EVP_CIPHER_CTX_mode(ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
65 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
66 | if (enc || (mode != EVP_CIPH_ECB_MODE && mode != EVP_CIPH_CBC_MODE))
| 48-318 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
67 | ret = aria_set_encrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8, executed 507 times by 1 test: ret = aria_set_encrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8, EVP_CIPHER_CTX_get_cipher_data(ctx)); Executed by:
| 507 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
68 | EVP_CIPHER_CTX_get_cipher_data(ctx)); executed 507 times by 1 test: ret = aria_set_encrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8, EVP_CIPHER_CTX_get_cipher_data(ctx)); Executed by:
| 507 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
69 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
70 | ret = aria_set_decrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8, executed 129 times by 1 test: ret = aria_set_decrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8, EVP_CIPHER_CTX_get_cipher_data(ctx)); Executed by:
| 129 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
71 | EVP_CIPHER_CTX_get_cipher_data(ctx)); executed 129 times by 1 test: ret = aria_set_decrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8, EVP_CIPHER_CTX_get_cipher_data(ctx)); Executed by:
| 129 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
72 | if (ret < 0) {
| 0-636 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
73 | EVPerr(EVP_F_ARIA_INIT_KEY,EVP_R_ARIA_KEY_SETUP_FAILED); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
74 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
75 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
76 | return 1; executed 636 times by 1 test: return 1; Executed by:
| 636 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
77 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
78 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
79 | static void aria_cbc_encrypt(const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
80 | size_t len, const ARIA_KEY *key, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
81 | unsigned char *ivec, const int enc) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
82 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
83 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
84 | if (enc)
| 240-306 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
85 | CRYPTO_cbc128_encrypt(in, out, len, key, ivec, executed 306 times by 1 test: CRYPTO_cbc128_encrypt(in, out, len, key, ivec, (block128_f) aria_encrypt); Executed by:
| 306 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
86 | (block128_f) aria_encrypt); executed 306 times by 1 test: CRYPTO_cbc128_encrypt(in, out, len, key, ivec, (block128_f) aria_encrypt); Executed by:
| 306 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
87 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
88 | CRYPTO_cbc128_decrypt(in, out, len, key, ivec, executed 240 times by 1 test: CRYPTO_cbc128_decrypt(in, out, len, key, ivec, (block128_f) aria_encrypt); Executed by:
| 240 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
89 | (block128_f) aria_encrypt); executed 240 times by 1 test: CRYPTO_cbc128_decrypt(in, out, len, key, ivec, (block128_f) aria_encrypt); Executed by:
| 240 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
90 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
91 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
92 | static void aria_cfb128_encrypt(const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
93 | size_t length, const ARIA_KEY *key, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
94 | unsigned char *ivec, int *num, const int enc) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
95 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
97 | CRYPTO_cfb128_encrypt(in, out, length, key, ivec, num, enc, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
98 | (block128_f) aria_encrypt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
99 | } executed 354 times by 1 test: end of block Executed by:
| 354 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
100 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
101 | static void aria_cfb1_encrypt(const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
102 | size_t length, const ARIA_KEY *key, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
103 | unsigned char *ivec, int *num, const int enc) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
104 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
105 | CRYPTO_cfb128_1_encrypt(in, out, length, key, ivec, num, enc, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
106 | (block128_f) aria_encrypt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
107 | } executed 210 times by 1 test: end of block Executed by:
| 210 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
108 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
109 | static void aria_cfb8_encrypt(const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
110 | size_t length, const ARIA_KEY *key, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
111 | unsigned char *ivec, int *num, const int enc) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
112 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
113 | CRYPTO_cfb128_8_encrypt(in, out, length, key, ivec, num, enc, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
114 | (block128_f) aria_encrypt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
115 | } executed 354 times by 1 test: end of block Executed by:
| 354 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
116 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
117 | static void aria_ecb_encrypt(const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
118 | const ARIA_KEY *key, const int enc) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
119 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
120 | aria_encrypt(in, out, key); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
121 | } executed 3150 times by 1 test: end of block Executed by:
| 3150 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
123 | static void aria_ofb128_encrypt(const unsigned char *in, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
124 | size_t length, const ARIA_KEY *key, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
125 | unsigned char *ivec, int *num) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
126 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
127 | CRYPTO_ofb128_encrypt(in, out, length, key, ivec, num, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
128 | (block128_f) aria_encrypt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
129 | } executed 354 times by 1 test: end of block Executed by:
| 354 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
131 | IMPLEMENT_BLOCK_CIPHER(aria_128, ks, aria, EVP_ARIA_KEY, never executed: end of block executed 182 times by 1 test: aria_cbc_encrypt(in, out, (long)inl, &((EVP_ARIA_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks, EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
executed 182 times by 1 test: return 1; Executed by:
never executed: chunk >>= 3; executed 118 times by 1 test: chunk = inl; Executed by:
executed 118 times by 1 test: chunk = inl; Executed by:
executed 118 times by 1 test: end of block Executed by:
executed 118 times by 1 test: return 1; Executed by:
never executed: return 1; executed 1050 times by 1 test: aria_ecb_encrypt(in + i, out + i, &((EVP_ARIA_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks, EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
executed 203 times by 1 test: return 1; Executed by:
never executed: end of block executed 118 times by 1 test: end of block Executed by:
executed 118 times by 1 test: return 1; Executed by:
executed 1962 times by 1 test: return &aria_128_cbc; Executed by:
executed 1962 times by 1 test: return &aria_128_cfb128; Executed by:
executed 1962 times by 1 test: return &aria_128_ofb; Executed by:
executed 1962 times by 1 test: return &aria_128_ecb; Executed by:
| 0-1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
132 | NID_aria_128, 16, 16, 16, 128, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
133 | 0, aria_init_key, NULL, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
134 | EVP_CIPHER_set_asn1_iv, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
135 | EVP_CIPHER_get_asn1_iv, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
136 | NULL) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
137 | IMPLEMENT_BLOCK_CIPHER(aria_192, ks, aria, EVP_ARIA_KEY, never executed: end of block executed 182 times by 1 test: aria_cbc_encrypt(in, out, (long)inl, &((EVP_ARIA_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks, EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
executed 182 times by 1 test: return 1; Executed by:
never executed: chunk >>= 3; executed 118 times by 1 test: chunk = inl; Executed by:
executed 118 times by 1 test: chunk = inl; Executed by:
executed 118 times by 1 test: end of block Executed by:
executed 118 times by 1 test: return 1; Executed by:
never executed: return 1; executed 1050 times by 1 test: aria_ecb_encrypt(in + i, out + i, &((EVP_ARIA_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks, EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
executed 203 times by 1 test: return 1; Executed by:
never executed: end of block executed 118 times by 1 test: end of block Executed by:
executed 118 times by 1 test: return 1; Executed by:
executed 1962 times by 1 test: return &aria_192_cbc; Executed by:
executed 1962 times by 1 test: return &aria_192_cfb128; Executed by:
executed 1962 times by 1 test: return &aria_192_ofb; Executed by:
executed 1962 times by 1 test: return &aria_192_ecb; Executed by:
| 0-1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
138 | NID_aria_192, 16, 24, 16, 128, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
139 | 0, aria_init_key, NULL, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
140 | EVP_CIPHER_set_asn1_iv, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
141 | EVP_CIPHER_get_asn1_iv, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
142 | NULL) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
143 | IMPLEMENT_BLOCK_CIPHER(aria_256, ks, aria, EVP_ARIA_KEY, never executed: end of block executed 182 times by 1 test: aria_cbc_encrypt(in, out, (long)inl, &((EVP_ARIA_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks, EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
executed 182 times by 1 test: return 1; Executed by:
never executed: chunk >>= 3; executed 118 times by 1 test: chunk = inl; Executed by:
executed 118 times by 1 test: chunk = inl; Executed by:
executed 118 times by 1 test: end of block Executed by:
executed 118 times by 1 test: return 1; Executed by:
never executed: return 1; executed 1050 times by 1 test: aria_ecb_encrypt(in + i, out + i, &((EVP_ARIA_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx))->ks, EVP_CIPHER_CTX_encrypting(ctx)); Executed by:
executed 203 times by 1 test: return 1; Executed by:
never executed: end of block executed 118 times by 1 test: end of block Executed by:
executed 118 times by 1 test: return 1; Executed by:
executed 1962 times by 1 test: return &aria_256_cbc; Executed by:
executed 1962 times by 1 test: return &aria_256_cfb128; Executed by:
executed 1962 times by 1 test: return &aria_256_ofb; Executed by:
executed 1962 times by 1 test: return &aria_256_ecb; Executed by:
| 0-1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
144 | NID_aria_256, 16, 32, 16, 128, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
145 | 0, aria_init_key, NULL, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
146 | EVP_CIPHER_set_asn1_iv, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
147 | EVP_CIPHER_get_asn1_iv, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
148 | NULL) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
149 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
150 | # define IMPLEMENT_ARIA_CFBR(ksize,cbits) \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
151 | IMPLEMENT_CFBR(aria,aria,EVP_ARIA_KEY,ks,ksize,cbits,16,0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
152 | IMPLEMENT_ARIA_CFBR(128,1) executed 70 times by 1 test: chunk >>= 3; Executed by:
executed 70 times by 1 test: chunk = inl; Executed by:
executed 70 times by 1 test: chunk = inl; Executed by:
executed 70 times by 1 test: end of block Executed by:
executed 70 times by 1 test: return 1; Executed by:
executed 1962 times by 1 test: return &aria_128_cfb1; Executed by:
| 0-1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
153 | IMPLEMENT_ARIA_CFBR(192,1) executed 70 times by 1 test: chunk >>= 3; Executed by:
executed 70 times by 1 test: chunk = inl; Executed by:
executed 70 times by 1 test: chunk = inl; Executed by:
executed 70 times by 1 test: end of block Executed by:
executed 70 times by 1 test: return 1; Executed by:
executed 1962 times by 1 test: return &aria_192_cfb1; Executed by:
| 0-1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
154 | IMPLEMENT_ARIA_CFBR(256,1) executed 70 times by 1 test: chunk >>= 3; Executed by:
executed 70 times by 1 test: chunk = inl; Executed by:
executed 70 times by 1 test: chunk = inl; Executed by:
executed 70 times by 1 test: end of block Executed by:
executed 70 times by 1 test: return 1; Executed by:
executed 1962 times by 1 test: return &aria_256_cfb1; Executed by:
| 0-1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
155 | IMPLEMENT_ARIA_CFBR(128,8) never executed: chunk >>= 3; executed 118 times by 1 test: chunk = inl; Executed by:
executed 118 times by 1 test: chunk = inl; Executed by:
executed 118 times by 1 test: end of block Executed by:
executed 118 times by 1 test: return 1; Executed by:
executed 1962 times by 1 test: return &aria_128_cfb8; Executed by:
| 0-1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
156 | IMPLEMENT_ARIA_CFBR(192,8) never executed: chunk >>= 3; executed 118 times by 1 test: chunk = inl; Executed by:
executed 118 times by 1 test: chunk = inl; Executed by:
executed 118 times by 1 test: end of block Executed by:
executed 118 times by 1 test: return 1; Executed by:
executed 1962 times by 1 test: return &aria_192_cfb8; Executed by:
| 0-1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
157 | IMPLEMENT_ARIA_CFBR(256,8) never executed: chunk >>= 3; executed 118 times by 1 test: chunk = inl; Executed by:
executed 118 times by 1 test: chunk = inl; Executed by:
executed 118 times by 1 test: end of block Executed by:
executed 118 times by 1 test: return 1; Executed by:
executed 1962 times by 1 test: return &aria_256_cfb8; Executed by:
| 0-1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
158 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
159 | # define BLOCK_CIPHER_generic(nid,keylen,blocksize,ivlen,nmode,mode,MODE,flags) \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
160 | static const EVP_CIPHER aria_##keylen##_##mode = { \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
161 | nid##_##keylen##_##nmode,blocksize,keylen/8,ivlen, \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
162 | flags|EVP_CIPH_##MODE##_MODE, \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
163 | aria_init_key, \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
164 | aria_##mode##_cipher, \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
165 | NULL, \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
166 | sizeof(EVP_ARIA_KEY), \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
167 | NULL,NULL,NULL,NULL }; \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
168 | const EVP_CIPHER *EVP_aria_##keylen##_##mode(void) \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
169 | { return &aria_##keylen##_##mode; } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
170 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
171 | static int aria_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
172 | const unsigned char *in, size_t len) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
173 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
174 | unsigned int num = EVP_CIPHER_CTX_num(ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
175 | EVP_ARIA_KEY *dat = EVP_C_DATA(EVP_ARIA_KEY,ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
176 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
177 | CRYPTO_ctr128_encrypt(in, out, len, &dat->ks, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
178 | EVP_CIPHER_CTX_iv_noconst(ctx), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
179 | EVP_CIPHER_CTX_buf_noconst(ctx), &num, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
180 | (block128_f) aria_encrypt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
181 | EVP_CIPHER_CTX_set_num(ctx, num); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
182 | return 1; executed 354 times by 1 test: return 1; Executed by:
| 354 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
183 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
184 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
185 | BLOCK_CIPHER_generic(NID_aria, 128, 1, 16, ctr, ctr, CTR, 0) executed 1962 times by 1 test: return &aria_128_ctr; Executed by:
| 1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
186 | BLOCK_CIPHER_generic(NID_aria, 192, 1, 16, ctr, ctr, CTR, 0) executed 1962 times by 1 test: return &aria_192_ctr; Executed by:
| 1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
187 | BLOCK_CIPHER_generic(NID_aria, 256, 1, 16, ctr, ctr, CTR, 0) executed 1962 times by 1 test: return &aria_256_ctr; Executed by:
| 1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
188 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
189 | /* Authenticated cipher modes (GCM/CCM) */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
190 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
191 | /* increment counter (64-bit int) by 1 */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
192 | static void ctr64_inc(unsigned char *counter) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
193 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
194 | int n = 8; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
195 | unsigned char c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
196 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
197 | do { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
198 | --n; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
199 | c = counter[n]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
200 | ++c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
201 | counter[n] = c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
202 | if (c)
| 0-206 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
203 | return; executed 206 times by 1 test: return; Executed by:
| 206 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
204 | } while (n); never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
205 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
206 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
207 | static int aria_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
208 | const unsigned char *iv, int enc) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
209 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
210 | int ret; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
211 | EVP_ARIA_GCM_CTX *gctx = EVP_C_DATA(EVP_ARIA_GCM_CTX,ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
212 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
213 | if (!iv && !key)
| 48-207 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
214 | return 1; executed 48 times by 1 test: return 1; Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
215 | if (key) {
| 0-207 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
216 | ret = aria_set_encrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
217 | &gctx->ks.ks); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
218 | CRYPTO_gcm128_init(&gctx->gcm, &gctx->ks, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
219 | (block128_f) aria_encrypt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
220 | if (ret < 0) {
| 0-207 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
221 | EVPerr(EVP_F_ARIA_GCM_INIT_KEY,EVP_R_ARIA_KEY_SETUP_FAILED); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
222 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
223 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
224 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
225 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
226 | * If we have an iv can set it directly, otherwise use saved IV. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
227 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
228 | if (iv == NULL && gctx->iv_set)
| 0-159 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
229 | iv = gctx->iv; never executed: iv = gctx->iv; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
230 | if (iv) {
| 48-159 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
231 | CRYPTO_gcm128_setiv(&gctx->gcm, iv, gctx->ivlen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
232 | gctx->iv_set = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
233 | } executed 48 times by 1 test: end of block Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
234 | gctx->key_set = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
235 | } else { executed 207 times by 1 test: end of block Executed by:
| 207 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
236 | /* If key set use IV, otherwise copy */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
237 | if (gctx->key_set)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
238 | CRYPTO_gcm128_setiv(&gctx->gcm, iv, gctx->ivlen); never executed: CRYPTO_gcm128_setiv(&gctx->gcm, iv, gctx->ivlen); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
239 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
240 | memcpy(gctx->iv, iv, gctx->ivlen); never executed: memcpy(gctx->iv, iv, gctx->ivlen); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
241 | gctx->iv_set = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
242 | gctx->iv_gen = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
243 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
244 | return 1; executed 207 times by 1 test: return 1; Executed by:
| 207 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
245 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
246 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
247 | static int aria_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
248 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
249 | EVP_ARIA_GCM_CTX *gctx = EVP_C_DATA(EVP_ARIA_GCM_CTX,c); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
250 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
251 | switch (type) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
252 | case EVP_CTRL_INIT: executed 207 times by 1 test: case 0x0: Executed by:
| 207 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
253 | gctx->key_set = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
254 | gctx->iv_set = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
255 | gctx->ivlen = EVP_CIPHER_CTX_iv_length(c); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
256 | gctx->iv = EVP_CIPHER_CTX_iv_noconst(c); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
257 | gctx->taglen = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
258 | gctx->iv_gen = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
259 | gctx->tls_aad_len = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
260 | return 1; executed 207 times by 1 test: return 1; Executed by:
| 207 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
261 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
262 | case EVP_CTRL_AEAD_SET_IVLEN: executed 48 times by 1 test: case 0x9: Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
263 | if (arg <= 0)
| 0-48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
264 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
265 | /* Allocate memory for IV if needed */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
266 | if ((arg > EVP_MAX_IV_LENGTH) && (arg > gctx->ivlen)) {
| 0-48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
267 | if (gctx->iv != EVP_CIPHER_CTX_iv_noconst(c))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
268 | OPENSSL_free(gctx->iv); never executed: CRYPTO_free(gctx->iv, __FILE__, 268); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
269 | if ((gctx->iv = OPENSSL_malloc(arg)) == NULL) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
270 | EVPerr(EVP_F_ARIA_GCM_CTRL, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
271 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
272 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
273 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
274 | gctx->ivlen = arg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
275 | return 1; executed 48 times by 1 test: return 1; Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
276 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
277 | case EVP_CTRL_AEAD_SET_TAG: executed 24 times by 1 test: case 0x11: Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
278 | if (arg <= 0 || arg > 16 || EVP_CIPHER_CTX_encrypting(c))
| 0-24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
279 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
280 | memcpy(EVP_CIPHER_CTX_buf_noconst(c), ptr, arg); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
281 | gctx->taglen = arg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
282 | return 1; executed 24 times by 1 test: return 1; Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
283 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
284 | case EVP_CTRL_AEAD_GET_TAG: executed 24 times by 1 test: case 0x10: Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
285 | if (arg <= 0 || arg > 16 || !EVP_CIPHER_CTX_encrypting(c)
| 0-24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
286 | || gctx->taglen < 0)
| 0-24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
287 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
288 | memcpy(ptr, EVP_CIPHER_CTX_buf_noconst(c), arg); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
289 | return 1; executed 24 times by 1 test: return 1; Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
290 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
291 | case EVP_CTRL_GCM_SET_IV_FIXED: executed 159 times by 1 test: case 0x12: Executed by:
| 159 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
292 | /* Special case: -1 length restores whole IV */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
293 | if (arg == -1) {
| 0-159 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
294 | memcpy(gctx->iv, ptr, gctx->ivlen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
295 | gctx->iv_gen = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
296 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
297 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
298 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
299 | * Fixed field must be at least 4 bytes and invocation field at least | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
300 | * 8. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
301 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
302 | if ((arg < 4) || (gctx->ivlen - arg) < 8)
| 0-159 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
303 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
304 | if (arg)
| 0-159 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
305 | memcpy(gctx->iv, ptr, arg); executed 159 times by 1 test: memcpy(gctx->iv, ptr, arg); Executed by:
| 159 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
306 | if (EVP_CIPHER_CTX_encrypting(c)
| 65-94 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
307 | && RAND_bytes(gctx->iv + arg, gctx->ivlen - arg) <= 0)
| 0-65 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
308 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
309 | gctx->iv_gen = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
310 | return 1; executed 159 times by 1 test: return 1; Executed by:
| 159 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
311 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
312 | case EVP_CTRL_GCM_IV_GEN: executed 206 times by 1 test: case 0x13: Executed by:
| 206 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
313 | if (gctx->iv_gen == 0 || gctx->key_set == 0)
| 0-206 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
314 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
315 | CRYPTO_gcm128_setiv(&gctx->gcm, gctx->iv, gctx->ivlen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
316 | if (arg <= 0 || arg > gctx->ivlen)
| 0-206 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
317 | arg = gctx->ivlen; never executed: arg = gctx->ivlen; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
318 | memcpy(ptr, gctx->iv + gctx->ivlen - arg, arg); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
319 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
320 | * Invocation field will be at least 8 bytes in size and so no need | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
321 | * to check wrap around or increment more than last 8 bytes. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
322 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
323 | ctr64_inc(gctx->iv + gctx->ivlen - 8); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
324 | gctx->iv_set = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
325 | return 1; executed 206 times by 1 test: return 1; Executed by:
| 206 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
326 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
327 | case EVP_CTRL_GCM_SET_IV_INV: executed 111 times by 1 test: case 0x18: Executed by:
| 111 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
328 | if (gctx->iv_gen == 0 || gctx->key_set == 0
| 0-111 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
329 | || EVP_CIPHER_CTX_encrypting(c))
| 0-111 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
330 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
331 | memcpy(gctx->iv + gctx->ivlen - arg, ptr, arg); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
332 | CRYPTO_gcm128_setiv(&gctx->gcm, gctx->iv, gctx->ivlen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
333 | gctx->iv_set = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
334 | return 1; executed 111 times by 1 test: return 1; Executed by:
| 111 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
335 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
336 | case EVP_CTRL_AEAD_TLS1_AAD: executed 321 times by 1 test: case 0x16: Executed by:
| 321 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
337 | /* Save the AAD for later use */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
338 | if (arg != EVP_AEAD_TLS1_AAD_LEN)
| 0-321 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
339 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
340 | memcpy(EVP_CIPHER_CTX_buf_noconst(c), ptr, arg); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
341 | gctx->tls_aad_len = arg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
342 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
343 | unsigned int len = | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
344 | EVP_CIPHER_CTX_buf_noconst(c)[arg - 2] << 8 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
345 | | EVP_CIPHER_CTX_buf_noconst(c)[arg - 1]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
346 | /* Correct length for explicit IV */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
347 | if (len < EVP_GCM_TLS_EXPLICIT_IV_LEN)
| 2-319 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
348 | return 0; executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
349 | len -= EVP_GCM_TLS_EXPLICIT_IV_LEN; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
350 | /* If decrypting correct for tag too */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
351 | if (!EVP_CIPHER_CTX_encrypting(c)) {
| 113-206 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
352 | if (len < EVP_GCM_TLS_TAG_LEN)
| 2-111 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
353 | return 0; executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
354 | len -= EVP_GCM_TLS_TAG_LEN; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
355 | } executed 111 times by 1 test: end of block Executed by:
| 111 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
356 | EVP_CIPHER_CTX_buf_noconst(c)[arg - 2] = len >> 8; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
357 | EVP_CIPHER_CTX_buf_noconst(c)[arg - 1] = len & 0xff; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
358 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
359 | /* Extra padding: tag appended to record */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
360 | return EVP_GCM_TLS_TAG_LEN; executed 317 times by 1 test: return 16; Executed by:
| 317 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
361 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
362 | case EVP_CTRL_COPY: never executed: case 0x8: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
363 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
364 | EVP_CIPHER_CTX *out = ptr; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
365 | EVP_ARIA_GCM_CTX *gctx_out = EVP_C_DATA(EVP_ARIA_GCM_CTX,out); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
366 | if (gctx->gcm.key) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
367 | if (gctx->gcm.key != &gctx->ks)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
368 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
369 | gctx_out->gcm.key = &gctx_out->ks; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
370 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
371 | if (gctx->iv == EVP_CIPHER_CTX_iv_noconst(c))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
372 | gctx_out->iv = EVP_CIPHER_CTX_iv_noconst(out); never executed: gctx_out->iv = EVP_CIPHER_CTX_iv_noconst(out); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
373 | else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
374 | if ((gctx_out->iv = OPENSSL_malloc(gctx->ivlen)) == NULL) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
375 | EVPerr(EVP_F_ARIA_GCM_CTRL, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
376 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
377 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
378 | memcpy(gctx_out->iv, gctx->iv, gctx->ivlen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
379 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
380 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
381 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
382 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
383 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
384 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
385 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
386 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
387 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
388 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
389 | static int aria_gcm_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
390 | const unsigned char *in, size_t len) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
391 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
392 | EVP_ARIA_GCM_CTX *gctx = EVP_C_DATA(EVP_ARIA_GCM_CTX,ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
393 | int rv = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
394 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
395 | /* Encrypt/decrypt must be performed in place */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
396 | if (out != in
| 0-317 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
397 | || len < (EVP_GCM_TLS_EXPLICIT_IV_LEN + EVP_GCM_TLS_TAG_LEN))
| 0-317 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
398 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
399 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
400 | * Set IV from start of buffer or generate IV and write to start of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
401 | * buffer. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
402 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
403 | if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CIPHER_CTX_encrypting(ctx) ?
| 0-317 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
404 | EVP_CTRL_GCM_IV_GEN : EVP_CTRL_GCM_SET_IV_INV,
| 0-317 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
405 | EVP_GCM_TLS_EXPLICIT_IV_LEN, out) <= 0)
| 0-317 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
406 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
407 | /* Use saved AAD */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
408 | if (CRYPTO_gcm128_aad(&gctx->gcm, EVP_CIPHER_CTX_buf_noconst(ctx),
| 0-317 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
409 | gctx->tls_aad_len))
| 0-317 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
410 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
411 | /* Fix buffer and length to point to payload */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
412 | in += EVP_GCM_TLS_EXPLICIT_IV_LEN; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
413 | out += EVP_GCM_TLS_EXPLICIT_IV_LEN; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
414 | len -= EVP_GCM_TLS_EXPLICIT_IV_LEN + EVP_GCM_TLS_TAG_LEN; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
415 | if (EVP_CIPHER_CTX_encrypting(ctx)) {
| 111-206 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
416 | /* Encrypt payload */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
417 | if (CRYPTO_gcm128_encrypt(&gctx->gcm, in, out, len))
| 0-206 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
418 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
419 | out += len; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
420 | /* Finally write tag */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
421 | CRYPTO_gcm128_tag(&gctx->gcm, out, EVP_GCM_TLS_TAG_LEN); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
422 | rv = len + EVP_GCM_TLS_EXPLICIT_IV_LEN + EVP_GCM_TLS_TAG_LEN; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
423 | } else { executed 206 times by 1 test: end of block Executed by:
| 206 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
424 | /* Decrypt */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
425 | if (CRYPTO_gcm128_decrypt(&gctx->gcm, in, out, len))
| 0-111 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
426 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
427 | /* Retrieve tag */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
428 | CRYPTO_gcm128_tag(&gctx->gcm, EVP_CIPHER_CTX_buf_noconst(ctx), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
429 | EVP_GCM_TLS_TAG_LEN); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
430 | /* If tag mismatch wipe buffer */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
431 | if (CRYPTO_memcmp(EVP_CIPHER_CTX_buf_noconst(ctx), in + len,
| 46-65 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
432 | EVP_GCM_TLS_TAG_LEN)) {
| 46-65 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
433 | OPENSSL_cleanse(out, len); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
434 | goto err; executed 65 times by 1 test: goto err; Executed by:
| 65 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
435 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
436 | rv = len; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
437 | } executed 46 times by 1 test: end of block Executed by:
| 46 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
438 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
439 | err: code before this statement executed 252 times by 1 test: err: Executed by:
| 252 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
440 | gctx->iv_set = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
441 | gctx->tls_aad_len = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
442 | return rv; executed 317 times by 1 test: return rv; Executed by:
| 317 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
443 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
444 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
445 | static int aria_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
446 | const unsigned char *in, size_t len) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
447 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
448 | EVP_ARIA_GCM_CTX *gctx = EVP_C_DATA(EVP_ARIA_GCM_CTX,ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
449 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
450 | /* If not set up, return error */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
451 | if (!gctx->key_set)
| 0-557 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
452 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
453 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
454 | if (gctx->tls_aad_len >= 0)
| 240-317 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
455 | return aria_gcm_tls_cipher(ctx, out, in, len); executed 317 times by 1 test: return aria_gcm_tls_cipher(ctx, out, in, len); Executed by:
| 317 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
456 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
457 | if (!gctx->iv_set)
| 0-240 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
458 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
459 | if (in) {
| 48-192 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
460 | if (out == NULL) {
| 96 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
461 | if (CRYPTO_gcm128_aad(&gctx->gcm, in, len))
| 0-96 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
462 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
463 | } else if (EVP_CIPHER_CTX_encrypting(ctx)) { executed 96 times by 1 test: end of block Executed by:
| 48-96 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
464 | if (CRYPTO_gcm128_encrypt(&gctx->gcm, in, out, len))
| 0-48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
465 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
466 | } else { executed 48 times by 1 test: end of block Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
467 | if (CRYPTO_gcm128_decrypt(&gctx->gcm, in, out, len))
| 0-48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
468 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
469 | } executed 48 times by 1 test: end of block Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
470 | return len; executed 192 times by 1 test: return len; Executed by:
| 192 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
471 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
472 | if (!EVP_CIPHER_CTX_encrypting(ctx)) {
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
473 | if (gctx->taglen < 0)
| 0-24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
474 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
475 | if (CRYPTO_gcm128_finish(&gctx->gcm,
| 0-24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
476 | EVP_CIPHER_CTX_buf_noconst(ctx),
| 0-24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
477 | gctx->taglen) != 0)
| 0-24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
478 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
479 | gctx->iv_set = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
480 | return 0; executed 24 times by 1 test: return 0; Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
481 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
482 | CRYPTO_gcm128_tag(&gctx->gcm, EVP_CIPHER_CTX_buf_noconst(ctx), 16); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
483 | gctx->taglen = 16; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
484 | /* Don't reuse the IV */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
485 | gctx->iv_set = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
486 | return 0; executed 24 times by 1 test: return 0; Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
487 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
488 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
489 | static int aria_ccm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
490 | const unsigned char *iv, int enc) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
491 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
492 | int ret; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
493 | EVP_ARIA_CCM_CTX *cctx = EVP_C_DATA(EVP_ARIA_CCM_CTX,ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
494 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
495 | if (!iv && !key)
| 0-72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
496 | return 1; executed 72 times by 1 test: return 1; Executed by:
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
497 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
498 | if (key) {
| 0-72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
499 | ret = aria_set_encrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
500 | &cctx->ks.ks); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
501 | CRYPTO_ccm128_init(&cctx->ccm, cctx->M, cctx->L, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
502 | &cctx->ks, (block128_f) aria_encrypt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
503 | if (ret < 0) {
| 0-72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
504 | EVPerr(EVP_F_ARIA_CCM_INIT_KEY,EVP_R_ARIA_KEY_SETUP_FAILED); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
505 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
506 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
507 | cctx->str = NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
508 | cctx->key_set = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
509 | } executed 72 times by 1 test: end of block Executed by:
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
510 | if (iv) {
| 0-72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
511 | memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), iv, 15 - cctx->L); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
512 | cctx->iv_set = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
513 | } executed 72 times by 1 test: end of block Executed by:
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
514 | return 1; executed 72 times by 1 test: return 1; Executed by:
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
515 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
516 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
517 | static int aria_ccm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
518 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
519 | EVP_ARIA_CCM_CTX *cctx = EVP_C_DATA(EVP_ARIA_CCM_CTX,c); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
520 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
521 | switch (type) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
522 | case EVP_CTRL_INIT: executed 72 times by 1 test: case 0x0: Executed by:
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
523 | cctx->key_set = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
524 | cctx->iv_set = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
525 | cctx->L = 8; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
526 | cctx->M = 12; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
527 | cctx->tag_set = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
528 | cctx->len_set = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
529 | cctx->tls_aad_len = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
530 | return 1; executed 72 times by 1 test: return 1; Executed by:
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
531 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
532 | case EVP_CTRL_AEAD_TLS1_AAD: never executed: case 0x16: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
533 | /* Save the AAD for later use */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
534 | if (arg != EVP_AEAD_TLS1_AAD_LEN)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
535 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
536 | memcpy(EVP_CIPHER_CTX_buf_noconst(c), ptr, arg); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
537 | cctx->tls_aad_len = arg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
538 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
539 | uint16_t len = | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
540 | EVP_CIPHER_CTX_buf_noconst(c)[arg - 2] << 8 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
541 | | EVP_CIPHER_CTX_buf_noconst(c)[arg - 1]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
542 | /* Correct length for explicit IV */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
543 | if (len < EVP_CCM_TLS_EXPLICIT_IV_LEN)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
544 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
545 | len -= EVP_CCM_TLS_EXPLICIT_IV_LEN; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
546 | /* If decrypting correct for tag too */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
547 | if (!EVP_CIPHER_CTX_encrypting(c)) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
548 | if (len < cctx->M)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
549 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
550 | len -= cctx->M; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
551 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
552 | EVP_CIPHER_CTX_buf_noconst(c)[arg - 2] = len >> 8; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
553 | EVP_CIPHER_CTX_buf_noconst(c)[arg - 1] = len & 0xff; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
554 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
555 | /* Extra padding: tag appended to record */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
556 | return cctx->M; never executed: return cctx->M; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
557 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
558 | case EVP_CTRL_CCM_SET_IV_FIXED: never executed: case 0x12: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
559 | /* Sanity check length */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
560 | if (arg != EVP_CCM_TLS_FIXED_IV_LEN)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
561 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
562 | /* Just copy to first part of IV */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
563 | memcpy(EVP_CIPHER_CTX_iv_noconst(c), ptr, arg); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
564 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
565 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
566 | case EVP_CTRL_AEAD_SET_IVLEN: executed 72 times by 1 test: case 0x9: Executed by:
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
567 | arg = 15 - arg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
568 | /* fall thru */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
569 | case EVP_CTRL_CCM_SET_L: code before this statement executed 72 times by 1 test: case 0x14: Executed by:
never executed: case 0x14: | 0-72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
570 | if (arg < 2 || arg > 8)
| 0-72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
571 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
572 | cctx->L = arg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
573 | return 1; executed 72 times by 1 test: return 1; Executed by:
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
574 | case EVP_CTRL_AEAD_SET_TAG: executed 72 times by 1 test: case 0x11: Executed by:
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
575 | if ((arg & 1) || arg < 4 || arg > 16)
| 0-72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
576 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
577 | if (EVP_CIPHER_CTX_encrypting(c) && ptr)
| 0-36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
578 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
579 | if (ptr) {
| 36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
580 | cctx->tag_set = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
581 | memcpy(EVP_CIPHER_CTX_buf_noconst(c), ptr, arg); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
582 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
583 | cctx->M = arg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
584 | return 1; executed 72 times by 1 test: return 1; Executed by:
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
585 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
586 | case EVP_CTRL_AEAD_GET_TAG: executed 36 times by 1 test: case 0x10: Executed by:
| 36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
587 | if (!EVP_CIPHER_CTX_encrypting(c) || !cctx->tag_set)
| 0-36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
588 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
589 | if (!CRYPTO_ccm128_tag(&cctx->ccm, ptr, (size_t)arg))
| 0-36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
590 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
591 | cctx->tag_set = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
592 | cctx->iv_set = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
593 | cctx->len_set = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
594 | return 1; executed 36 times by 1 test: return 1; Executed by:
| 36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
595 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
596 | case EVP_CTRL_COPY: never executed: case 0x8: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
597 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
598 | EVP_CIPHER_CTX *out = ptr; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
599 | EVP_ARIA_CCM_CTX *cctx_out = EVP_C_DATA(EVP_ARIA_CCM_CTX,out); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
600 | if (cctx->ccm.key) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
601 | if (cctx->ccm.key != &cctx->ks)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
602 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
603 | cctx_out->ccm.key = &cctx_out->ks; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
604 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
605 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
606 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
607 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
608 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
609 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
610 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
611 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
612 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
613 | static int aria_ccm_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
614 | const unsigned char *in, size_t len) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
615 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
616 | EVP_ARIA_CCM_CTX *cctx = EVP_C_DATA(EVP_ARIA_CCM_CTX,ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
617 | CCM128_CONTEXT *ccm = &cctx->ccm; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
618 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
619 | /* Encrypt/decrypt must be performed in place */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
620 | if (out != in || len < (EVP_CCM_TLS_EXPLICIT_IV_LEN + (size_t)cctx->M))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
621 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
622 | /* If encrypting set explicit IV from sequence number (start of AAD) */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
623 | if (EVP_CIPHER_CTX_encrypting(ctx))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
624 | memcpy(out, EVP_CIPHER_CTX_buf_noconst(ctx), never executed: memcpy(out, EVP_CIPHER_CTX_buf_noconst(ctx), 8); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
625 | EVP_CCM_TLS_EXPLICIT_IV_LEN); never executed: memcpy(out, EVP_CIPHER_CTX_buf_noconst(ctx), 8); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
626 | /* Get rest of IV from explicit IV */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
627 | memcpy(EVP_CIPHER_CTX_iv_noconst(ctx) + EVP_CCM_TLS_FIXED_IV_LEN, in, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
628 | EVP_CCM_TLS_EXPLICIT_IV_LEN); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
629 | /* Correct length value */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
630 | len -= EVP_CCM_TLS_EXPLICIT_IV_LEN + cctx->M; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
631 | if (CRYPTO_ccm128_setiv(ccm, EVP_CIPHER_CTX_iv_noconst(ctx), 15 - cctx->L,
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
632 | len))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
633 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
634 | /* Use saved AAD */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
635 | CRYPTO_ccm128_aad(ccm, EVP_CIPHER_CTX_buf_noconst(ctx), cctx->tls_aad_len); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
636 | /* Fix buffer to point to payload */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
637 | in += EVP_CCM_TLS_EXPLICIT_IV_LEN; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
638 | out += EVP_CCM_TLS_EXPLICIT_IV_LEN; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
639 | if (EVP_CIPHER_CTX_encrypting(ctx)) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
640 | if (cctx->str ? CRYPTO_ccm128_encrypt_ccm64(ccm, in, out, len, cctx->str)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
641 | : CRYPTO_ccm128_encrypt(ccm, in, out, len))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
642 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
643 | if (!CRYPTO_ccm128_tag(ccm, out + len, cctx->M))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
644 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
645 | return len + EVP_CCM_TLS_EXPLICIT_IV_LEN + cctx->M; never executed: return len + 8 + cctx->M; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
646 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
647 | if (cctx->str ? !CRYPTO_ccm128_decrypt_ccm64(ccm, in, out, len, cctx->str)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
648 | : !CRYPTO_ccm128_decrypt(ccm, in, out, len)) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
649 | unsigned char tag[16]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
650 | if (CRYPTO_ccm128_tag(ccm, tag, cctx->M)) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
651 | if (!CRYPTO_memcmp(tag, in + len, cctx->M))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
652 | return len; never executed: return len; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
653 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
654 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
655 | OPENSSL_cleanse(out, len); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
656 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
657 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
658 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
659 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
660 | static int aria_ccm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
661 | const unsigned char *in, size_t len) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
662 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
663 | EVP_ARIA_CCM_CTX *cctx = EVP_C_DATA(EVP_ARIA_CCM_CTX,ctx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
664 | CCM128_CONTEXT *ccm = &cctx->ccm; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
665 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
666 | /* If not set up, return error */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
667 | if (!cctx->key_set)
| 0-288 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
668 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
669 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
670 | if (cctx->tls_aad_len >= 0)
| 0-288 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
671 | return aria_ccm_tls_cipher(ctx, out, in, len); never executed: return aria_ccm_tls_cipher(ctx, out, in, len); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
672 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
673 | /* EVP_*Final() doesn't return any data */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
674 | if (in == NULL && out != NULL)
| 72-144 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
675 | return 0; executed 72 times by 1 test: return 0; Executed by:
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
676 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
677 | if (!cctx->iv_set)
| 0-216 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
678 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
679 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
680 | if (!EVP_CIPHER_CTX_encrypting(ctx) && !cctx->tag_set)
| 0-108 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
681 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
682 | if (!out) {
| 72-144 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
683 | if (!in) {
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
684 | if (CRYPTO_ccm128_setiv(ccm, EVP_CIPHER_CTX_iv_noconst(ctx),
| 0-72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
685 | 15 - cctx->L, len))
| 0-72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
686 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
687 | cctx->len_set = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
688 | return len; executed 72 times by 1 test: return len; Executed by:
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
689 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
690 | /* If have AAD need message length */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
691 | if (!cctx->len_set && len)
| 0-72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
692 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
693 | CRYPTO_ccm128_aad(ccm, in, len); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
694 | return len; executed 72 times by 1 test: return len; Executed by:
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
695 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
696 | /* If not set length yet do it */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
697 | if (!cctx->len_set) {
| 0-72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
698 | if (CRYPTO_ccm128_setiv(ccm, EVP_CIPHER_CTX_iv_noconst(ctx),
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
699 | 15 - cctx->L, len))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
700 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
701 | cctx->len_set = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
702 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
703 | if (EVP_CIPHER_CTX_encrypting(ctx)) {
| 36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
704 | if (cctx->str ? CRYPTO_ccm128_encrypt_ccm64(ccm, in, out, len, cctx->str)
| 0-36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
705 | : CRYPTO_ccm128_encrypt(ccm, in, out, len))
| 0-36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
706 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
707 | cctx->tag_set = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
708 | return len; executed 36 times by 1 test: return len; Executed by:
| 36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
709 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
710 | int rv = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
711 | if (cctx->str ? !CRYPTO_ccm128_decrypt_ccm64(ccm, in, out, len,
| 0-36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
712 | cctx->str) :
| 0-36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
713 | !CRYPTO_ccm128_decrypt(ccm, in, out, len)) {
| 0-36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
714 | unsigned char tag[16]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
715 | if (CRYPTO_ccm128_tag(ccm, tag, cctx->M)) {
| 0-36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
716 | if (!CRYPTO_memcmp(tag, EVP_CIPHER_CTX_buf_noconst(ctx),
| 0-36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
717 | cctx->M))
| 0-36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
718 | rv = len; executed 36 times by 1 test: rv = len; Executed by:
| 36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
719 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
720 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
721 | if (rv == -1)
| 0-36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
722 | OPENSSL_cleanse(out, len); never executed: OPENSSL_cleanse(out, len); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
723 | cctx->iv_set = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
724 | cctx->tag_set = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
725 | cctx->len_set = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
726 | return rv; executed 36 times by 1 test: return rv; Executed by:
| 36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
727 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
728 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
729 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
730 | #define ARIA_AUTH_FLAGS (EVP_CIPH_FLAG_DEFAULT_ASN1 \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
731 | | EVP_CIPH_CUSTOM_IV | EVP_CIPH_FLAG_CUSTOM_CIPHER \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
732 | | EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CTRL_INIT \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
733 | | EVP_CIPH_CUSTOM_COPY | EVP_CIPH_FLAG_AEAD_CIPHER) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
734 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
735 | #define BLOCK_CIPHER_aead(nid,keylen,blocksize,ivlen,nmode,mode,MODE,flags) \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
736 | static const EVP_CIPHER aria_##keylen##_##mode = { \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
737 | nid##_##keylen##_##nmode, \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
738 | blocksize, keylen/8, ivlen, \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
739 | ARIA_AUTH_FLAGS|EVP_CIPH_##MODE##_MODE, \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
740 | aria_##mode##_init_key, \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
741 | aria_##mode##_cipher, \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
742 | NULL, \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
743 | sizeof(EVP_ARIA_##MODE##_CTX), \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
744 | NULL,NULL,aria_##mode##_ctrl,NULL }; \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
745 | const EVP_CIPHER *EVP_aria_##keylen##_##mode(void) \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
746 | { return (EVP_CIPHER*)&aria_##keylen##_##mode; } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
747 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
748 | BLOCK_CIPHER_aead(NID_aria, 128, 1, 12, gcm, gcm, GCM, 0) executed 3920 times by 1 test: return (EVP_CIPHER*)&aria_128_gcm; Executed by:
| 3920 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
749 | BLOCK_CIPHER_aead(NID_aria, 192, 1, 12, gcm, gcm, GCM, 0) executed 1962 times by 1 test: return (EVP_CIPHER*)&aria_192_gcm; Executed by:
| 1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
750 | BLOCK_CIPHER_aead(NID_aria, 256, 1, 12, gcm, gcm, GCM, 0) executed 3920 times by 1 test: return (EVP_CIPHER*)&aria_256_gcm; Executed by:
| 3920 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
751 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
752 | BLOCK_CIPHER_aead(NID_aria, 128, 1, 12, ccm, ccm, CCM, 0) executed 1962 times by 1 test: return (EVP_CIPHER*)&aria_128_ccm; Executed by:
| 1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
753 | BLOCK_CIPHER_aead(NID_aria, 192, 1, 12, ccm, ccm, CCM, 0) executed 1962 times by 1 test: return (EVP_CIPHER*)&aria_192_ccm; Executed by:
| 1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
754 | BLOCK_CIPHER_aead(NID_aria, 256, 1, 12, ccm, ccm, CCM, 0) executed 1962 times by 1 test: return (EVP_CIPHER*)&aria_256_ccm; Executed by:
| 1962 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
755 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
756 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |