@@ -43,19 +43,20 @@ uint8_t encrypted[114] =
43
43
int main ()
44
44
{
45
45
uint8_t buf[114 +16 ];
46
+ i2p::crypto::AEADChaCha20Poly1305Encryptor encryptor;
46
47
// test encryption
47
- i2p::crypto::AEADChaCha20Poly1305 ((uint8_t *)text, 114 , ad, 12 , key, nonce, buf, 114 + 16 , true );
48
+ encryptor. Encrypt ((uint8_t *)text, 114 , ad, 12 , key, nonce, buf, 114 + 16 );
48
49
assert (memcmp (buf, encrypted, 114 ) == 0 );
49
50
assert (memcmp (buf + 114 , tag, 16 ) == 0 );
50
51
// test decryption
51
52
uint8_t buf1[114 ];
52
- assert (i2p::crypto::AEADChaCha20Poly1305 (buf, 114 , ad, 12 , key, nonce, buf1, 114 , false ));
53
+ i2p::crypto::AEADChaCha20Poly1305Decryptor decryptor;
54
+ assert (decryptor.Decrypt (buf, 114 , ad, 12 , key, nonce, buf1, 114 ));
53
55
assert (memcmp (buf1, text, 114 ) == 0 );
54
56
// test encryption of multiple buffers
55
57
memcpy (buf, text, 114 );
56
58
std::vector<std::pair<uint8_t *, std::size_t > > bufs{ std::make_pair (buf, 20 ), std::make_pair (buf + 20 , 10 ), std::make_pair (buf + 30 , 70 ), std::make_pair (buf + 100 , 14 ) };
57
- i2p::crypto::AEADChaCha20Poly1305Encryptor encryptor;
58
59
encryptor.Encrypt (bufs, key, nonce, buf + 114 );
59
- i2p::crypto::AEADChaCha20Poly1305 (buf, 114 , nullptr , 0 , key, nonce, buf1, 114 , false );
60
+ decryptor. Decrypt (buf, 114 , nullptr , 0 , key, nonce, buf1, 114 );
60
61
assert (memcmp (buf1, text, 114 ) == 0 );
61
62
}
0 commit comments