Skip to content

Commit

Permalink
TKSS-1036: Native SM3HMac engineUpdate should check parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
johnshajiang committed Jan 10, 2025
1 parent bde5f8d commit c3e8ee5
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2024, 2025, THL A29 Limited, a Tencent company. 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
Expand All @@ -22,6 +22,7 @@

import com.tencent.kona.crypto.util.Constants;
import com.tencent.kona.crypto.util.Sweeper;
import com.tencent.kona.jdk.internal.util.Preconditions;

import javax.crypto.MacSpi;
import javax.crypto.SecretKey;
Expand Down Expand Up @@ -57,7 +58,7 @@ protected void engineInit(Key key, AlgorithmParameterSpec params)
throw new InvalidKeyException("No key data");
}

sm3HMac = new NativeSM3HMac(key.getEncoded());
sm3HMac = new NativeSM3HMac(secret);

SWEEPER.register(this, new SweepNativeRef(sm3HMac));
}
Expand All @@ -69,6 +70,12 @@ protected void engineUpdate(byte input) {

@Override
protected void engineUpdate(byte[] input, int offset, int len) {
if (len == 0) {
return;
}
Preconditions.checkFromIndexSize(
offset, len, input.length, Preconditions.AIOOBE_FORMATTER);

byte[] data = new byte[len];
System.arraycopy(input, offset, data, 0, len);
sm3HMac.update(data);
Expand Down

0 comments on commit c3e8ee5

Please sign in to comment.