assert pt == TEST_PLAINTEXT
+ def test_crypto_aes_gcm_dec_missing_tag (self):
+ NaCl = os.urandom (CRYPTO_NACL_SIZE)
+ key = os.urandom (CRYPTO_KEY_SIZE)
+ enc = crypto.AES_GCM_context (crypto.ENCRYPT, key, TEST_AES_GCM_AAD)
+ iv = enc.iv
+ dec = crypto.AES_GCM_context (crypto.DECRYPT, key, TEST_AES_GCM_AAD, iv = iv)
+ ok, ct = enc.process_chunk (TEST_PLAINTEXT)
+ ok, _, tag = enc.done ()
+ ok, pt = dec.process_chunk (ct)
+ with pytest.raises (ValueError):
+ ok, _, _ = dec.done ()
+
+
def test_crypto_aes_gcm_dec_bad_tag (self):
NaCl = os.urandom (CRYPTO_NACL_SIZE)
key = os.urandom (CRYPTO_KEY_SIZE)
assert pt == orig_pt
+ def test_crypto_aes_gcm_dec_multicnk_bad_tag (self):
+ cnksiz = 1 << 10
+ orig_pt = fill_mod (1 << 14)
+ NaCl = os.urandom (CRYPTO_NACL_SIZE)
+ key = os.urandom (CRYPTO_KEY_SIZE)
+ enc = crypto.AES_GCM_context (crypto.ENCRYPT, key, TEST_AES_GCM_AAD)
+ iv = enc.iv
+ dec = crypto.AES_GCM_context (crypto.DECRYPT, key, TEST_AES_GCM_AAD, iv = iv)
+
+ off = 0
+ ct = b""
+ while off < len (orig_pt):
+ upto = min (off + cnksiz, len (orig_pt))
+ ok, cnk = enc.process_chunk (orig_pt [off:upto])
+ ct += cnk
+ off += cnksiz
+ ok, _, tag = enc.done ()
+
+ off = 0
+ pt = b""
+ while off < len (orig_pt):
+ upto = min (off + cnksiz, len (orig_pt))
+ ok, cnk = dec.process_chunk (ct [off:upto])
+ pt += cnk
+ off += cnksiz
+
+ with pytest.raises (cryptography.exceptions.InvalidTag):
+ tag = b"Y" + tag[:-1]
+ ok, _, _ = dec.done (tag)
+
+
+ def test_crypto_aes_gcm_dec_multicnk_missing_tag (self):
+ cnksiz = 1 << 10
+ orig_pt = fill_mod (1 << 14)
+ NaCl = os.urandom (CRYPTO_NACL_SIZE)
+ key = os.urandom (CRYPTO_KEY_SIZE)
+ enc = crypto.AES_GCM_context (crypto.ENCRYPT, key, TEST_AES_GCM_AAD)
+ iv = enc.iv
+ dec = crypto.AES_GCM_context (crypto.DECRYPT, key, TEST_AES_GCM_AAD, iv = iv)
+
+ off = 0
+ ct = b""
+ while off < len (orig_pt):
+ upto = min (off + cnksiz, len (orig_pt))
+ ok, cnk = enc.process_chunk (orig_pt [off:upto])
+ ct += cnk
+ off += cnksiz
+ ok, _, tag = enc.done ()
+
+ off = 0
+ pt = b""
+ while off < len (orig_pt):
+ upto = min (off + cnksiz, len (orig_pt))
+ ok, cnk = dec.process_chunk (ct [off:upto])
+ pt += cnk
+ off += cnksiz
+
+ with pytest.raises (ValueError):
+ ok, _, _ = dec.done ()
+
+
def test_crypto_fmt_hdr_make (self):
meta = faux_hdr()
ok, hdr = crypto.hdr_make (meta)