source: svn/trunk/newcon3bcm2_21bu/dta/src/bootloader/aes/main.c @ 2

Last change on this file since 2 was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 721 bytes
Line 
1// AES usage example
2// compile as: gcc main.c aes.h aes.c
3
4#include <stdlib.h>
5#include <stdio.h>
6#include "aes.h"
7
8int main(int argc, char *argv[])
9{
10        unsigned char key[KEY_128] = "uber strong key!";
11        unsigned char ptext[16] = "Attack at dawn!";
12        unsigned char ctext[16];
13        unsigned char decptext[16];
14        aes_ctx_t *ctx;
15        int i;
16
17        init_aes();
18        ctx = aes_alloc_ctx(key, sizeof(key));
19        if(!ctx) {
20                perror("aes_alloc_ctx");
21                return EXIT_FAILURE;
22        }
23        aes_encrypt(ctx, ptext, ctext);
24        aes_decrypt(ctx, ctext, decptext);
25        i = 16;
26        printf("plaintext: %s\nciphertext: ", ptext);
27        for(i = 0; i < 16; i++)
28                printf("%02x", ctext[i]);
29        printf("\ndecrypted ciphertext: %s\n", decptext);
30
31        aes_free_ctx(ctx);
32        return EXIT_SUCCESS;
33}
Note: See TracBrowser for help on using the repository browser.