14
14
AESCCM ,
15
15
AESGCM ,
16
16
AESOCB3 ,
17
- AESSIV ,
18
17
ChaCha20Poly1305 ,
19
18
)
20
19
21
- _AEADTypes = typing .Union [
22
- AESCCM , AESGCM , AESOCB3 , AESSIV , ChaCha20Poly1305
23
- ]
20
+ _AEADTypes = typing .Union [AESCCM , AESGCM , AESOCB3 , ChaCha20Poly1305 ]
24
21
25
22
26
23
def _is_evp_aead_supported_cipher (
@@ -44,16 +41,9 @@ def _aead_cipher_supported(backend: Backend, cipher: _AEADTypes) -> bool:
44
41
cipher_name = _evp_cipher_cipher_name (cipher )
45
42
if backend ._fips_enabled and cipher_name not in backend ._fips_aead :
46
43
return False
47
- # SIV isn't loaded through get_cipherbyname but instead a new fetch API
48
- # only available in 3.0+. But if we know we're on 3.0+ then we know
49
- # it's supported.
50
- if cipher_name .endswith (b"-siv" ):
51
- return backend ._lib .CRYPTOGRAPHY_OPENSSL_300_OR_GREATER == 1
52
- else :
53
- return (
54
- backend ._lib .EVP_get_cipherbyname (cipher_name )
55
- != backend ._ffi .NULL
56
- )
44
+ return (
45
+ backend ._lib .EVP_get_cipherbyname (cipher_name ) != backend ._ffi .NULL
46
+ )
57
47
58
48
59
49
def _aead_create_ctx (
@@ -231,7 +221,6 @@ def _evp_cipher_cipher_name(cipher: _AEADTypes) -> bytes:
231
221
AESCCM ,
232
222
AESGCM ,
233
223
AESOCB3 ,
234
- AESSIV ,
235
224
ChaCha20Poly1305 ,
236
225
)
237
226
@@ -241,26 +230,14 @@ def _evp_cipher_cipher_name(cipher: _AEADTypes) -> bytes:
241
230
return f"aes-{ len (cipher ._key ) * 8 } -ccm" .encode ("ascii" )
242
231
elif isinstance (cipher , AESOCB3 ):
243
232
return f"aes-{ len (cipher ._key ) * 8 } -ocb" .encode ("ascii" )
244
- elif isinstance (cipher , AESSIV ):
245
- return f"aes-{ len (cipher ._key ) * 8 // 2 } -siv" .encode ("ascii" )
246
233
else :
247
234
assert isinstance (cipher , AESGCM )
248
235
return f"aes-{ len (cipher ._key ) * 8 } -gcm" .encode ("ascii" )
249
236
250
237
251
238
def _evp_cipher (cipher_name : bytes , backend : Backend ):
252
- if cipher_name .endswith (b"-siv" ):
253
- evp_cipher = backend ._lib .EVP_CIPHER_fetch (
254
- backend ._ffi .NULL ,
255
- cipher_name ,
256
- backend ._ffi .NULL ,
257
- )
258
- backend .openssl_assert (evp_cipher != backend ._ffi .NULL )
259
- evp_cipher = backend ._ffi .gc (evp_cipher , backend ._lib .EVP_CIPHER_free )
260
- else :
261
- evp_cipher = backend ._lib .EVP_get_cipherbyname (cipher_name )
262
- backend .openssl_assert (evp_cipher != backend ._ffi .NULL )
263
-
239
+ evp_cipher = backend ._lib .EVP_get_cipherbyname (cipher_name )
240
+ backend .openssl_assert (evp_cipher != backend ._ffi .NULL )
264
241
return evp_cipher
265
242
266
243
@@ -389,10 +366,7 @@ def _evp_cipher_process_data(backend: Backend, ctx, data: bytes) -> bytes:
389
366
buf = backend ._ffi .new ("unsigned char[]" , len (data ))
390
367
data_ptr = backend ._ffi .from_buffer (data )
391
368
res = backend ._lib .EVP_CipherUpdate (ctx , buf , outlen , data_ptr , len (data ))
392
- if res == 0 :
393
- # AES SIV can error here if the data is invalid on decrypt
394
- backend ._consume_errors ()
395
- raise InvalidTag
369
+ backend .openssl_assert (res != 0 )
396
370
return backend ._ffi .buffer (buf , outlen [0 ])[:]
397
371
398
372
@@ -405,7 +379,7 @@ def _evp_cipher_encrypt(
405
379
tag_length : int ,
406
380
ctx : typing .Any = None ,
407
381
) -> bytes :
408
- from cryptography .hazmat .primitives .ciphers .aead import AESCCM , AESSIV
382
+ from cryptography .hazmat .primitives .ciphers .aead import AESCCM
409
383
410
384
if ctx is None :
411
385
cipher_name = _evp_cipher_cipher_name (cipher )
@@ -445,14 +419,7 @@ def _evp_cipher_encrypt(
445
419
backend .openssl_assert (res != 0 )
446
420
tag = backend ._ffi .buffer (tag_buf )[:]
447
421
448
- if isinstance (cipher , AESSIV ):
449
- # RFC 5297 defines the output as IV || C, where the tag we generate
450
- # is the "IV" and C is the ciphertext. This is the opposite of our
451
- # other AEADs, which are Ciphertext || Tag
452
- backend .openssl_assert (len (tag ) == 16 )
453
- return tag + processed_data
454
- else :
455
- return processed_data + tag
422
+ return processed_data + tag
456
423
457
424
458
425
def _evp_cipher_decrypt (
@@ -464,20 +431,13 @@ def _evp_cipher_decrypt(
464
431
tag_length : int ,
465
432
ctx : typing .Any = None ,
466
433
) -> bytes :
467
- from cryptography .hazmat .primitives .ciphers .aead import AESCCM , AESSIV
434
+ from cryptography .hazmat .primitives .ciphers .aead import AESCCM
468
435
469
436
if len (data ) < tag_length :
470
437
raise InvalidTag
471
438
472
- if isinstance (cipher , AESSIV ):
473
- # RFC 5297 defines the output as IV || C, where the tag we generate
474
- # is the "IV" and C is the ciphertext. This is the opposite of our
475
- # other AEADs, which are Ciphertext || Tag
476
- tag = data [:tag_length ]
477
- data = data [tag_length :]
478
- else :
479
- tag = data [- tag_length :]
480
- data = data [:- tag_length ]
439
+ tag = data [- tag_length :]
440
+ data = data [:- tag_length ]
481
441
if ctx is None :
482
442
cipher_name = _evp_cipher_cipher_name (cipher )
483
443
ctx = _evp_cipher_aead_setup (
0 commit comments