-
Notifications
You must be signed in to change notification settings - Fork 96
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
CRYPTO-60: opensslCipher support GCM mode #70
Conversation
this.padding = padding; | ||
|
||
// context should be initialized | ||
if (context != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According the previous code, if context is zero, we still pass it to OpenSslCommonMode? Is the behavior changed now?
// context should be initialized | ||
if (context != 0) { | ||
if (algorithm == AlgorithmMode.AES_GCM.ordinal()) { | ||
opensslBlockCipher = new OpenSslGaloisCounterMode(context, algorithm, padding); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: OpenSslGaloisCounterMode: Is OpenSslGaloisCounterCipher better?
if (algorithm == AlgorithmMode.AES_GCM.ordinal()) { | ||
opensslBlockCipher = new OpenSslGaloisCounterMode(context, algorithm, padding); | ||
} else { | ||
opensslBlockCipher = new OpenSslCommonMode(context, algorithm, padding); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: OpenSslCommonMode: is OpenSslCommonCipher better?
} | ||
} | ||
|
||
/** Checks whether context is initialized. */ | ||
private void checkState() { | ||
Utils.checkState(context != 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question, why not use context for checking State? Is the behavior changed now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
behavior is not changed. The context was moved to to the Cipher(OpenSslFeedbackCipher).
The cipher will check its own state. -
Well, I am considering to remove OpenSsl.java. From my point of view, now this layer(OpenSsl.java) seems redundant , we can move the logic(paramenters check) in OpenSsl.java to OpenSslCipher.
Then, the codebase will be clear:
- OpenSslCipher which implements the CryptoCipher interface which is exposed to the users.
- OpenSslFeedbackCipher and its sub classes (OpenSslGaloisCounterMode,OpenSslCommonMode) are private classes. they do the real work(encription/decription) for different modes.
- OpenSslNative: JNI class
Maybe we can do this later.
inputLen, output, outputOffset, output.length - outputOffset); | ||
|
||
len += OpenSslNative.doFinalByteArray(context, output, outputOffset + len, | ||
output.length - outputOffset); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should output.length - outputOffset
be output.length - outputOffset - len
?
@@ -216,12 +216,15 @@ static FARPROC WINAPI do_dlsym(JNIEnv *env, HMODULE handle, LPCSTR symbol) { | |||
#define ENCRYPT_MODE 1 | |||
#define DECRYPT_MODE 0 | |||
|
|||
/** Currently only support AES/CTR/NoPadding. */ | |||
/** Currently only support AES/CTR/NoPadding, AES/CBC/NoPadding. AES/GCM/NoPadding */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AES/CTR/NoPadding, AES/CBC/NoPadding, AES/CBC/PKCS5Padding, AES/GCM/NoPadding
} | ||
|
||
len += OpenSslNative.doFinalByteArray(context, output, outputOffset + len, | ||
output.length - outputOffset); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should output.length - outputOffset
be output.length - outputOffset - len
Hi, I am very interested in this PR - any reason why it was not merged? |
@yaronlev171, This PR implements GCM only in Cipher level. it needs to be tested more, but I was busy on other stuffs. I will be back on this PR soon, i will refine the code and do more testing. now, Stream level api does not support GCM. We need to do more work on stream API. |
@kexianda thanks for the reply. |
class OpenSslGaloisCounterMode extends OpenSslFeedbackCipher { | ||
|
||
// buffer for AAD data; if consumed, set as null | ||
private ByteArrayOutputStream aadBuffer = new ByteArrayOutputStream(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be set inside init() so the cipher with aad is reusable after clean(). [tested]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for this comment. I'll update the patch.
+1, thank @kexianda for the contribution! |
Thank @sundapeng. I will update the testcases with samples for GCM/GMAC soon. |
support AES-GCM cipher, also we has GMAC. code refactor.
BUILD SUCCESS on my local dev enviroment. but failed on travis-ci. |
Thank @kexianda, I will fix it. |
Is there a timeline for the release of this feature. The version is 3 years old. |
CRYPTO-60
support GCM mode