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

Subversion Repositories tiny_aes

[/] [tiny_aes/] [trunk/] [testcase_generator/] [gen_test_case.c] - Blame information for rev 13

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 homer.hsin
#include <stdio.h>
2
#include <stdlib.h>
3
 
4
typedef unsigned char byte;
5
typedef unsigned int word;
6
 
7
void encrypt_128_key_expand_inline_no_branch(word state[], word key[]);
8
void encrypt_192_key_expand_inline_no_branch(word state[], word key[]);
9
void encrypt_256_key_expand_inline_no_branch(word state[], word key[]);
10
 
11
word rand_word();
12
void rand_word_array(word w[], int bit_num);
13
void print_verilog_hex(word w[], int bit_num);
14
 
15
int main() {
16
    const int num_case = 5;
17
    int bit_num;
18
    int i;
19
    word state[4];
20
    word key[8];
21
 
22
    bit_num = 128;
23
    printf("AES-%d test cases:\n\n", bit_num);
24
    for(i=0; i<num_case; i++) {
25
        rand_word_array(state, 128);
26
        rand_word_array(key, bit_num);
27
        printf("plaintext: ");
28
        print_verilog_hex(state, 128);
29
        printf("\n");
30
        printf("key:       ");
31
        print_verilog_hex(key, bit_num);
32
        printf("\n");
33
        encrypt_128_key_expand_inline_no_branch(state, key);
34
        printf("ciphertext:");
35
        print_verilog_hex(state, 128);
36
        printf("\n\n");
37
    }
38
 
39
    bit_num = 192;
40
    printf("AES-%d test cases:\n\n", bit_num);
41
    for(i=0; i<num_case; i++) {
42
        rand_word_array(state, 128);
43
        rand_word_array(key, bit_num);
44
        printf("plaintext: ");
45
        print_verilog_hex(state, 128);
46
        printf("\n");
47
        printf("key:       ");
48
        print_verilog_hex(key, bit_num);
49
        printf("\n");
50
        encrypt_192_key_expand_inline_no_branch(state, key);
51
        printf("ciphertext:");
52
        print_verilog_hex(state, 128);
53
        printf("\n\n");
54
    }
55
 
56
    bit_num = 256;
57
    printf("AES-%d test cases:\n\n", bit_num);
58
    for(i=0; i<num_case; i++) {
59
        rand_word_array(state, 128);
60
        rand_word_array(key, bit_num);
61
        printf("plaintext: ");
62
        print_verilog_hex(state, 128);
63
        printf("\n");
64
        printf("key:       ");
65
        print_verilog_hex(key, bit_num);
66
        printf("\n");
67
        encrypt_256_key_expand_inline_no_branch(state, key);
68
        printf("ciphertext:");
69
        print_verilog_hex(state, 128);
70
        printf("\n\n");
71
    }
72
 
73
    return 0;
74
}
75
 
76
word rand_word() {
77
    word w = 0;
78
    int i;
79
    for(i=0; i<4; i++) {
80
        word x = rand() & 255;
81
        w = (w << 8) | x;
82
    }
83
    return w;
84
}
85
 
86
void rand_word_array(word w[], int bit_num) {
87
    int word_num = bit_num / 32;
88
    int i;
89
    for(i=0; i<word_num; i++)
90
        w[i] = rand_word();
91
}
92
 
93
void print_verilog_hex(word w[], int bit_num) {
94
    int byte_num = bit_num / 8;
95
    int i;
96
    byte *b = (byte *)w;
97
    printf("%d'h", bit_num);
98
    for(i=0; i<byte_num; i++)
99
        printf("%02x", b[i]);
100
}

powered by: WebSVN 2.1.0

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