Skip to content

Commit

Permalink
TKSS-850: Add reset and reuse test cases for SM3HMac
Browse files Browse the repository at this point in the history
  • Loading branch information
johnshajiang committed Sep 2, 2024
1 parent 9fb1822 commit 612d646
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022, 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2022, 2024, 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 it
Expand Down Expand Up @@ -200,6 +200,35 @@ public void testBigByteBuffer() throws Exception {
Assertions.assertArrayEquals(mac, macBuffer);
}

@Test
public void testReuse() throws Exception {
Mac hmacSM3 = Mac.getInstance("HmacSM3", PROVIDER);
SecretKeySpec keySpec = new SecretKeySpec(KEY, "HmacSM3");
hmacSM3.init(keySpec);

byte[] mac1 = hmacSM3.doFinal(MESSAGE);
Assertions.assertArrayEquals(MAC, mac1);

byte[] mac2 = hmacSM3.doFinal(MESSAGE);
Assertions.assertArrayEquals(MAC, mac2);
}

@Test
public void testReset() throws Exception {
Mac hmacSM3 = Mac.getInstance("HmacSM3", PROVIDER);
SecretKeySpec keySpec = new SecretKeySpec(KEY, "HmacSM3");
hmacSM3.init(keySpec);

hmacSM3.update(MESSAGE, 0, MESSAGE.length / 2);
hmacSM3.reset();
hmacSM3.update(MESSAGE, 0, MESSAGE.length / 2);
hmacSM3.update(MESSAGE, MESSAGE.length / 2,
MESSAGE.length - MESSAGE.length / 2);
byte[] mac = hmacSM3.doFinal();

Assertions.assertArrayEquals(MAC, mac);
}

@Test
public void testHmacSM3Parallelly() throws Exception {
TestUtils.repeatTaskParallelly(() -> {
Expand Down

0 comments on commit 612d646

Please sign in to comment.