mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-07 00:46:17 +08:00
sm2 with short ciphertext
This commit is contained in:
5
demos/otp/Makefile
Normal file
5
demos/otp/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
all:
|
||||
gcc mkgen.c ../../libcrypto.a -o mkgen
|
||||
gcc tkgen.c ../../libcrypto.a -o tkgen
|
||||
clean:
|
||||
rm -fr mkgen tkgen
|
||||
21
demos/otp/mkgen.c
Normal file
21
demos/otp/mkgen.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <libgen.h>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
unsigned char mk[32];
|
||||
int i;
|
||||
|
||||
RAND_bytes(mk, sizeof(mk));
|
||||
|
||||
for (i = 0; i < sizeof(mk); i++) {
|
||||
printf("%02x", mk[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
49
demos/otp/tkgen.c
Normal file
49
demos/otp/tkgen.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <libgen.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/otp.h>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *prog;
|
||||
char *id;
|
||||
char *mk;
|
||||
int offset;
|
||||
OTP_PARAMS params;
|
||||
unsigned int otp;
|
||||
|
||||
prog = basename(argv[0]);
|
||||
|
||||
if (argc < 3) {
|
||||
printf("usage: %s <event> <key> [<offset>]\n", prog);
|
||||
return 0;
|
||||
}
|
||||
|
||||
id = argv[1];
|
||||
mk = argv[2];
|
||||
|
||||
if (argc > 3)
|
||||
offset = atoi(argv[3]);
|
||||
|
||||
params.type = NID_sm3;
|
||||
params.te = 60;
|
||||
params.option = "end";
|
||||
params.option_size = strlen(params.option);
|
||||
params.otp_digits = 6;
|
||||
params.offset = offset;
|
||||
|
||||
OpenSSL_add_all_algorithms();
|
||||
if (!OTP_generate(¶ms, id, strlen(id), &otp, (unsigned char *)mk, strlen(mk))) {
|
||||
fprintf(stderr, "failed\n");
|
||||
}
|
||||
|
||||
printf("OTP = %06u\n", otp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user