You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
associatedData - data that is not encrypted but included into MAC calculation.
plaintext - data to be encrypted.
Returns:
byte array with encrypted data
Implementation:
// Prepare or validate nonceif (nonce == null) {
// Create a new fresh nonce if no nonce provided.nonce = Generator.randomBytes(NONCE_LENGTH)
} elseif (nonce.length != NONCE_LENGTH) {
thrownewException();
}
// Derive encryption and authentication keybyte[] KEY_ENC = KDF.derive(key, 20_001, keyContext);
byte[] KEY_MAC = KDF.derive(key, 20_002, keyContext);
// Prepare IV. Append 4 zero bytes to make IV 16 bytes long. So, the counter in CTR mode always starts at 0.// We expect that only 32 least significant bits in nonce is used as a counter, so the maximum length of plaintext is 2^32.byte[] IV = ByteUtils.concat(nonce, ByteUtils.zeroBytes(4));
// Encryptbyte[] ENCRYPTED = AES.encrypt(plaintext, IV, KEY_ENC, "AES/CTR/NoPadding");
// Calculate MACbyte[] MAC = Mac.kmac256(KEY_MAC, ByteUtils.concat(nonce, associatedData, ENCRYPTED), LABEL);
// Prepare final ciphertextreturnByteUtils.concat(nonce, MAC, ENCRYPTED);
Description
Add new encryption algorithms for crypto4:
Cover the new encryption algorithms by tests.
Acceptance criteria
AEAD implemented as specified and covered by unit tests.
Technical specification
Let's define a new primitive that provides authenticated encryption with associated data:
Common constants:
NONCE_LENGTH = 12
- The purpose of nonce is to provide initial IV value to AES/CTR.TAG_LENGTH = 32
- The tag length specifies howLABEL
- The kmac256 label:String LABEL = "PA4MAC-AEAD"
byte[] AEAD.seal(SecretKey key, byte[] keyContext, byte[] nonce, byte[] associatedData, byte[] plaintext)
key
- secret symmetric key.keyContext
- a context related to the secret key.nonce
- nonce a part of IV for underlying cipher.associatedData
- data that is not encrypted but included into MAC calculation.plaintext
- data to be encrypted.byte[] AEAD.open(SecretKey key, byte[] keyContext, byte[] associatedData, byte[] ciphertext)
key
- secret symmetric key.keyContext
- a context related to the secret key.associatedData
- data that is included into MAC calculation.ciphertext
- data to be decrypted.byte[] AEAD.extractNonce(byte[] ciphertext)
QA specification
Functionality is covered by unit tests.
The text was updated successfully, but these errors were encountered: