Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/evp/e_gost2814789.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||||||||
4 | - | |||||||||||||||||||||||||||||||
5 | typedef struct { | - | ||||||||||||||||||||||||||||||
6 | GOST2814789_KEY ks; | - | ||||||||||||||||||||||||||||||
7 | int param_nid; | - | ||||||||||||||||||||||||||||||
8 | } EVP_GOST2814789_CTX; | - | ||||||||||||||||||||||||||||||
9 | - | |||||||||||||||||||||||||||||||
10 | static int | - | ||||||||||||||||||||||||||||||
11 | gost2814789_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) | - | ||||||||||||||||||||||||||||||
12 | { | - | ||||||||||||||||||||||||||||||
13 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | - | ||||||||||||||||||||||||||||||
14 | - | |||||||||||||||||||||||||||||||
15 | switch (type) { | - | ||||||||||||||||||||||||||||||
16 | case never executed: 0x7:case 0x7: never executed: case 0x7: | 0 | ||||||||||||||||||||||||||||||
17 | if (ptr !=
| 0 | ||||||||||||||||||||||||||||||
18 | ((void *)0)
| 0 | ||||||||||||||||||||||||||||||
19 | ) { | - | ||||||||||||||||||||||||||||||
20 | *((int *)ptr) = 810; | - | ||||||||||||||||||||||||||||||
21 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||
22 | } else { | - | ||||||||||||||||||||||||||||||
23 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
24 | } | - | ||||||||||||||||||||||||||||||
25 | case executed 12 times by 1 test: 0x0:case 0x0: Executed by:
executed 12 times by 1 test: case 0x0: Executed by:
| 12 | ||||||||||||||||||||||||||||||
26 | - | |||||||||||||||||||||||||||||||
27 | c->param_nid = 824; | - | ||||||||||||||||||||||||||||||
28 | return executed 12 times by 1 test: Gost2814789_set_sbox(&c->ks, c->param_nid);return Gost2814789_set_sbox(&c->ks, c->param_nid); Executed by:
executed 12 times by 1 test: return Gost2814789_set_sbox(&c->ks, c->param_nid); Executed by:
| 12 | ||||||||||||||||||||||||||||||
29 | case executed 12 times by 1 test: 0x19:case 0x19: Executed by:
executed 12 times by 1 test: case 0x19: Executed by:
| 12 | ||||||||||||||||||||||||||||||
30 | return executed 12 times by 1 test: Gost2814789_set_sbox(&c->ks, arg);return Gost2814789_set_sbox(&c->ks, arg); Executed by:
executed 12 times by 1 test: return Gost2814789_set_sbox(&c->ks, arg); Executed by:
| 12 | ||||||||||||||||||||||||||||||
31 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
32 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||
33 | } | - | ||||||||||||||||||||||||||||||
34 | } | - | ||||||||||||||||||||||||||||||
35 | - | |||||||||||||||||||||||||||||||
36 | static int | - | ||||||||||||||||||||||||||||||
37 | gost2814789_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | - | ||||||||||||||||||||||||||||||
38 | const unsigned char *iv, int enc) | - | ||||||||||||||||||||||||||||||
39 | { | - | ||||||||||||||||||||||||||||||
40 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | - | ||||||||||||||||||||||||||||||
41 | - | |||||||||||||||||||||||||||||||
42 | return executed 12 times by 1 test: Gost2814789_set_key(&c->ks, key, ctx->key_len * 8);return Gost2814789_set_key(&c->ks, key, ctx->key_len * 8); Executed by:
executed 12 times by 1 test: return Gost2814789_set_key(&c->ks, key, ctx->key_len * 8); Executed by:
| 12 | ||||||||||||||||||||||||||||||
43 | } | - | ||||||||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||||||||
45 | int | - | ||||||||||||||||||||||||||||||
46 | gost2814789_set_asn1_params(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params) | - | ||||||||||||||||||||||||||||||
47 | { | - | ||||||||||||||||||||||||||||||
48 | int len = 0; | - | ||||||||||||||||||||||||||||||
49 | unsigned char *buf = | - | ||||||||||||||||||||||||||||||
50 | ((void *)0) | - | ||||||||||||||||||||||||||||||
51 | ; | - | ||||||||||||||||||||||||||||||
52 | unsigned char *p = | - | ||||||||||||||||||||||||||||||
53 | ((void *)0) | - | ||||||||||||||||||||||||||||||
54 | ; | - | ||||||||||||||||||||||||||||||
55 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | - | ||||||||||||||||||||||||||||||
56 | ASN1_OCTET_STRING *os = | - | ||||||||||||||||||||||||||||||
57 | ((void *)0) | - | ||||||||||||||||||||||||||||||
58 | ; | - | ||||||||||||||||||||||||||||||
59 | GOST_CIPHER_PARAMS *gcp = GOST_CIPHER_PARAMS_new(); | - | ||||||||||||||||||||||||||||||
60 | - | |||||||||||||||||||||||||||||||
61 | if (gcp ==
| 0 | ||||||||||||||||||||||||||||||
62 | ((void *)0)
| 0 | ||||||||||||||||||||||||||||||
63 | ) { | - | ||||||||||||||||||||||||||||||
64 | ERR_put_error(50,(0xfff),((1|64)),__FILE__,110); | - | ||||||||||||||||||||||||||||||
65 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
66 | } | - | ||||||||||||||||||||||||||||||
67 | if (ASN1_OCTET_STRING_set(gcp->iv, ctx->iv, ctx->cipher->iv_len) == 0
| 0 | ||||||||||||||||||||||||||||||
68 | GOST_CIPHER_PARAMS_free(gcp); | - | ||||||||||||||||||||||||||||||
69 | ERR_put_error(50,(0xfff),(13),__FILE__,115); | - | ||||||||||||||||||||||||||||||
70 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
71 | } | - | ||||||||||||||||||||||||||||||
72 | ASN1_OBJECT_free(gcp->enc_param_set); | - | ||||||||||||||||||||||||||||||
73 | gcp->enc_param_set = OBJ_nid2obj(c->param_nid); | - | ||||||||||||||||||||||||||||||
74 | - | |||||||||||||||||||||||||||||||
75 | len = i2d_GOST_CIPHER_PARAMS(gcp, | - | ||||||||||||||||||||||||||||||
76 | ((void *)0) | - | ||||||||||||||||||||||||||||||
77 | ); | - | ||||||||||||||||||||||||||||||
78 | p = buf = malloc(len); | - | ||||||||||||||||||||||||||||||
79 | if (buf ==
| 0 | ||||||||||||||||||||||||||||||
80 | ((void *)0)
| 0 | ||||||||||||||||||||||||||||||
81 | ) { | - | ||||||||||||||||||||||||||||||
82 | GOST_CIPHER_PARAMS_free(gcp); | - | ||||||||||||||||||||||||||||||
83 | ERR_put_error(50,(0xfff),((1|64)),__FILE__,125); | - | ||||||||||||||||||||||||||||||
84 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
85 | } | - | ||||||||||||||||||||||||||||||
86 | i2d_GOST_CIPHER_PARAMS(gcp, &p); | - | ||||||||||||||||||||||||||||||
87 | GOST_CIPHER_PARAMS_free(gcp); | - | ||||||||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||||||||
89 | os = ASN1_OCTET_STRING_new(); | - | ||||||||||||||||||||||||||||||
90 | if (os ==
| 0 | ||||||||||||||||||||||||||||||
91 | ((void *)0)
| 0 | ||||||||||||||||||||||||||||||
92 | ) { | - | ||||||||||||||||||||||||||||||
93 | free(buf); | - | ||||||||||||||||||||||||||||||
94 | ERR_put_error(50,(0xfff),((1|64)),__FILE__,134); | - | ||||||||||||||||||||||||||||||
95 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
96 | } | - | ||||||||||||||||||||||||||||||
97 | if (ASN1_OCTET_STRING_set(os, buf, len) == 0
| 0 | ||||||||||||||||||||||||||||||
98 | ASN1_OCTET_STRING_free(os); | - | ||||||||||||||||||||||||||||||
99 | free(buf); | - | ||||||||||||||||||||||||||||||
100 | ERR_put_error(50,(0xfff),(13),__FILE__,140); | - | ||||||||||||||||||||||||||||||
101 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
102 | } | - | ||||||||||||||||||||||||||||||
103 | free(buf); | - | ||||||||||||||||||||||||||||||
104 | - | |||||||||||||||||||||||||||||||
105 | ASN1_TYPE_set(params, 16, os); | - | ||||||||||||||||||||||||||||||
106 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||
107 | } | - | ||||||||||||||||||||||||||||||
108 | - | |||||||||||||||||||||||||||||||
109 | int | - | ||||||||||||||||||||||||||||||
110 | gost2814789_get_asn1_params(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params) | - | ||||||||||||||||||||||||||||||
111 | { | - | ||||||||||||||||||||||||||||||
112 | int ret = -1; | - | ||||||||||||||||||||||||||||||
113 | int len; | - | ||||||||||||||||||||||||||||||
114 | GOST_CIPHER_PARAMS *gcp = | - | ||||||||||||||||||||||||||||||
115 | ((void *)0) | - | ||||||||||||||||||||||||||||||
116 | ; | - | ||||||||||||||||||||||||||||||
117 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | - | ||||||||||||||||||||||||||||||
118 | unsigned char *p; | - | ||||||||||||||||||||||||||||||
119 | - | |||||||||||||||||||||||||||||||
120 | if (ASN1_TYPE_get(params) != 16
| 0 | ||||||||||||||||||||||||||||||
121 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||||||||
123 | p = params->value.sequence->data; | - | ||||||||||||||||||||||||||||||
124 | - | |||||||||||||||||||||||||||||||
125 | gcp = d2i_GOST_CIPHER_PARAMS( | - | ||||||||||||||||||||||||||||||
126 | ((void *)0) | - | ||||||||||||||||||||||||||||||
127 | , (const unsigned char **)&p, | - | ||||||||||||||||||||||||||||||
128 | params->value.sequence->length); | - | ||||||||||||||||||||||||||||||
129 | - | |||||||||||||||||||||||||||||||
130 | len = gcp->iv->length; | - | ||||||||||||||||||||||||||||||
131 | if (len != ctx->cipher->iv_len
| 0 | ||||||||||||||||||||||||||||||
132 | GOST_CIPHER_PARAMS_free(gcp); | - | ||||||||||||||||||||||||||||||
133 | ERR_put_error(50,(0xfff),(103),__FILE__,169); | - | ||||||||||||||||||||||||||||||
134 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||
135 | } | - | ||||||||||||||||||||||||||||||
136 | - | |||||||||||||||||||||||||||||||
137 | if (!Gost2814789_set_sbox(&c->ks, OBJ_obj2nid(gcp->enc_param_set))
| 0 | ||||||||||||||||||||||||||||||
138 | GOST_CIPHER_PARAMS_free(gcp); | - | ||||||||||||||||||||||||||||||
139 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||
140 | } | - | ||||||||||||||||||||||||||||||
141 | c->param_nid = OBJ_obj2nid(gcp->enc_param_set); | - | ||||||||||||||||||||||||||||||
142 | - | |||||||||||||||||||||||||||||||
143 | memcpy(ctx->oiv, gcp->iv->data, len); | - | ||||||||||||||||||||||||||||||
144 | memcpy(ctx->iv, gcp->iv->data, len); | - | ||||||||||||||||||||||||||||||
145 | - | |||||||||||||||||||||||||||||||
146 | GOST_CIPHER_PARAMS_free(gcp); | - | ||||||||||||||||||||||||||||||
147 | - | |||||||||||||||||||||||||||||||
148 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||
149 | } | - | ||||||||||||||||||||||||||||||
150 | - | |||||||||||||||||||||||||||||||
151 | static int gost2814789_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) { size_t i, bl; bl = ctx->cipher->block_size; if(inl < bl
never executed: 1;return 1; never executed: inl -= bl; for(i=0; i <= inlreturn 1;
executed 5 times by 1 test: returnGost2814789_ecb_encrypt(in + i, out + i, &((EVP_GOST2814789_CTX *)ctx->cipher_data)->ks, ctx->encrypt); Executed by:
executed 4 times by 1 test: 1;return 1; Executed by:
executed 4 times by 1 test: }return 1; Executed by:
| 0-5 | ||||||||||||||||||||||||||||||
152 | static int gost2814789_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) { size_t chunk=((size_t)1<<(sizeof(long)*8-2)); if (64==1
never executed: if (inl<chunkchunk>>=3;
executed 5 times by 1 test: while(inlchunk=inl; Executed by:
executed 5 times by 1 test: }chunk=inl; Executed by:
executed 5 times by 1 test: returnend of block Executed by:
executed 5 times by 1 test: 1;return 1; Executed by:
executed 5 times by 1 test: }return 1; Executed by:
| 0-5 | ||||||||||||||||||||||||||||||
153 | - | |||||||||||||||||||||||||||||||
154 | static int | - | ||||||||||||||||||||||||||||||
155 | gost2814789_cnt_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||||||||||||||||||||||||||
156 | const unsigned char *in, size_t inl) | - | ||||||||||||||||||||||||||||||
157 | { | - | ||||||||||||||||||||||||||||||
158 | EVP_GOST2814789_CTX *c = ctx->cipher_data; | - | ||||||||||||||||||||||||||||||
159 | - | |||||||||||||||||||||||||||||||
160 | while (inl >= ((size_t)1<<(sizeof(long)*8-2))
| 0-3 | ||||||||||||||||||||||||||||||
161 | Gost2814789_cnt_encrypt(in, out, (long)((size_t)1<<(sizeof(long)*8-2)), &c->ks, | - | ||||||||||||||||||||||||||||||
162 | ctx->iv, ctx->buf, &ctx->num); | - | ||||||||||||||||||||||||||||||
163 | inl -= ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||||||||||||||||||||
164 | in += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||||||||||||||||||||
165 | out += ((size_t)1<<(sizeof(long)*8-2)); | - | ||||||||||||||||||||||||||||||
166 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
167 | - | |||||||||||||||||||||||||||||||
168 | if (inl
| 0-3 | ||||||||||||||||||||||||||||||
169 | Gost2814789_cnt_encrypt(in, out, inl, &c->ks, ctx->iv, ctx->buf, executed 3 times by 1 test: Gost2814789_cnt_encrypt(in, out, inl, &c->ks, ctx->iv, ctx->buf, &ctx->num); Executed by:
| 3 | ||||||||||||||||||||||||||||||
170 | &ctx->num); executed 3 times by 1 test: Gost2814789_cnt_encrypt(in, out, inl, &c->ks, ctx->iv, ctx->buf, &ctx->num); Executed by:
| 3 | ||||||||||||||||||||||||||||||
171 | return executed 3 times by 1 test: 1;return 1; Executed by:
executed 3 times by 1 test: return 1; Executed by:
| 3 | ||||||||||||||||||||||||||||||
172 | } | - | ||||||||||||||||||||||||||||||
173 | - | |||||||||||||||||||||||||||||||
174 | - | |||||||||||||||||||||||||||||||
175 | - | |||||||||||||||||||||||||||||||
176 | - | |||||||||||||||||||||||||||||||
177 | static const EVP_CIPHER gost2814789_ecb = { 938, 8, 32, 0, 0x100 | 0x40 | 0x1, gost2814789_init_key, gost2814789_ecb_cipher, | - | ||||||||||||||||||||||||||||||
178 | ((void *)0) | - | ||||||||||||||||||||||||||||||
179 | , sizeof(EVP_GOST2814789_CTX), gost2814789_set_asn1_params, gost2814789_get_asn1_params, gost2814789_ctl, | - | ||||||||||||||||||||||||||||||
180 | ((void *)0) | - | ||||||||||||||||||||||||||||||
181 | }; const EVP_CIPHER *EVP_gost2814789_ecb(void) { return executed 292 times by 33 tests: &gost2814789_ecb;return &gost2814789_ecb; Executed by:
executed 292 times by 33 tests: }return &gost2814789_ecb; Executed by:
| 292 | ||||||||||||||||||||||||||||||
182 | - | |||||||||||||||||||||||||||||||
183 | - | |||||||||||||||||||||||||||||||
184 | - | |||||||||||||||||||||||||||||||
185 | static const EVP_CIPHER gost2814789_cfb64 = { 813, 1, 32, 8, 0x100 | 0x40 | 0x3, gost2814789_init_key, gost2814789_cfb64_cipher, | - | ||||||||||||||||||||||||||||||
186 | ((void *)0) | - | ||||||||||||||||||||||||||||||
187 | , sizeof(EVP_GOST2814789_CTX), gost2814789_set_asn1_params, gost2814789_get_asn1_params, gost2814789_ctl, | - | ||||||||||||||||||||||||||||||
188 | ((void *)0) | - | ||||||||||||||||||||||||||||||
189 | }; const EVP_CIPHER *EVP_gost2814789_cfb64(void) { return executed 625 times by 33 tests: &gost2814789_cfb64;return &gost2814789_cfb64; Executed by:
executed 625 times by 33 tests: }return &gost2814789_cfb64; Executed by:
| 625 | ||||||||||||||||||||||||||||||
190 | - | |||||||||||||||||||||||||||||||
191 | - | |||||||||||||||||||||||||||||||
192 | - | |||||||||||||||||||||||||||||||
193 | static const EVP_CIPHER gost2814789_cnt = { 814, 1, 32, 8, 0x100 | 0x40 | 0x4, gost2814789_init_key, gost2814789_cnt_cipher, | - | ||||||||||||||||||||||||||||||
194 | ((void *)0) | - | ||||||||||||||||||||||||||||||
195 | , sizeof(EVP_GOST2814789_CTX), gost2814789_set_asn1_params, gost2814789_get_asn1_params, gost2814789_ctl, | - | ||||||||||||||||||||||||||||||
196 | ((void *)0) | - | ||||||||||||||||||||||||||||||
197 | }; const EVP_CIPHER *EVP_gost2814789_cnt(void) { return executed 625 times by 33 tests: &gost2814789_cnt;return &gost2814789_cnt; Executed by:
executed 625 times by 33 tests: }return &gost2814789_cnt; Executed by:
| 625 | ||||||||||||||||||||||||||||||
Switch to Source code | Preprocessed file |