@@ -36,6 +36,7 @@ static int (*dlsym_EVP_CipherUpdate)(EVP_CIPHER_CTX *, unsigned char *, \
36
36
int * , const unsigned char * , int );
37
37
static int (* dlsym_EVP_CipherFinal_ex )(EVP_CIPHER_CTX * , unsigned char * , int * );
38
38
static EVP_CIPHER * (* dlsym_EVP_aes_256_ctr )(void );
39
+ static EVP_CIPHER * (* dlsym_EVP_aes_192_ctr )(void );
39
40
static EVP_CIPHER * (* dlsym_EVP_aes_128_ctr )(void );
40
41
static void * openssl ;
41
42
#endif
@@ -54,6 +55,7 @@ typedef int (__cdecl *__dlsym_EVP_CipherUpdate)(EVP_CIPHER_CTX *, \
54
55
typedef int (__cdecl * __dlsym_EVP_CipherFinal_ex )(EVP_CIPHER_CTX * , \
55
56
unsigned char * , int * );
56
57
typedef EVP_CIPHER * (__cdecl * __dlsym_EVP_aes_256_ctr )(void );
58
+ typedef EVP_CIPHER * (__cdecl * __dlsym_EVP_aes_192_ctr )(void );
57
59
typedef EVP_CIPHER * (__cdecl * __dlsym_EVP_aes_128_ctr )(void );
58
60
static __dlsym_EVP_CIPHER_CTX_new dlsym_EVP_CIPHER_CTX_new ;
59
61
static __dlsym_EVP_CIPHER_CTX_free dlsym_EVP_CIPHER_CTX_free ;
@@ -64,6 +66,7 @@ static __dlsym_EVP_CipherInit_ex dlsym_EVP_CipherInit_ex;
64
66
static __dlsym_EVP_CipherUpdate dlsym_EVP_CipherUpdate ;
65
67
static __dlsym_EVP_CipherFinal_ex dlsym_EVP_CipherFinal_ex ;
66
68
static __dlsym_EVP_aes_256_ctr dlsym_EVP_aes_256_ctr ;
69
+ static __dlsym_EVP_aes_192_ctr dlsym_EVP_aes_192_ctr ;
67
70
static __dlsym_EVP_aes_128_ctr dlsym_EVP_aes_128_ctr ;
68
71
static HMODULE openssl ;
69
72
#endif
@@ -72,12 +75,15 @@ static void loadAesCtr(JNIEnv *env)
72
75
{
73
76
#ifdef UNIX
74
77
LOAD_DYNAMIC_SYMBOL (dlsym_EVP_aes_256_ctr , env , openssl , "EVP_aes_256_ctr" );
78
+ LOAD_DYNAMIC_SYMBOL (dlsym_EVP_aes_192_ctr , env , openssl , "EVP_aes_192_ctr" );
75
79
LOAD_DYNAMIC_SYMBOL (dlsym_EVP_aes_128_ctr , env , openssl , "EVP_aes_128_ctr" );
76
80
#endif
77
81
78
82
#ifdef WINDOWS
79
83
LOAD_DYNAMIC_SYMBOL (__dlsym_EVP_aes_256_ctr , dlsym_EVP_aes_256_ctr , \
80
84
env , openssl , "EVP_aes_256_ctr" );
85
+ LOAD_DYNAMIC_SYMBOL (__dlsym_EVP_aes_192_ctr , dlsym_EVP_aes_192_ctr , \
86
+ env , openssl , "EVP_aes_192_ctr" );
81
87
LOAD_DYNAMIC_SYMBOL (__dlsym_EVP_aes_128_ctr , dlsym_EVP_aes_128_ctr , \
82
88
env , openssl , "EVP_aes_128_ctr" );
83
89
#endif
@@ -165,7 +171,7 @@ JNIEXPORT jlong JNICALL Java_org_apache_hadoop_crypto_OpensslCipher_initContext
165
171
return (jlong )0 ;
166
172
}
167
173
168
- if (dlsym_EVP_aes_256_ctr == NULL || dlsym_EVP_aes_128_ctr == NULL ) {
174
+ if (dlsym_EVP_aes_256_ctr == NULL || dlsym_EVP_aes_192_ctr == NULL || dlsym_EVP_aes_128_ctr == NULL ) {
169
175
THROW (env , "java/security/NoSuchAlgorithmException" , \
170
176
"Doesn't support AES CTR." );
171
177
return (jlong )0 ;
@@ -188,6 +194,8 @@ static EVP_CIPHER * getEvpCipher(int alg, int keyLen)
188
194
if (alg == AES_CTR ) {
189
195
if (keyLen == KEY_LENGTH_256 ) {
190
196
cipher = dlsym_EVP_aes_256_ctr ();
197
+ } else if (keyLen == KEY_LENGTH_192 ) {
198
+ cipher = dlsym_EVP_aes_192_ctr ();
191
199
} else if (keyLen == KEY_LENGTH_128 ) {
192
200
cipher = dlsym_EVP_aes_128_ctr ();
193
201
}
@@ -201,12 +209,22 @@ JNIEXPORT jlong JNICALL Java_org_apache_hadoop_crypto_OpensslCipher_init
201
209
{
202
210
int jKeyLen = (* env )-> GetArrayLength (env , key );
203
211
int jIvLen = (* env )-> GetArrayLength (env , iv );
204
- if (jKeyLen != KEY_LENGTH_128 && jKeyLen != KEY_LENGTH_256 ) {
205
- THROW (env , "java/lang/IllegalArgumentException" , "Invalid key length." );
212
+ if (jKeyLen != KEY_LENGTH_128 && jKeyLen != KEY_LENGTH_192 && jKeyLen != KEY_LENGTH_256 ) {
213
+ char * keyLenErrMsg ;
214
+ if (asprintf (& keyLenErrMsg , "Invalid key length: %d bytes" , jKeyLen ) < 0 ) {
215
+ THROW (env , "java/lang/IllegalArgumentException" , "Invalid key length" );
216
+ } else {
217
+ THROW (env , "java/lang/IllegalArgumentException" , keyLenErrMsg );
218
+ }
206
219
return (jlong )0 ;
207
220
}
208
221
if (jIvLen != IV_LENGTH ) {
209
- THROW (env , "java/lang/IllegalArgumentException" , "Invalid iv length." );
222
+ char * ivLenErrMsg ;
223
+ if (asprintf (& ivLenErrMsg , "Invalid iv length: %d bytes" , jIvLen ) < 0 ) {
224
+ THROW (env , "java/lang/IllegalArgumentException" , "Invalid iv length." );
225
+ } else {
226
+ THROW (env , "java/lang/IllegalArgumentException" , ivLenErrMsg );
227
+ }
210
228
return (jlong )0 ;
211
229
}
212
230
0 commit comments