linaro-swg / optee_examples

OP-TEE Sample Applications
Other
163 stars 140 forks source link

Getting input from user #25

Closed cezane closed 6 years ago

cezane commented 6 years ago

I am changing the AES example in order to encrypt/decrypt some data received from the user. In the host main.c file, I am using:

printf("Please type your secret: \n");
fflush(stdin);
fgets(clear, sizeof(clear), stdin);

printf("Load key in TA\n");
memset(key, 0xa5, sizeof(key)); /* Load some dummy value */
set_key(&ctx, key, AES_TEST_KEY_SIZE);

printf("Reset ciphering operation in TA (provides the initial vector)\n");
memset(iv, 0, sizeof(iv)); /* Load some dummy value */
set_iv(&ctx, iv, AES_TEST_KEY_SIZE);

cipher_buffer(&ctx, ciph, temp, AES_TEST_BUFFER_SIZE);

In the TA side, I put the following in the cipher_buffer function:

DMSG("Secret received: %s", (char *) params[0].memref.buffer);

And I am getting the following output:

D/TA: cipherbuffer:356 Secret received: �3��(��߽vr�]tS���NM=���(����Ο� 2 �\��$��\�gól�6�-(���ݠ��fn��e�>��l���]�@�q;](K�bU��A���Ը �@\��p����~Odž���DJ�^�m�XyR�����H��)V*�Ћ�G�:nXu�j��Ts�����m$g�q��@nU�iRդd�ht�����>aN4%m�g��>ˣ�v

I would like to know if I am missing something because (char *) params[0].memref.buffer is not printing the string I am passing. I know TEE_PARAM_TYPE_MEMREF_INPUT has two attributes: a buffer ( void *) and a size (size_t). So, why this cast is not working properly?

Thank you.

vchong commented 6 years ago

It sounds like you want to pass in clear, but you're actually passing in ciph in cipher_buffer(&ctx, ciph, temp, AES_TEST_BUFFER_SIZE);. Try cipher_buffer(&ctx, clear, ciph, AES_TEST_BUFFER_SIZE); instead.

cezane commented 6 years ago

Yes, @vchong . I just noticed few minutes after opening this issue. The code was correct, but I was just seeing the print of the "decrypt" part, when ciph is passed (few lines before it is possible to see the clear string printed correctly). Thank you.