Showing
23 changed files
with
205 additions
and
0 deletions
doc/기초조사서/기초조사서.docx
0 → 100644
No preview for this file type
doc/면담확인서/면담확인서(3월).hwp
0 → 100644
No preview for this file type
doc/면담확인서/면담확인서(4월).hwp
0 → 100644
No preview for this file type
doc/면담확인서/면담확인서(5월).hwp
0 → 100644
No preview for this file type
doc/미팅 발표 자료/0325 발표.pptx
0 → 100644
No preview for this file type
doc/미팅 발표 자료/0405 발표.pptx
0 → 100644
No preview for this file type
doc/미팅 발표 자료/0420 발표.pptx
0 → 100644
No preview for this file type
doc/미팅 발표 자료/0526 발표.pptx
0 → 100644
No preview for this file type
doc/주간보고서/주간보고서(2021.03.21).hwp
0 → 100644
No preview for this file type
doc/주간보고서/주간보고서(2021.03.28).hwp
0 → 100644
No preview for this file type
doc/주간보고서/주간보고서(2021.04.05).hwp
0 → 100644
No preview for this file type
doc/주간보고서/주간보고서(2021.04.12).hwp
0 → 100644
No preview for this file type
doc/주간보고서/주간보고서(2021.04.19).hwp
0 → 100644
No preview for this file type
doc/주간보고서/주간보고서(2021.04.26).hwp
0 → 100644
No preview for this file type
doc/주간보고서/주간보고서(2021.05.10).hwp
0 → 100644
No preview for this file type
doc/주간보고서/주간보고서(2021.05.16).hwp
0 → 100644
No preview for this file type
doc/주간보고서/주간보고서(2021.05.23).hwp
0 → 100644
No preview for this file type
doc/주간보고서/주간보고서(2021.06.17).hwp
0 → 100644
No preview for this file type
doc/중간보고서/중간보고서.doc
0 → 100644
No preview for this file type
doc/최종보고서/최종보고서.docx
0 → 100644
No preview for this file type
source code(OPENSSL)/RA_code.c
0 → 100644
1 | +void main (void) { | ||
2 | + char test_in [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
3 | + int test_in_len = strlen (test_in); | ||
4 | + | ||
5 | + char test_decrypted [512]; | ||
6 | + int test_decrypted_len; | ||
7 | + | ||
8 | + TEEC_Result rc; | ||
9 | + TEEC_Context ctx; | ||
10 | + TEEC_Session sess; | ||
11 | + TEEC_Operation op; | ||
12 | + TEEC_SharedMemory field_in; | ||
13 | + TEEC_SharedMemory field_back; | ||
14 | + TEEC_SharedMemory dummy; | ||
15 | + TEEC_UUID uuid = FIM_TA_UUID; | ||
16 | + uint32_t err_origin; | ||
17 | + | ||
18 | + rc = TEEC_InitializeContext(NULL, &ctx); | ||
19 | + rc = TEEC_OpenSession(&ctx, &sess, &uuid, TEEC_LOGIN_PUBLIC, NULL, NULL, &err_origin); | ||
20 | + check_rc(rc, "TEEC_OpenSession", &err_origin); | ||
21 | + | ||
22 | + field_in.buffer = NULL; | ||
23 | + field_in.size = 256; | ||
24 | + field_in.flags = TEEC_MEM_INPUT; | ||
25 | + rc = TEEC_AllocateSharedMemory(&ctx, &field_in); | ||
26 | + check_rc(rc, "TEEC_AllocateSharedMemory for field_in", NULL); | ||
27 | + | ||
28 | + field_back.buffer = NULL; | ||
29 | + field_back.size = 256; | ||
30 | + field_back.flags = TEEC_MEM_OUTPUT; | ||
31 | + rc = TEEC_AllocateSharedMemory(&ctx, &field_back); | ||
32 | + check_rc(rc, "TEEC_AllocateSharedMemory for field_back", NULL); | ||
33 | + | ||
34 | + dummy.buffer = NULL; | ||
35 | + dummy.size = 1; | ||
36 | + dummy.flags = TEEC_MEM_INPUT; | ||
37 | + rc = TEEC_AllocateSharedMemory(&ctx, &dummy); | ||
38 | + check_rc(rc, "TEEC_AllocateSharedMemory for dummy parameter", NULL); | ||
39 | + | ||
40 | + /* Clear the TEEC_Operation struct */ | ||
41 | + memset(&op, 0, sizeof(op)); | ||
42 | + | ||
43 | + op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_MEMREF_WHOLE, | ||
44 | + TEEC_MEMREF_WHOLE, TEEC_VALUE_OUTPUT); | ||
45 | + op.params[0].memref.parent = &field_in; | ||
46 | + op.params[1].memref.parent = &field_back; | ||
47 | + op.params[2].memref.parent = &dummy; | ||
48 | + op.params[3].value.a = 0; | ||
49 | + | ||
50 | + memcpy(field_in.buffer, test_in, test_in_len); | ||
51 | + field_in.size = test_in_len; | ||
52 | + rc = TEEC_InvokeCommand(&sess, TEST_ENCRYPT_IN_TA, &op, &err_origin); | ||
53 | + decrypt_using_public_key (CA_public_key_copy, (char *)field_back.buffer, field_back.size, test_decrypted, &test_decrypted_len); | ||
54 | + printf ("In string: %s\n", test_in); | ||
55 | + printf ("Test in len: %i\n", test_in_len); | ||
56 | + printf ("Encryted value: %s\n", (char *) field_back.buffer); | ||
57 | + printf ("Encryted len: %i\n", (int) field_back.size); | ||
58 | + printf ("Decrypted value: %s\n", test_decrypted); | ||
59 | + printf ("Decrypted len: %i\n", test_decrypted_len); | ||
60 | +} | ||
61 | + | ||
62 | +char CA_public_key_copy [] = | ||
63 | + "-----BEGIN PUBLIC KEY-----\n" | ||
64 | + "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAL5c51/v1osjr5+lRPykmpQKyGdXMG0g\n" | ||
65 | + "S6Du1l8Hm0qYXc+azq6qqZvr39zeufw/VLKTfeKeKVJX1D28TImn6cUCAwEAAQ==\n" | ||
66 | + "-----END PUBLIC KEY-----\n"; | ||
67 | + | ||
68 | + | ||
69 | + | ||
70 | +BOOLEAN decrypt_using_public_key (char * public_key, char * in, int in_len, char * out, int * out_len) { | ||
71 | + | ||
72 | + RSA * rsa = createRSA ((unsigned char *) public_key, 1); | ||
73 | + *out_len = RSA_public_decrypt (in_len, (unsigned char *)in, (unsigned char *) out, rsa, RSA_PKCS1_PADDING); | ||
74 | + | ||
75 | + if (*out_len == -1) | ||
76 | + return FALSE; | ||
77 | + else | ||
78 | + return TRUE; | ||
79 | + | ||
80 | +} | ||
81 | + | ||
82 | + | ||
83 | +RSA *createRSA(unsigned char *key, int public) { | ||
84 | + RSA *rsa = NULL; | ||
85 | + BIO *keybio; | ||
86 | + keybio = BIO_new_mem_buf(key, -1); | ||
87 | + if (keybio == NULL) { | ||
88 | + printf("Failed to create key BIO"); | ||
89 | + return 0; | ||
90 | + } | ||
91 | + if (public) { | ||
92 | + rsa = PEM_read_bio_RSA_PUBKEY(keybio, &rsa, NULL, NULL); | ||
93 | + } else { | ||
94 | + rsa = PEM_read_bio_RSAPrivateKey(keybio, &rsa, NULL, NULL); | ||
95 | + } | ||
96 | + if (rsa == NULL) { | ||
97 | + printf("Failed to create RSA"); | ||
98 | + } | ||
99 | + return rsa; | ||
100 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
source code(OPENSSL)/Reference_code.c
0 → 100644
This diff is collapsed. Click to expand it.
source code(OPENSSL)/TA_code.c
0 → 100644
1 | +static TEE_Result test_encrypt_ta(TEE_Param params[4]) | ||
2 | +{ | ||
3 | + | ||
4 | + char *in = (char *)params[TEST_STRING].memref.buffer; | ||
5 | + int in_len = params[TEST_STRING].memref.size; | ||
6 | + | ||
7 | + char encrypted[512]; | ||
8 | + int encrypted_len; | ||
9 | + | ||
10 | + encrypt_using_private_key(in, in_len, encrypted, &encrypted_len); | ||
11 | + memcpy(params[TEST_EN_DECRYPTED].memref.buffer, encrypted, encrypted_len); | ||
12 | + params[TEST_EN_DECRYPTED].memref.size = encrypted_len; | ||
13 | + params[TEST_RC_POS].value.a = ALL_OK; | ||
14 | + return TEE_SUCCESS; | ||
15 | +} | ||
16 | + | ||
17 | +bool encrypt_using_private_key(char *in, int in_len, char *out, int *out_len) | ||
18 | +{ | ||
19 | + | ||
20 | + TEE_Result ret = TEE_SUCCESS; // return code | ||
21 | + TEE_ObjectHandle key = (TEE_ObjectHandle)NULL; | ||
22 | + TEE_Attribute rsa_attrs[3]; | ||
23 | + void *to_encrypt = NULL; | ||
24 | + uint32_t cipher_len = 256; | ||
25 | + void *cipher = NULL; | ||
26 | + | ||
27 | + rsa_attrs[0].attributeID = TEE_ATTR_RSA_MODULUS; | ||
28 | + rsa_attrs[0].content.ref.buffer = CA_modulus; | ||
29 | + rsa_attrs[0].content.ref.length = SIZE_OF_VEC(CA_modulus); | ||
30 | + | ||
31 | + rsa_attrs[1].attributeID = TEE_ATTR_RSA_PUBLIC_EXPONENT; | ||
32 | + rsa_attrs[1].content.ref.buffer = CA_public_key; | ||
33 | + rsa_attrs[1].content.ref.length = SIZE_OF_VEC(CA_public_key); | ||
34 | + | ||
35 | + rsa_attrs[2].attributeID = TEE_ATTR_RSA_PRIVATE_EXPONENT; | ||
36 | + rsa_attrs[2].content.ref.buffer = CA_private_key; | ||
37 | + rsa_attrs[2].content.ref.length = SIZE_OF_VEC(CA_private_key); | ||
38 | + | ||
39 | + ret = TEE_AllocateTransientObject(TEE_TYPE_RSA_KEYPAIR, 1024, &key); | ||
40 | + ret = TEE_PopulateTransientObject(key, (TEE_Attribute *)&rsa_attrs, 3); | ||
41 | + to_encrypt = TEE_Malloc(in_len, 0); | ||
42 | + cipher = TEE_Malloc(cipher_len, 0); | ||
43 | + TEE_MemMove(to_encrypt, in, in_len - 1); | ||
44 | + if (!perform_rsa_operation(key, TEE_MODE_ENCRYPT, to_encrypt, in_len, cipher, &cipher_len)) | ||
45 | + { | ||
46 | + DMSG("Encrypt failed : 0x%x", ret); | ||
47 | + return TEE_ERROR_BAD_PARAMETERS; | ||
48 | + } | ||
49 | + | ||
50 | + memcpy(out, cipher, cipher_len); | ||
51 | + *out_len = cipher_len; | ||
52 | + out[cipher_len] = '\0'; | ||
53 | + DMSG("Return: %s", out); | ||
54 | + DMSG("Return lenght: %i", *out_len); | ||
55 | + | ||
56 | + return TRUE; | ||
57 | +} | ||
58 | + | ||
59 | +#define SIZE_OF_VEC(vec) (sizeof(vec) - 1) | ||
60 | + | ||
61 | +uint8_t CA_modulus[] = | ||
62 | + "\xbe\x5c\xe7\x5f\xef\xd6\x8b\x23\xaf\x9f\xa5\x44\xfc\xa4\x9a" | ||
63 | + "\x94\x0a\xc8\x67\x57\x30\x6d\x20\x4b\xa0\xee\xd6\x5f\x07\x9b" | ||
64 | + "\x4a\x98\x5d\xcf\x9a\xce\xae\xaa\xa9\x9b\xeb\xdf\xdc\xde\xb9" | ||
65 | + "\xfc\x3f\x54\xb2\x93\x7d\xe2\x9e\x29\x52\x57\xd4\x3d\xbc\x4c" | ||
66 | + "\x89\xa7\xe9\xc5"; | ||
67 | + | ||
68 | +uint8_t CA_public_key[] = | ||
69 | + "\x01\x00\x01"; | ||
70 | + | ||
71 | +uint8_t CA_private_key[] = | ||
72 | + "\x48\x30\x89\x19\xcb\xa5\x2b\xac\xc3\xcc\x21\xeb\x90\x77\x87" | ||
73 | + "\x9b\x3e\x9f\x92\xf8\xf0\x87\x61\xa8\xec\x85\xc6\x4b\xd1\x61" | ||
74 | + "\xa5\x9e\x8b\xc7\xa1\x5a\x72\xf0\x04\xc8\x04\x5d\x5e\x52\x18" | ||
75 | + "\x5c\xd4\x68\x82\x21\x17\xdd\xa1\xcc\x42\x87\xe5\x84\xe1\x58" | ||
76 | + "\x20\xc2\x03\x7d"; | ||
77 | + | ||
78 | +B perform_rsa_operation(TEE_ObjectHandle key, TEE_OperationMode mode, | ||
79 | + void *in_chunk, uint32_t in_chunk_len, | ||
80 | + void *out_chunk, uint32_t *out_chunk_len) | ||
81 | +{ | ||
82 | + | ||
83 | + TEE_ObjectInfo info; | ||
84 | + TEE_OperationHandle handle = (TEE_OperationHandle)NULL; | ||
85 | + TEE_Result ret = TEE_SUCCESS; | ||
86 | + | ||
87 | + TEE_GetObjectInfo(key, &info); | ||
88 | + ret = TEE_AllocateOperation(&handle, TEE_ALG_RSAES_PKCS1_V1_5, mode, info.maxObjectSize); | ||
89 | + ret = TEE_SetOperationKey(handle, key); | ||
90 | + | ||
91 | + if (mode == TEE_MODE_ENCRYPT) | ||
92 | + { | ||
93 | + DMSG("Encrypting values\n"); | ||
94 | + ret = TEE_AsymmetricEncrypt(handle, (TEE_Attribute *)NULL, 0, in_chunk, in_chunk_len, out_chunk, out_chunk_len); | ||
95 | + } | ||
96 | + | ||
97 | + if (mode == TEE_MODE_DECRYPT) | ||
98 | + { | ||
99 | + DMSG("Decrypting values\n"); | ||
100 | + ret = TEE_AsymmetricDecrypt(handle, (TEE_Attribute *)NULL, 0, in_chunk, in_chunk_len, out_chunk, out_chunk_len); | ||
101 | + } | ||
102 | + | ||
103 | + TEE_FreeOperation(handle); | ||
104 | + return TRUE; | ||
105 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment