OpenCores
URL https://opencores.org/ocsvn/avs_aes/avs_aes/trunk

Subversion Repositories avs_aes

[/] [avs_aes/] [trunk/] [sw/] [AEStester.c] - Blame information for rev 21

Details | Compare with Previous | View Log

Line No. Rev Author Line
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 21 ruschi
int main() {
42
        avs_aes_handle context;
43
        int i = 0;
44 5 ruschi
 
45 21 ruschi
        unsigned int result[4];
46
        unsigned int Userkey[] = {
47
                        0x11111111, 0x22222222,
48
                        0x33333333, 0x44444444,
49
                        0x55555555, 0x66666666,
50
                        0x77777777, 0x88888888
51
        };
52
        unsigned int Payload[] = {
53
                        0xAA555555, 0xBB666666,
54
                        0xCC777777, 0xDD888888
55
        };
56 5 ruschi
 
57
// START AES-Operations
58
        printf("AES-Test\n");
59 21 ruschi
        avs_aes_init(&context);
60
        avs_aes_setKey(&context, &Userkey);
61
        avs_aes_setPayload(&context, &Payload);
62
        avs_aes_encrypt(&context);
63 11 ruschi
 
64 21 ruschi
        while (avs_aes_isBusy(&context)) {
65
                printf("not ready\n");
66
        }
67
        printf("receiving 729cd44f 32a48d85 b8188185 c579ae49\n");
68
        memcpy(result, context.result, sizeof(result));
69
        for (i = 0; i < 4; i++) {
70
                printf("received 0x%X \n", result[i]);
71
        }
72
 
73 5 ruschi
// Decrypt same payload -  
74 21 ruschi
        avs_aes_decrypt(&context);
75
        while (avs_aes_isBusy(&context)) {
76
                printf("not ready\n");
77
        }
78
        printf("receiving 9c7076af ac2e5716 6681d3ac 014f64c0 \n");
79
        memcpy(result, context.result, sizeof(result));
80
        for (i = 0; i < 4; i++) {
81
                printf("received 0x%X \n", result[i]);
82
        }
83 5 ruschi
// Change payload ...
84
        Payload[3] = 0x11111111;
85 21 ruschi
        Payload[2] = 0xAAAAAAAA;
86
        Payload[1] = 0xCCCCCCCC;
87 5 ruschi
        Payload[0] = 0x00000000;
88
        //new encryption
89 21 ruschi
        avs_aes_setPayload(&context, &Payload);
90 5 ruschi
        avs_aes_encrypt(&context);
91 21 ruschi
        while (avs_aes_isBusy(&context)) {
92
                printf("not ready\n");
93
        }
94
        memcpy(result, context.result, sizeof(result));
95
        for (i = 0; i < 4; i++) {
96
                printf("received 0x%X \n", result[i]);
97
        }
98 5 ruschi
        //new decryption
99 21 ruschi
        avs_aes_decrypt(&context);
100
        while (avs_aes_isBusy(&context)) {
101
                printf("not ready\n");
102
        }
103
        memcpy(result, context.result, 4 * sizeof(unsigned int));
104
        for (i = 0; i < 4; i++) {
105
                printf("received 0x%X \n", result[i]);
106
        }
107
        printf("Done \n");
108 5 ruschi
 
109 21 ruschi
        return 0;
110
 
111 5 ruschi
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.