Skip to content

Commit

Permalink
Rename hpke method names
Browse files Browse the repository at this point in the history
  • Loading branch information
hwupathum committed Mar 22, 2024
1 parent bb6d435 commit 84e8a9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
20 changes: 10 additions & 10 deletions ballerina/hpke.bal
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ public isolated function encryptMlKem768Hpke(byte[] input, PublicKey publicKey,
# + input - The content to be decrypted
# + encapsulatedKey - The encapsulated secret
# + privateKey - The MlKem private key used for decryption
# + length - The length of the output (in bytes)
# + symmetricKeySize - The length of the symmetric key (in bytes)
# + return - Decrypted data or else a `crypto:Error` if error occurs
public isolated function decryptMlKem768Hpke(byte[] input, byte[] encapsulatedKey, PrivateKey privateKey, int length = 32) returns byte[]|Error {
public isolated function decryptMlKem768Hpke(byte[] input, byte[] encapsulatedKey, PrivateKey privateKey, AesKeySize symmetricKeySize = 32) returns byte[]|Error {

Check warning on line 75 in ballerina/hpke.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/hpke.bal#L75

Added line #L75 was not covered by tests
byte[] key = check decapsulateMlKem768(encapsulatedKey, privateKey);
key = check hkdfSha256(key, length);
key = check hkdfSha256(key, symmetricKeySize);
return check decryptAesEcb(input, key);
}

Check warning on line 79 in ballerina/hpke.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/hpke.bal#L79

Added line #L79 was not covered by tests

Expand All @@ -92,14 +92,14 @@ public isolated function decryptMlKem768Hpke(byte[] input, byte[] encapsulatedKe
# };
# crypto:PublicKey mlkemPublicKey = check crypto:decodeMlKem768PublicKeyFromTrustStore(mlkemKeyStore, "keyAlias");
# crypto:PublicKey rsaPublicKey = check crypto:decodeRsaPublicKeyFromTrustStore(rsaKeyStore, "keyAlias");
# crypto:HybridEncryptionResult encryptionResult = crypto:encryptRsaMlKem768Hpke(data, rsaPublicKey, mlkemPublicKey);
# crypto:HybridEncryptionResult encryptionResult = crypto:encryptRsaKemMlKem768Hpke(data, rsaPublicKey, mlkemPublicKey);
# ```
# + input - The content to be encrypted
# + rsaPublicKey - The RSA public key used for encryption
# + mlkemPublicKey - The MlKem public key used for encryption
# + symmetricKeySize - The length of the symmetric key (in bytes)
# + return - Encrypted data or else a `crypto:Error` if an error occurs
public isolated function encryptRsaMlKem768Hpke(byte[] input, PublicKey rsaPublicKey, PublicKey mlkemPublicKey, AesKeySize symmetricKeySize = 32) returns HybridEncryptionResult|Error {
public isolated function encryptRsaKemMlKem768Hpke(byte[] input, PublicKey rsaPublicKey, PublicKey mlkemPublicKey, AesKeySize symmetricKeySize = 32) returns HybridEncryptionResult|Error {

Check warning on line 102 in ballerina/hpke.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/hpke.bal#L102

Added line #L102 was not covered by tests
EncapsulationResult hybridEncapsulationResult = check encapsulateRsaKemMlKem768(rsaPublicKey, mlkemPublicKey);
byte[] sharedSecret = check hkdfSha256(hybridEncapsulationResult.sharedSecret, symmetricKeySize);
byte[] ciphertext = check encryptAesEcb(input, sharedSecret);
Expand All @@ -123,21 +123,21 @@ public isolated function encryptRsaMlKem768Hpke(byte[] input, PublicKey rsaPubli
# };
# crypto:PublicKey mlkemPublicKey = check crypto:decodeMlKem768PublicKeyFromTrustStore(mlkemKeyStore, "keyAlias");
# crypto:PublicKey rsaPublicKey = check crypto:decodeRsaPublicKeyFromTrustStore(rsaKeyStore, "keyAlias");
# crypto:HybridEncryptionResult encryptionResult = crypto:encryptRsaMlKem768Hpke(data, rsaPublicKey, mlkemPublicKey);
# crypto:HybridEncryptionResult encryptionResult = crypto:encryptRsaKemMlKem768Hpke(data, rsaPublicKey, mlkemPublicKey);
# byte[] cipherText = encryptionResult.cipherText;
# byte[] encapsulatedKey = encryptionResult.encapsulatedSecret;
# crypto:PrivateKey mlkemPrivateKey = check crypto:decodeMlKem768PrivateKeyFromKeyStore(mlkemKeyStore, "keyAlias");
# crypto:PrivateKey rsaPrivateKey = check crypto:decodeRsaPrivateKeyFromKeyStore(rsaKeyStore, "keyAlias");
# byte[] decryptedData = check crypto:decryptRsaMlKem768Hpke(cipherText, encapsulatedKey, rsaPrivateKey, mlkemPrivateKey);
# byte[] decryptedData = check crypto:decryptRsaKemMlKem768Hpke(cipherText, encapsulatedKey, rsaPrivateKey, mlkemPrivateKey);
# ```
# + input - The content to be decrypted
# + encapsulatedKey - The encapsulated secret
# + rsaPrivateKey - The RSA private key used for decryption
# + mlkemPrivateKey - The MlKem private key used for decryption
# + length - The length of the output (in bytes)
# + symmetricKeySize - The length of the symmetric key (in bytes)
# + return - Decrypted data or else a `crypto:Error` if error occurs
public isolated function decryptRsaMlKem768Hpke(byte[] input, byte[] encapsulatedKey, PrivateKey rsaPrivateKey, PrivateKey mlkemPrivateKey, int length = 32) returns byte[]|Error {
public isolated function decryptRsaKemMlKem768Hpke(byte[] input, byte[] encapsulatedKey, PrivateKey rsaPrivateKey, PrivateKey mlkemPrivateKey, AesKeySize symmetricKeySize = 32) returns byte[]|Error {

Check warning on line 139 in ballerina/hpke.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/hpke.bal#L139

Added line #L139 was not covered by tests
byte[] key = check decapsulateRsaKemMlKem768(encapsulatedKey, rsaPrivateKey, mlkemPrivateKey);
key = check hkdfSha256(key, length);
key = check hkdfSha256(key, symmetricKeySize);
return check decryptAesEcb(input, key);
}

Check warning on line 143 in ballerina/hpke.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/hpke.bal#L143

Added line #L143 was not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ private Constants() {}
public static final String CERTIFICATE_RECORD_SIGNATURE_ALG_FIELD = "signingAlgorithm";

// Fields of `EncapsulationResult` record.
public static final String ENCAPSULATED_RESULT_RECORD_ALGORITHM_FIELD = "algorithm";
public static final String ENCAPSULATED_RESULT_RECORD_ENCAPSULATED_FIELD = "encapsulatedSecret";
public static final String ENCAPSULATED_RESULT_RECORD_SECRET_FIELD = "sharedSecret";

Expand Down

0 comments on commit 84e8a9f

Please sign in to comment.