Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate AesSiv parameters in AesSivKeyManager the same way the AesSivParameters #34

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/main/java/com/google/crypto/tink/daead/AesSivKeyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static DeterministicAead createDeterministicAead(AesSivKey key)
PrimitiveConstructor.create(
AesSivKeyManager::createDeterministicAead, AesSivKey.class, DeterministicAead.class);

private static final int KEY_SIZE_IN_BYTES = 64;
private static final int AES256_KEY_SIZE_IN_BYTES = 64;

static String getKeyType() {
return "type.googleapis.com/google.crypto.tink.AesSivKey";
Expand All @@ -76,13 +76,12 @@ static String getKeyType() {

private static void validateParameters(AesSivParameters parameters)
throws GeneralSecurityException {
if (parameters.getKeySizeBytes() != KEY_SIZE_IN_BYTES) {
int keySizeBytes = parameters.getKeySizeBytes();
if (keySizeBytes != 32 && keySizeBytes != 48 && keySizeBytes != 64) {
throw new InvalidAlgorithmParameterException(
"invalid key size: "
+ parameters.getKeySizeBytes()
+ ". Valid keys must have "
+ KEY_SIZE_IN_BYTES
+ " bytes.");
String.format(
"Invalid key size %d; only 32-byte, 48-byte and 64-byte AES-SIV keys are supported",
keySizeBytes));
}
}

Expand Down Expand Up @@ -153,7 +152,7 @@ public static final KeyTemplate aes256SivTemplate() {
() ->
KeyTemplate.createFrom(
AesSivParameters.builder()
.setKeySizeBytes(KEY_SIZE_IN_BYTES)
.setKeySizeBytes(AES256_KEY_SIZE_IN_BYTES)
.setVariant(AesSivParameters.Variant.TINK)
.build()));
}
Expand All @@ -167,7 +166,7 @@ public static final KeyTemplate rawAes256SivTemplate() {
() ->
KeyTemplate.createFrom(
AesSivParameters.builder()
.setKeySizeBytes(KEY_SIZE_IN_BYTES)
.setKeySizeBytes(AES256_KEY_SIZE_IN_BYTES)
.setVariant(AesSivParameters.Variant.NO_PREFIX)
.build()));
}
Expand Down