Skip to content

Commit

Permalink
Removed isEncrypt boolean variable
Browse files Browse the repository at this point in the history
  • Loading branch information
U-AMR\skamath4 authored and smita-kamath committed Sep 28, 2023
1 parent 775a2ce commit 8292699
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 43 deletions.
6 changes: 3 additions & 3 deletions src/hotspot/cpu/x86/stubGenerator_x86_64.hpp
Expand Up @@ -330,7 +330,7 @@ class StubGenerator: public StubCodeGenerator {
// AVX2 AES Galois Counter Mode implementation
address generate_avx2_galoisCounterMode_AESCrypt();
void aesgcm_avx2(Register in, Register len, Register ct, Register out, Register key,
Register state, Register subkeyHtbl, Register counter, Register enc_dec);
Register state, Register subkeyHtbl, Register counter);

// Vector AES Counter implementation
address generate_counterMode_VectorAESCrypt();
Expand Down Expand Up @@ -359,11 +359,11 @@ class StubGenerator: public StubCodeGenerator {
bool final_reduction, int index, XMMRegister counter_inc_mask);
// AVX2 AES-GCM related functions
void initial_blocks(XMMRegister ctr, Register rounds, Register key, Register len,
Register in, Register out, Register subkeyHtbl, Register isEncrypt, Register pos);
Register in, Register out, Register ct, Register subkeyHtbl, Register pos);
void gfmul_avx2(XMMRegister GH, XMMRegister HK);
void generateHtbl_8_block_avx2(Register htbl, Register rscratch);
void ghash8_encrypt8_parallel(Register key, Register subkeyHtbl, XMMRegister ctr_blockx, XMMRegister aad_hashx,
Register in, Register out, Register pos, bool out_order, Register isEncrypt, Register rounds);
Register in, Register out, Register ct, Register pos, bool out_order, Register rounds);
void ghash_last_8(Register subkeyHtbl);

// Load key and shuffle operation
Expand Down
25 changes: 10 additions & 15 deletions src/hotspot/cpu/x86/stubGenerator_x86_64_aes.cpp
Expand Up @@ -302,7 +302,6 @@ address StubGenerator::generate_galoisCounterMode_AESCrypt() {
// state = r13 | r9 (c_rarg5)
// subkeyHtbl = r11 | r11
// counter = rsi | r12
// isEncrypt = r12 | r13
//
// Output:
// rax - number of processed bytes
Expand All @@ -323,8 +322,6 @@ address StubGenerator::generate_avx2_galoisCounterMode_AESCrypt() {
const Register subkeyHtbl = r11;
const Address counter_mem(rbp, 3 * wordSize);
const Register counter = r12;
const Address isEncrypt_mem(rbp, 4 * wordSize);
const Register isEncrypt = r13;
#else
const Address key_mem(rbp, 6 * wordSize);
const Register key = rdi;
Expand All @@ -334,8 +331,6 @@ address StubGenerator::generate_avx2_galoisCounterMode_AESCrypt() {
const Register subkeyHtbl = r11;
const Address counter_mem(rbp, 9 * wordSize);
const Register counter = rsi;
const Address isEncrypt_mem(rbp, 10 * wordSize);
const Register isEncrypt = r12;
#endif
__ enter();
// Save state before entering routine
Expand All @@ -353,15 +348,15 @@ address StubGenerator::generate_avx2_galoisCounterMode_AESCrypt() {
#endif
__ movptr(subkeyHtbl, subkeyH_mem);
__ movptr(counter, counter_mem);
__ movptr(isEncrypt, isEncrypt_mem);

// Save rbp and rsp
__ push(rbp);
__ movq(rbp, rsp);
// Align stack
__ andq(rsp, -64);
__ subptr(rsp, 16 * longSize); // Create space on the stack for saving AES entries

aesgcm_avx2(in, len, ct, out, key, state, subkeyHtbl, counter, isEncrypt);
aesgcm_avx2(in, len, ct, out, key, state, subkeyHtbl, counter);
__ vzeroupper();
__ movq(rsp, rbp);
__ pop(rbp);
Expand Down Expand Up @@ -3365,7 +3360,7 @@ void StubGenerator::generateHtbl_8_block_avx2(Register htbl, Register rscratch)
}

void StubGenerator::ghash8_encrypt8_parallel(Register key, Register subkeyHtbl, XMMRegister ctr_blockx, XMMRegister aad_hashx,
Register in, Register out, Register pos, bool in_order, Register isEncrypt, Register rounds) {
Register in, Register out, Register ct, Register pos, bool in_order, Register rounds) {

const XMMRegister t1 = xmm0;
const XMMRegister t2 = xmm10;
Expand Down Expand Up @@ -3721,7 +3716,7 @@ void StubGenerator::ghash8_encrypt8_parallel(Register key, Register subkeyHtbl,
__ movdqu(Address(out, pos, Address::times_1, 16 * 6), xmm7);
__ movdqu(Address(out, pos, Address::times_1, 16 * 7), xmm8);

__ cmpl(isEncrypt, 1);
__ cmpptr(ct, out);
__ jcc(Assembler::equal, skip_reload);
__ movdqu(xmm1, Address(in, pos, Address::times_1, 16 * 0));
__ movdqu(xmm2, Address(in, pos, Address::times_1, 16 * 1));
Expand Down Expand Up @@ -3913,7 +3908,7 @@ void StubGenerator::ghash_last_8(Register subkeyHtbl) {
}

void StubGenerator::initial_blocks(XMMRegister ctr, Register rounds, Register key,
Register len, Register in, Register out, Register subkeyHtbl, Register isEncrypt, Register pos) {
Register len, Register in, Register out, Register ct, Register subkeyHtbl, Register pos) {
const XMMRegister t1 = xmm12;
const XMMRegister t2 = xmm13;
const XMMRegister t3 = xmm14;
Expand Down Expand Up @@ -4141,7 +4136,7 @@ void StubGenerator::initial_blocks(XMMRegister ctr, Register rounds, Register ke
__ vpxor(xmm8, xmm8, t1, Assembler::AVX_128bit);
__ movdqu(Address(out, pos, Address::times_1, 16 * 7), xmm8);

__ cmpl(isEncrypt, 1);
__ cmpptr(ct, out);
__ jcc(Assembler::equal, skip_reload);
__ movdqu(xmm1, Address(in, pos, Address::times_1, 16 * 0));
__ movdqu(xmm2, Address(in, pos, Address::times_1, 16 * 1));
Expand Down Expand Up @@ -4170,7 +4165,7 @@ void StubGenerator::initial_blocks(XMMRegister ctr, Register rounds, Register ke
}

void StubGenerator::aesgcm_avx2(Register in, Register len, Register ct, Register out, Register key,
Register state, Register subkeyHtbl, Register counter, Register isEncrypt) {
Register state, Register subkeyHtbl, Register counter) {
const Register pos = rax;
const Register rounds = r10;
const XMMRegister ctr_blockx = xmm9;
Expand Down Expand Up @@ -4201,7 +4196,7 @@ void StubGenerator::aesgcm_avx2(Register in, Register len, Register ct, Register
//Save the amount of data left to process in r14
__ mov(r14, len);

initial_blocks(xmm9, rounds, key, r14, in, out, subkeyHtbl, isEncrypt, pos);
initial_blocks(xmm9, rounds, key, r14, in, out, ct, subkeyHtbl, pos);

//The entire message was encrypted processed in initial and now need to be hashed
__ cmpl(len, 0);
Expand All @@ -4220,7 +4215,7 @@ void StubGenerator::aesgcm_avx2(Register in, Register len, Register ct, Register
__ jcc(Assembler::greater, encrypt_by_8);

__ addl(r15, 8);
ghash8_encrypt8_parallel(key, subkeyHtbl, ctr_blockx, aad_hashx, in, out, pos, false, isEncrypt, rounds);
ghash8_encrypt8_parallel(key, subkeyHtbl, ctr_blockx, aad_hashx, in, out, ct, pos, false, rounds);
__ addl(pos, 128);
__ subl(r14, 128);
__ cmpl(r14, 128);
Expand All @@ -4233,7 +4228,7 @@ void StubGenerator::aesgcm_avx2(Register in, Register len, Register ct, Register
__ vpshufb(xmm9, xmm9, ExternalAddress(counter_shuffle_mask_addr()), Assembler::AVX_128bit, rbx /*rscratch*/);

__ addl(r15, 8);
ghash8_encrypt8_parallel(key, subkeyHtbl, ctr_blockx, aad_hashx, in, out, pos, true, isEncrypt, rounds);
ghash8_encrypt8_parallel(key, subkeyHtbl, ctr_blockx, aad_hashx, in, out, ct, pos, true, rounds);

__ vpshufb(xmm9, xmm9, ExternalAddress(counter_shuffle_mask_addr()), Assembler::AVX_128bit, rbx /*rscratch*/);
__ addl(pos, 128);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/classfile/vmIntrinsics.hpp
Expand Up @@ -490,7 +490,7 @@ class methodHandle;
do_class(com_sun_crypto_provider_galoisCounterMode, "com/sun/crypto/provider/GaloisCounterMode") \
do_intrinsic(_galoisCounterMode_AESCrypt, com_sun_crypto_provider_galoisCounterMode, gcm_crypt_name, aes_gcm_signature, F_S) \
do_name(gcm_crypt_name, "implGCMCrypt0") \
do_signature(aes_gcm_signature, "([BII[BI[BILcom/sun/crypto/provider/GCTR;Lcom/sun/crypto/provider/GHASH;Z)I") \
do_signature(aes_gcm_signature, "([BII[BI[BILcom/sun/crypto/provider/GCTR;Lcom/sun/crypto/provider/GHASH;)I") \
\
/* support for sun.security.provider.MD5 */ \
do_class(sun_security_provider_md5, "sun/security/provider/MD5") \
Expand Down
6 changes: 2 additions & 4 deletions src/hotspot/share/opto/graphKit.cpp
Expand Up @@ -2492,8 +2492,7 @@ Node* GraphKit::make_runtime_call(int flags,
Node* parm0, Node* parm1,
Node* parm2, Node* parm3,
Node* parm4, Node* parm5,
Node* parm6, Node* parm7,
Node* parm8) {
Node* parm6, Node* parm7) {
assert(call_addr != nullptr, "must not call null targets");

// Slow-path call
Expand Down Expand Up @@ -2540,8 +2539,7 @@ Node* GraphKit::make_runtime_call(int flags,
if (parm5 != nullptr) { call->init_req(TypeFunc::Parms+5, parm5);
if (parm6 != nullptr) { call->init_req(TypeFunc::Parms+6, parm6);
if (parm7 != nullptr) { call->init_req(TypeFunc::Parms+7, parm7);
if (parm8 != nullptr) { call->init_req(TypeFunc::Parms+8, parm8);
/* close each nested if ===> */ } } } } } } } } }
/* close each nested if ===> */ } } } } } } } }
assert(call->in(call->req()-1) != nullptr, "must initialize all parms");

if (!is_leaf) {
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/share/opto/graphKit.hpp
Expand Up @@ -804,8 +804,7 @@ class GraphKit : public Phase {
Node* parm0 = nullptr, Node* parm1 = nullptr,
Node* parm2 = nullptr, Node* parm3 = nullptr,
Node* parm4 = nullptr, Node* parm5 = nullptr,
Node* parm6 = nullptr, Node* parm7 = nullptr,
Node* parm8 = nullptr);
Node* parm6 = nullptr, Node* parm7 = nullptr);

Node* sign_extend_byte(Node* in);
Node* sign_extend_short(Node* in);
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/share/opto/library_call.cpp
Expand Up @@ -7617,7 +7617,6 @@ bool LibraryCallKit::inline_galoisCounterMode_AESCrypt() {
Node* outOfs = argument(6);
Node* gctr_object = argument(7);
Node* ghash_object = argument(8);
Node* isEncrypt = argument(9);

// (1) in, ct and out are arrays.
const TypeAryPtr* in_type = in->Value(&_gvn)->isa_aryptr();
Expand Down Expand Up @@ -7674,7 +7673,7 @@ bool LibraryCallKit::inline_galoisCounterMode_AESCrypt() {
Node* gcmCrypt = make_runtime_call(RC_LEAF|RC_NO_FP,
OptoRuntime::galoisCounterMode_aescrypt_Type(),
stubAddr, stubName, TypePtr::BOTTOM,
in_start, len, ct_start, out_start, k_start, state_start, subkeyHtbl_start, cnt_start, isEncrypt);
in_start, len, ct_start, out_start, k_start, state_start, subkeyHtbl_start, cnt_start);

// return cipher length (int)
Node* retvalue = _gvn.transform(new ProjNode(gcmCrypt, TypeFunc::Parms));
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/share/opto/runtime.cpp
Expand Up @@ -1013,7 +1013,7 @@ const TypeFunc* OptoRuntime::counterMode_aescrypt_Type() {
//for counterMode calls of aescrypt encrypt/decrypt, four pointers and a length, returning int
const TypeFunc* OptoRuntime::galoisCounterMode_aescrypt_Type() {
// create input type (domain)
int num_args = 9;
int num_args = 8;
int argcnt = num_args;
const Type** fields = TypeTuple::fields(argcnt);
int argp = TypeFunc::Parms;
Expand All @@ -1025,7 +1025,6 @@ const TypeFunc* OptoRuntime::galoisCounterMode_aescrypt_Type() {
fields[argp++] = TypePtr::NOTNULL; // long[] state from GHASH obj
fields[argp++] = TypePtr::NOTNULL; // long[] subkeyHtbl from GHASH obj
fields[argp++] = TypePtr::NOTNULL; // byte[] counter from GCTR obj
fields[argp++] = TypeInt::BOOL; // bool encryption

assert(argp == TypeFunc::Parms + argcnt, "correct decoding");
const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + argcnt, fields);
Expand Down
Expand Up @@ -587,15 +587,15 @@ private static byte[] getJ0(byte[] iv, byte[] subkeyH, int blockSize) {
*/
private static int implGCMCrypt(byte[] in, int inOfs, int inLen, byte[] ct,
int ctOfs, byte[] out, int outOfs,
GCTR gctr, GHASH ghash, boolean encryption) {
GCTR gctr, GHASH ghash) {

int len = 0;
// Loop if input length is greater than the SPLIT_LEN
if (inLen > SPLIT_LEN && ct != null) {
int partlen;
while (inLen >= SPLIT_LEN) {
partlen = implGCMCrypt0(in, inOfs + len, SPLIT_LEN, ct,
ctOfs + len, out, outOfs + len, gctr, ghash, encryption);
ctOfs + len, out, outOfs + len, gctr, ghash);
len += partlen;
inLen -= partlen;
}
Expand All @@ -608,7 +608,7 @@ private static int implGCMCrypt(byte[] in, int inOfs, int inLen, byte[] ct,
len += gctr.update(in, inOfs + len, inLen, out, outOfs);
} else {
len += implGCMCrypt0(in, inOfs + len, inLen, ct,
ctOfs + len, out, outOfs + len, gctr, ghash, encryption);
ctOfs + len, out, outOfs + len, gctr, ghash);
}
}
return len;
Expand Down Expand Up @@ -642,7 +642,7 @@ private static int implGCMCrypt(byte[] in, int inOfs, int inLen, byte[] ct,
@IntrinsicCandidate
private static int implGCMCrypt0(byte[] in, int inOfs, int inLen,
byte[] ct, int ctOfs, byte[] out, int outOfs,
GCTR gctr, GHASH ghash, boolean isEncrypt) {
GCTR gctr, GHASH ghash) {

inLen -= (inLen % PARALLEL_LEN);

Expand Down Expand Up @@ -750,7 +750,7 @@ int getBufferedLength() {
* on 768 byte blocks and let the calling method operate on smaller
* sizes.
*/
int implGCMCrypt(ByteBuffer src, ByteBuffer dst, boolean encryption) {
int implGCMCrypt(ByteBuffer src, ByteBuffer dst) {
int srcLen = src.remaining() - (src.remaining() % PARALLEL_LEN);

if (srcLen < PARALLEL_LEN) {
Expand All @@ -766,7 +766,7 @@ int implGCMCrypt(ByteBuffer src, ByteBuffer dst, boolean encryption) {
inPlaceArray ? null : ct.array(),
ct.arrayOffset() + ct.position(),
dst.array(), dst.arrayOffset() + dst.position(),
gctr, ghash, encryption);
gctr, ghash);
src.position(src.position() + len);
dst.position(dst.position() + len);
return len;
Expand All @@ -780,7 +780,7 @@ int implGCMCrypt(ByteBuffer src, ByteBuffer dst, boolean encryption) {
do {
src.get(bin, 0, PARALLEL_LEN);
len -= GaloisCounterMode.implGCMCrypt(bin, 0, PARALLEL_LEN,
ct, 0, bout, 0, gctr, ghash, encryption);
ct, 0, bout, 0, gctr, ghash);
dst.put(bout, 0, PARALLEL_LEN);
} while (len >= PARALLEL_LEN);

Expand Down Expand Up @@ -889,7 +889,7 @@ int doLastBlock(GCMOperation op, ByteBuffer buffer, ByteBuffer src,
if (bLen > 0) {
// en/decrypt any PARALLEL_LEN sized data in the buffer
if (bLen >= PARALLEL_LEN) {
len = implGCMCrypt(buffer, dst, encryption);
len = implGCMCrypt(buffer, dst);
bLen -= len;
}

Expand Down Expand Up @@ -928,7 +928,7 @@ int doLastBlock(GCMOperation op, ByteBuffer buffer, ByteBuffer src,
// en/decrypt whatever remains in src.
// If src has been consumed, this will be a no-op
if (src.remaining() >= PARALLEL_LEN) {
len += implGCMCrypt(src, dst, encryption);
len += implGCMCrypt(src, dst);
}

return len + op.doFinal(src, dst);
Expand Down Expand Up @@ -1170,7 +1170,7 @@ public int doUpdate(byte[] in, int inOfs, int inLen, byte[] out,
// Encrypt the remaining blocks inside of 'in'
if (inLen >= PARALLEL_LEN) {
int r = GaloisCounterMode.implGCMCrypt(in, inOfs, inLen, out,
outOfs, out, outOfs, gctr, ghash, encryption);
outOfs, out, outOfs, gctr, ghash);
len += r;
inOfs += r;
inLen -= r;
Expand Down Expand Up @@ -1236,7 +1236,7 @@ public int doUpdate(ByteBuffer src, ByteBuffer dst)
int resultLen;
// encrypt any PARALLEL_LEN sized data in 'src'
if (srcLen >= PARALLEL_LEN) {
resultLen = implGCMCrypt(src, dst, encryption);
resultLen = implGCMCrypt(src, dst);
srcLen -= resultLen;
len += resultLen;
}
Expand Down Expand Up @@ -1688,7 +1688,7 @@ int decryptBlocks(GCMOperation op, byte[] in, int inOfs, int inLen,

if (bLen >= PARALLEL_LEN) {
len = GaloisCounterMode.implGCMCrypt(buffer, 0, bLen,
buffer, 0, out, outOfs, gctr, ghash, encryption);
buffer, 0, out, outOfs, gctr, ghash);
outOfs += len;
// Use len as it becomes the ibuffer offset, if
// needed, in the next op
Expand Down Expand Up @@ -1800,7 +1800,7 @@ public int doFinal(byte[] in, int inOfs, int inLen, byte[] out,

if (inLen >= PARALLEL_LEN) {
len = implGCMCrypt(in, inOfs, inLen, out, outOfs, out, outOfs,
gctr, ghash, true);
gctr, ghash);
inLen -= len;
outOfs += len;
}
Expand Down Expand Up @@ -1862,7 +1862,7 @@ public int doFinal(byte[] in, int inOfs, int inLen, byte[] out,
// 'in' and 'out' are the same. All other in-place situations
// have been resolved by overlapDetection()
len += implGCMCrypt(in, inOfs, inLen, (in == out ? null : in),
inOfs, out, outOfs, gctr, ghash, false);
inOfs, out, outOfs, gctr, ghash);
}
ghash.doFinal(in, inOfs + len, inLen - len);
return len + gctr.doFinal(in, inOfs + len, inLen - len, out,
Expand Down

0 comments on commit 8292699

Please sign in to comment.