Showing
8 changed files
with
81 additions
and
1 deletions
IoT 디바이스 암호 라이브러리 최적화(강현태).docx
0 → 100644
No preview for this file type
Makefile
0 → 100644
1 | +test : clean test.o | ||
2 | + ./test/bin/test.o > report.xml | ||
3 | +test.o : | ||
4 | + gcc test/src/test.c -L/usr/local/opt/openssl/lib -o test/bin/test.o -lcmocka -lssl -lcrypto | ||
5 | +pull : | ||
6 | + cd lib; \ | ||
7 | + git clone https://github.com/openssl/openssl.git; \ | ||
8 | + ./config --prefix= | ||
9 | + | ||
10 | + | ||
11 | +clean : | ||
12 | + rm -f ~/test/bin/test.o report.xml | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
docs/1주.pptx
0 → 100644
No preview for this file type
docs/plan.docx
0 → 100644
No preview for this file type
docs/구상도.pptx
0 → 100644
No preview for this file type
File moved
test/src/test.c
0 → 100644
1 | +#include <stdarg.h> | ||
2 | +#include <stddef.h> | ||
3 | +#include <setjmp.h> | ||
4 | +#include <cmocka.h> | ||
5 | +#include <string.h> | ||
6 | + | ||
7 | +#include <stdio.h> | ||
8 | +#include <openssl/rsa.h> | ||
9 | + | ||
10 | +#define ASCII_START 32 | ||
11 | +#define ASCII_END 126 | ||
12 | + | ||
13 | +char* generateRandomString(int size) { | ||
14 | + int i; | ||
15 | + char *res = malloc(size + 1); | ||
16 | + for(i = 0; i < size; i++) { | ||
17 | + res[i] = (char) (rand()%(ASCII_END-ASCII_START))+ASCII_START; | ||
18 | + } | ||
19 | + res[i] = '\0'; | ||
20 | + return res; | ||
21 | +} | ||
22 | + | ||
23 | +static void rsa_normal_test(void **state){ | ||
24 | + int i; | ||
25 | + int bits = 2048; //key size | ||
26 | + int buflen = 1024; //buffer suze | ||
27 | + unsigned char *plaintext, *ciphertext, *randomstring; | ||
28 | + int same; | ||
29 | + BIGNUM *bn = BN_new(); | ||
30 | + BN_set_word(bn, RSA_F4); | ||
31 | + | ||
32 | + //1. rsa구조체 생성 | ||
33 | + RSA *rsa = RSA_new(); | ||
34 | + | ||
35 | + //2. key pair(private,public) 생성 | ||
36 | + RSA_generate_key_ex(rsa, bits, bn, NULL); | ||
37 | + | ||
38 | + //3. 본인의 public key로 암호화. | ||
39 | + randomstring=plaintext=(unsigned char*)generateRandomString(buflen); | ||
40 | + RSA_public_encrypt(buflen, plaintext, ciphertext, rsa,RSA_PKCS1_OAEP_PADDING); | ||
41 | + | ||
42 | + //4. 본인의 private key로 복호화. | ||
43 | + RSA_private_decrypt(buflen, ciphertext, plaintext, rsa,RSA_PKCS1_OAEP_PADDING); | ||
44 | + | ||
45 | + //5. 원 평문과 일치하는지 확인 | ||
46 | + same = 1; | ||
47 | + for(i=0;i<buflen;i++){ | ||
48 | + if(plaintext[i]!=randomstring[i]){ | ||
49 | + same=0; | ||
50 | + break; | ||
51 | + } | ||
52 | + } | ||
53 | + assert_true(same); | ||
54 | + | ||
55 | + (void)state; | ||
56 | +} | ||
57 | + | ||
58 | +int main(void){ | ||
59 | + srand(time(NULL)); | ||
60 | + cmocka_set_message_output(CM_OUTPUT_XML); | ||
61 | + const struct CMUnitTest test_group[]={ | ||
62 | + cmocka_unit_test(rsa_normal_test) | ||
63 | + }; | ||
64 | + | ||
65 | + return cmocka_run_group_tests(test_group,NULL,NULL); | ||
66 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment