-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SM4 pass openssl and other known test vectors. SM4-GCM and SM4-XTS only support the GB/T GF(2^128) encoding standard.
- Loading branch information
Showing
16 changed files
with
1,267 additions
and
691 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,8 @@ set(tools | |
|
||
set(tests | ||
sm4 | ||
sm4_cbc | ||
sm4_ctr | ||
sm3 | ||
sm4_sm3_hmac | ||
sm2_z256 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2014-2024 The GmSSL Project. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the License); you may | ||
* not use this file except in compliance with the License. | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <gmssl/rdrand.h> | ||
#include <gmssl/error.h> | ||
|
||
|
||
int test_rdrand(void) | ||
{ | ||
const uint8_t zeros[32] = {0}; | ||
uint8_t buf[32] = {0}; | ||
|
||
if (rdrand_bytes(buf, sizeof(buf)) != 1) { | ||
error_print(); | ||
return -1; | ||
} | ||
if (memcmp(buf, zeros, sizeof(zeros)) == 0) { | ||
error_print(); | ||
return -1; | ||
} | ||
|
||
printf("%s() ok\n", __FUNCTION__); | ||
return 1; | ||
} | ||
|
||
int test_rdseed(void) | ||
{ | ||
const uint8_t zeros[32] = {0}; | ||
uint8_t buf[32] = {0}; | ||
|
||
if (rdseed_bytes(buf, sizeof(buf)) != 1) { | ||
error_print(); | ||
return -1; | ||
} | ||
if (memcmp(buf, zeros, sizeof(zeros)) == 0) { | ||
error_print(); | ||
return -1; | ||
} | ||
|
||
printf("%s() ok\n", __FUNCTION__); | ||
return 1; | ||
} | ||
|
||
int main(void) | ||
{ | ||
if (test_rdrand() != 1) goto err; | ||
if (test_rdseed() != 1) goto err; | ||
printf("%s all tests passed\n", __FILE__); | ||
return 0; | ||
err: | ||
error_print(); | ||
return 1; | ||
} |
Oops, something went wrong.