@@ -31,7 +31,7 @@ namespace {
31
31
// Implements general AES encryption and decryption for CBC
32
32
// The key_data must be a secret key.
33
33
// On success, this function sets out to a new AllocatedBuffer
34
- // instance containing the results and returns WebCryptoCipherStatus::ERR_OK .
34
+ // instance containing the results and returns WebCryptoCipherStatus::OK .
35
35
WebCryptoCipherStatus AES_Cipher (
36
36
Environment* env,
37
37
KeyObjectData* key_data,
@@ -59,15 +59,15 @@ WebCryptoCipherStatus AES_Cipher(
59
59
nullptr ,
60
60
encrypt )) {
61
61
// Cipher init failed
62
- return WebCryptoCipherStatus::ERR_FAILED ;
62
+ return WebCryptoCipherStatus::FAILED ;
63
63
}
64
64
65
65
if (mode == EVP_CIPH_GCM_MODE && !EVP_CIPHER_CTX_ctrl (
66
66
ctx.get (),
67
67
EVP_CTRL_AEAD_SET_IVLEN,
68
68
params.iv .size (),
69
69
nullptr )) {
70
- return WebCryptoCipherStatus::ERR_FAILED ;
70
+ return WebCryptoCipherStatus::FAILED ;
71
71
}
72
72
73
73
if (!EVP_CIPHER_CTX_set_key_length (
@@ -80,7 +80,7 @@ WebCryptoCipherStatus AES_Cipher(
80
80
reinterpret_cast <const unsigned char *>(key_data->GetSymmetricKey ()),
81
81
params.iv .data <unsigned char >(),
82
82
encrypt )) {
83
- return WebCryptoCipherStatus::ERR_FAILED ;
83
+ return WebCryptoCipherStatus::FAILED ;
84
84
}
85
85
86
86
size_t tag_len = 0 ;
@@ -95,7 +95,7 @@ WebCryptoCipherStatus AES_Cipher(
95
95
EVP_CTRL_AEAD_SET_TAG,
96
96
params.tag .size (),
97
97
const_cast <char *>(params.tag .get ()))) {
98
- return WebCryptoCipherStatus::ERR_FAILED ;
98
+ return WebCryptoCipherStatus::FAILED ;
99
99
}
100
100
break ;
101
101
case kWebCryptoCipherEncrypt :
@@ -123,7 +123,7 @@ WebCryptoCipherStatus AES_Cipher(
123
123
&out_len,
124
124
params.additional_data .data <unsigned char >(),
125
125
params.additional_data .size ())) {
126
- return WebCryptoCipherStatus::ERR_FAILED ;
126
+ return WebCryptoCipherStatus::FAILED ;
127
127
}
128
128
129
129
char * data = MallocOpenSSL<char >(buf_len);
@@ -136,15 +136,15 @@ WebCryptoCipherStatus AES_Cipher(
136
136
&out_len,
137
137
in.data <unsigned char >(),
138
138
in.size ())) {
139
- return WebCryptoCipherStatus::ERR_FAILED ;
139
+ return WebCryptoCipherStatus::FAILED ;
140
140
}
141
141
142
142
total += out_len;
143
143
CHECK_LE (out_len, buf_len);
144
144
ptr += out_len;
145
145
out_len = EVP_CIPHER_CTX_block_size (ctx.get ());
146
146
if (!EVP_CipherFinal_ex (ctx.get (), ptr, &out_len)) {
147
- return WebCryptoCipherStatus::ERR_FAILED ;
147
+ return WebCryptoCipherStatus::FAILED ;
148
148
}
149
149
total += out_len;
150
150
@@ -153,15 +153,15 @@ WebCryptoCipherStatus AES_Cipher(
153
153
if (cipher_mode == kWebCryptoCipherEncrypt && mode == EVP_CIPH_GCM_MODE) {
154
154
data += out_len;
155
155
if (!EVP_CIPHER_CTX_ctrl (ctx.get (), EVP_CTRL_AEAD_GET_TAG, tag_len, ptr))
156
- return WebCryptoCipherStatus::ERR_FAILED ;
156
+ return WebCryptoCipherStatus::FAILED ;
157
157
total += tag_len;
158
158
}
159
159
160
160
// It's possible that we haven't used the full allocated space. Size down.
161
161
buf.Resize (total);
162
162
*out = std::move (buf);
163
163
164
- return WebCryptoCipherStatus::ERR_OK ;
164
+ return WebCryptoCipherStatus::OK ;
165
165
}
166
166
167
167
// The AES_CTR implementation here takes it's inspiration from the chromium
@@ -232,7 +232,7 @@ WebCryptoCipherStatus AES_CTR_Cipher2(
232
232
counter,
233
233
encrypt )) {
234
234
// Cipher init failed
235
- return WebCryptoCipherStatus::ERR_FAILED ;
235
+ return WebCryptoCipherStatus::FAILED ;
236
236
}
237
237
238
238
int out_len = 0 ;
@@ -243,17 +243,17 @@ WebCryptoCipherStatus AES_CTR_Cipher2(
243
243
&out_len,
244
244
in.data <unsigned char >(),
245
245
in.size ())) {
246
- return WebCryptoCipherStatus::ERR_FAILED ;
246
+ return WebCryptoCipherStatus::FAILED ;
247
247
}
248
248
249
249
if (!EVP_CipherFinal_ex (ctx.get (), out + out_len, &final_len))
250
- return WebCryptoCipherStatus::ERR_FAILED ;
250
+ return WebCryptoCipherStatus::FAILED ;
251
251
252
252
out_len += final_len;
253
253
if (static_cast <unsigned >(out_len) != in.size ())
254
- return WebCryptoCipherStatus::ERR_FAILED ;
254
+ return WebCryptoCipherStatus::FAILED ;
255
255
256
- return WebCryptoCipherStatus::ERR_OK ;
256
+ return WebCryptoCipherStatus::OK ;
257
257
}
258
258
259
259
WebCryptoCipherStatus AES_CTR_Cipher (
@@ -265,25 +265,25 @@ WebCryptoCipherStatus AES_CTR_Cipher(
265
265
ByteSource* out) {
266
266
BignumPointer num_counters (BN_new ());
267
267
if (!BN_lshift (num_counters.get (), BN_value_one (), params.length ))
268
- return WebCryptoCipherStatus::ERR_FAILED ;
268
+ return WebCryptoCipherStatus::FAILED ;
269
269
270
270
BignumPointer current_counter = GetCounter (params);
271
271
272
272
BignumPointer num_output (BN_new ());
273
273
274
274
if (!BN_set_word (num_output.get (), CeilDiv (in.size (), kAesBlockSize )))
275
- return WebCryptoCipherStatus::ERR_FAILED ;
275
+ return WebCryptoCipherStatus::FAILED ;
276
276
277
277
// Just like in chromium's implementation, if the counter will
278
278
// be incremented more than there are counter values, we fail.
279
279
if (BN_cmp (num_output.get (), num_counters.get ()) > 0 )
280
- return WebCryptoCipherStatus::ERR_FAILED ;
280
+ return WebCryptoCipherStatus::FAILED ;
281
281
282
282
BignumPointer remaining_until_reset (BN_new ());
283
283
if (!BN_sub (remaining_until_reset.get (),
284
284
num_counters.get (),
285
285
current_counter.get ())) {
286
- return WebCryptoCipherStatus::ERR_FAILED ;
286
+ return WebCryptoCipherStatus::FAILED ;
287
287
}
288
288
289
289
// Output size is identical to the input size
@@ -302,7 +302,7 @@ WebCryptoCipherStatus AES_CTR_Cipher(
302
302
in,
303
303
params.iv .data <unsigned char >(),
304
304
ptr);
305
- if (status == WebCryptoCipherStatus::ERR_OK )
305
+ if (status == WebCryptoCipherStatus::OK )
306
306
*out = std::move (buf);
307
307
return status;
308
308
}
@@ -319,7 +319,7 @@ WebCryptoCipherStatus AES_CTR_Cipher(
319
319
params.iv .data <unsigned char >(),
320
320
ptr);
321
321
322
- if (status != WebCryptoCipherStatus::ERR_OK )
322
+ if (status != WebCryptoCipherStatus::OK )
323
323
return status;
324
324
325
325
// Wrap the counter around to zero
@@ -336,7 +336,7 @@ WebCryptoCipherStatus AES_CTR_Cipher(
336
336
new_counter_block.data (),
337
337
ptr + input_size_part1);
338
338
339
- if (status == WebCryptoCipherStatus::ERR_OK )
339
+ if (status == WebCryptoCipherStatus::OK )
340
340
*out = std::move (buf);
341
341
342
342
return status;
0 commit comments