sm2 with short ciphertext

This commit is contained in:
Zhi Guan
2016-05-16 20:38:44 +02:00
parent 60d14da0cc
commit 62b396d193
19 changed files with 249 additions and 138 deletions

5
demos/otp/Makefile Normal file
View 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
View 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
View 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(&params, id, strlen(id), &otp, (unsigned char *)mk, strlen(mk))) {
fprintf(stderr, "failed\n");
}
printf("OTP = %06u\n", otp);
return 0;
}