Created
November 1, 2017 15:44
-
-
Save jessicacarneiro/01d24ba27fd943836056dfa02a1c3a27 to your computer and use it in GitHub Desktop.
Example of use of RELIC's AES function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include "relic.h" | |
| #define KEYSZ 128 | |
| int main() | |
| { | |
| if (core_init() != STS_OK) { | |
| core_clean(); | |
| return EXIT_FAILURE; | |
| } | |
| if (pc_param_set_any() != STS_OK) { | |
| THROW(ERR_NO_CURVE); | |
| core_clean(); | |
| return EXIT_FAILURE; | |
| } | |
| uint8_t key[KEYSZ] = { 1 }; | |
| uint8_t iv[BC_LEN] = { 0 }; | |
| uint8_t input[5] = {'A','l','i','c','e'}; | |
| uint8_t output[KEYSZ]; | |
| int output_sz = KEYSZ; | |
| if (bc_aes_cbc_enc(output, &output_sz, input, 5, key, KEYSZ, iv) == STS_OK) | |
| printf("1.Success enc\n"); | |
| else | |
| printf("1.Error enc\n"); | |
| printf("2.Output size in enc is %d\n", output_sz); | |
| printf("3.Input: "); | |
| for (int i = 0; i < 5; i++) { | |
| printf("%c", input[i]); | |
| } | |
| printf("\n"); | |
| uint8_t dec[KEYSZ]; | |
| memset(dec, 0, KEYSZ); | |
| printf("\n"); | |
| int dec_sz = KEYSZ; | |
| if (bc_aes_cbc_dec(dec, &dec_sz, output, output_sz, key, KEYSZ, iv) == STS_OK) | |
| printf("4.Success dec\n"); | |
| else | |
| printf("4.Error dec\n"); | |
| printf("5.Output size in dec is %d\n", dec_sz); | |
| printf("6.Output: "); | |
| for (int i = 0; i < dec_sz; i++) { | |
| printf("%c", dec[i]); | |
| } | |
| printf("\n"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment