6227536: KeyGenerator.init() methods do not throw IllegalArgumentException for keysize == 0

Reviewed-by: wetmore
This commit is contained in:
Kevin Driver 2022-07-29 20:30:28 +00:00 committed by Bradford Wetmore
parent cc2861a993
commit 0bcf17674e
3 changed files with 76 additions and 2 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -88,6 +88,11 @@ public final class HmacMD5KeyGenerator extends KeyGeneratorSpi {
* @param random the source of randomness for this key generator
*/
protected void engineInit(int keysize, SecureRandom random) {
if (keysize <= 0) {
throw new IllegalArgumentException("keysize must not be <= 0");
}
this.keysize = (keysize+7) / 8;
this.engineInit(random);
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -88,6 +88,11 @@ public final class HmacSHA1KeyGenerator extends KeyGeneratorSpi {
* @param random the source of randomness for this key generator
*/
protected void engineInit(int keysize, SecureRandom random) {
if (keysize <= 0) {
throw new IllegalArgumentException("keysize must not be <= 0");
}
this.keysize = (keysize+7) / 8;
this.engineInit(random);
}