• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the License); you may
5  *  not use this file except in compliance with the License.
6  *
7  *  http://www.apache.org/licenses/LICENSE-2.0
8  */
9 
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <gmssl/zuc.h>
14 
15 
main(void)16 int main(void)
17 {
18 	ZUC_CTX zuc_ctx;
19 	unsigned char key[16] = {
20 		0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,
21 		0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,
22 	};
23 	unsigned char iv[16] = {
24 		0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,
25 		0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,
26 	};
27 	unsigned char inbuf[1024];
28 	unsigned char outbuf[1024 + 32];
29 	ssize_t inlen;
30 	size_t outlen;
31 
32 	if (zuc_encrypt_init(&zuc_ctx, key, iv) != 1) {
33 		fprintf(stderr, "%s %d: error\n", __FILE__, __LINE__);
34 		return 1;
35 	}
36 	while ((inlen = fread(inbuf, 1, sizeof(inbuf), stdin)) > 0) {
37 		if (zuc_encrypt_update(&zuc_ctx, inbuf, inlen, outbuf, &outlen) != 1) {
38 			fprintf(stderr, "%s %d: error\n", __FILE__, __LINE__);
39 			return 1;
40 		}
41 		fwrite(outbuf, 1, outlen, stdout);
42 	}
43 	if (zuc_encrypt_finish(&zuc_ctx, outbuf, &outlen) != 1) {
44 		fprintf(stderr, "%s %d: error\n", __FILE__, __LINE__);
45 		return 1;
46 	}
47 	fwrite(outbuf, 1, outlen, stdout);
48 
49 	return 0;
50 }
51