1 |
11 |
ruschi |
/**
|
2 |
|
|
* \file AEStester.c
|
3 |
|
|
* \brief test program and example of how to use the software
|
4 |
|
|
*
|
5 |
|
|
* This file is part of the project avs_aes
|
6 |
|
|
* see: http://opencores.org/project,avs_aes
|
7 |
|
|
*
|
8 |
|
|
* \section AUTHORS
|
9 |
|
|
* Thomas Ruschival -- ruschi@opencores.org (www.ruschival.de)
|
10 |
|
|
*
|
11 |
|
|
* \section LICENSE
|
12 |
|
|
* Copyright (c) 2009, Authors and opencores.org
|
13 |
|
|
* All rights reserved.
|
14 |
|
|
*
|
15 |
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
16 |
|
|
* are permitted provided that the following conditions are met:
|
17 |
|
|
* * Redistributions of source code must retain the above copyright notice,
|
18 |
|
|
* this list of conditions and the following disclaimer.
|
19 |
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
20 |
|
|
* this list of conditions and the following disclaimer in the documentation
|
21 |
|
|
* and/or other materials provided with the distribution.
|
22 |
|
|
* * Neither the name of the organization nor the names of its contributors
|
23 |
|
|
* may be used to endorse or promote products derived from this software without
|
24 |
|
|
* specific prior written permission.
|
25 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
26 |
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
27 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
28 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
29 |
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
30 |
|
|
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
31 |
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
32 |
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
33 |
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
34 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
35 |
|
|
* THE POSSIBILITY OF SUCH DAMAGE
|
36 |
|
|
*/
|
37 |
5 |
ruschi |
#include <stdio.h>
|
38 |
|
|
#include <string.h>
|
39 |
|
|
#include <avs_aes.h>
|
40 |
|
|
|
41 |
|
|
int main(){
|
42 |
|
|
avs_aes_handle context;
|
43 |
|
|
int i=0;
|
44 |
|
|
|
45 |
|
|
unsigned int result[4];
|
46 |
|
|
unsigned int Userkey[8] = {
|
47 |
|
|
0x11111111,0x22222222,0x33333333,0x44444444,
|
48 |
|
|
0x55555555,0x66666666,0x77777777,0x88888888};
|
49 |
|
|
unsigned int Payload[4] = {
|
50 |
|
|
0xAA555555,0xBB666666,0xCC777777,0xDD888888};
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
// START AES-Operations
|
54 |
|
|
printf("AES-Test\n");
|
55 |
|
|
avs_aes_init(&context);
|
56 |
|
|
avs_aes_setKey(&context,&Userkey);
|
57 |
|
|
avs_aes_setPayload(&context,&Payload);
|
58 |
|
|
avs_aes_encrypt(&context);
|
59 |
11 |
ruschi |
|
60 |
5 |
ruschi |
while(avs_aes_isBusy(&context)){
|
61 |
|
|
printf("not ready\n");
|
62 |
|
|
}
|
63 |
|
|
printf("receiving 729cd44f 32a48d85 b8188185 c579ae49\n");
|
64 |
|
|
memcpy(result,context.result,4*sizeof(unsigned int));
|
65 |
|
|
for(i=0; i<4 ; i++){
|
66 |
|
|
printf("received 0x%X \n",result[i]);
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
// Decrypt same payload -
|
70 |
|
|
avs_aes_decrypt(&context);
|
71 |
|
|
while(avs_aes_isBusy(&context)){
|
72 |
|
|
printf("not ready\n");
|
73 |
|
|
}
|
74 |
|
|
printf("receiving 9c7076af ac2e5716 6681d3ac 014f64c0 \n");
|
75 |
|
|
memcpy(result,context.result,4*sizeof(unsigned int));
|
76 |
|
|
for(i=0; i<4 ; i++){
|
77 |
|
|
printf("received 0x%X \n",result[i]);
|
78 |
|
|
}
|
79 |
|
|
// Change payload ...
|
80 |
|
|
Payload[3] = 0x11111111;
|
81 |
|
|
Payload[2] = 0xAAAAAAAA;
|
82 |
|
|
Payload[1] = 0xCCCCCCCC;
|
83 |
|
|
Payload[0] = 0x00000000;
|
84 |
|
|
//new encryption
|
85 |
|
|
avs_aes_setPayload(&context,&Payload);
|
86 |
|
|
avs_aes_encrypt(&context);
|
87 |
|
|
while(avs_aes_isBusy(&context)){
|
88 |
|
|
printf("not ready\n");
|
89 |
|
|
}
|
90 |
|
|
memcpy(result,context.result,4*sizeof(unsigned int));
|
91 |
|
|
for(i=0; i<4 ; i++){
|
92 |
|
|
printf("received 0x%X \n",result[i]);
|
93 |
|
|
}
|
94 |
|
|
//new decryption
|
95 |
|
|
avs_aes_decrypt(&context);
|
96 |
|
|
while(avs_aes_isBusy(&context)){
|
97 |
|
|
printf("not ready\n");
|
98 |
|
|
}
|
99 |
|
|
memcpy(result,context.result,4*sizeof(unsigned int));
|
100 |
|
|
for(i=0; i<4 ; i++){
|
101 |
|
|
printf("received 0x%X \n",result[i]);
|
102 |
|
|
}
|
103 |
|
|
printf("Done \n");
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
return 0;
|
107 |
|
|
|
108 |
|
|
}
|