mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-06 16:36:16 +08:00
Add ZUC demo
This commit is contained in:
8
demos/zuc/Makefile
Normal file
8
demos/zuc/Makefile
Normal file
@@ -0,0 +1,8 @@
|
||||
all:
|
||||
cc zuc_demo.c -lgmssl -o zuc_encrypt_demo
|
||||
cc zuc_demo.c -lgmssl -o zuc_decrypt_demo
|
||||
|
||||
clean:
|
||||
rm -fr zuc_encrypt_demo
|
||||
rm -fr zuc_decrypt_demo
|
||||
|
||||
41
demos/zuc/zuc_demo.c
Normal file
41
demos/zuc/zuc_demo.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmssl/zuc.h>
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ZUC_CTX zuc_ctx;
|
||||
unsigned char key[16] = {
|
||||
0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,
|
||||
0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,
|
||||
};
|
||||
unsigned char iv[16] = {
|
||||
0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,
|
||||
0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,
|
||||
};
|
||||
unsigned char inbuf[1024];
|
||||
unsigned char outbuf[1024 + 32];
|
||||
ssize_t inlen;
|
||||
size_t outlen;
|
||||
|
||||
if (zuc_encrypt_init(&zuc_ctx, key, iv) != 1) {
|
||||
fprintf(stderr, "%s %d: error\n", __FILE__, __LINE__);
|
||||
return 1;
|
||||
}
|
||||
while ((inlen = fread(inbuf, 1, sizeof(inbuf), stdin)) > 0) {
|
||||
if (zuc_encrypt_update(&zuc_ctx, inbuf, inlen, outbuf, &outlen) != 1) {
|
||||
fprintf(stderr, "%s %d: error\n", __FILE__, __LINE__);
|
||||
return 1;
|
||||
}
|
||||
fwrite(outbuf, 1, outlen, stdout);
|
||||
}
|
||||
if (zuc_encrypt_finish(&zuc_ctx, outbuf, &outlen) != 1) {
|
||||
fprintf(stderr, "%s %d: error\n", __FILE__, __LINE__);
|
||||
return 1;
|
||||
}
|
||||
fwrite(outbuf, 1, outlen, stdout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user