OLD | NEW |
1 /* | 1 /* |
2 * aes_calc.c | 2 * aes_calc.c |
3 * | 3 * |
4 * A simple AES calculator for generating AES encryption values | 4 * A simple AES calculator for generating AES encryption values |
5 * | 5 * |
6 * David A. McGrew | 6 * David A. McGrew |
7 * Cisco Systems, Inc. | 7 * Cisco Systems, Inc. |
8 */ | 8 */ |
| 9 |
9 /* | 10 /* |
10 * | 11 * |
11 * Copyright (c) 2001-2006, Cisco Systems, Inc. | 12 * Copyright (c) 2001-2006, Cisco Systems, Inc. |
12 * All rights reserved. | 13 * All rights reserved. |
13 * | 14 * |
14 * Redistribution and use in source and binary forms, with or without | 15 * Redistribution and use in source and binary forms, with or without |
15 * modification, are permitted provided that the following conditions | 16 * modification, are permitted provided that the following conditions |
16 * are met: | 17 * are met: |
17 * | 18 * |
18 * Redistributions of source code must retain the above copyright | 19 * Redistributions of source code must retain the above copyright |
(...skipping 27 matching lines...) Expand all Loading... |
46 | 47 |
47 Example usage (with first NIST FIPS 197 test case): | 48 Example usage (with first NIST FIPS 197 test case): |
48 | 49 |
49 [sh]$ test/aes_calc 000102030405060708090a0b0c0d0e0f 00112233445566778899aabbccd
deeff -v | 50 [sh]$ test/aes_calc 000102030405060708090a0b0c0d0e0f 00112233445566778899aabbccd
deeff -v |
50 plaintext: 00112233445566778899aabbccddeeff | 51 plaintext: 00112233445566778899aabbccddeeff |
51 key: 000102030405060708090a0b0c0d0e0f | 52 key: 000102030405060708090a0b0c0d0e0f |
52 ciphertext: 69c4e0d86a7b0430d8cdb78070b4c55a | 53 ciphertext: 69c4e0d86a7b0430d8cdb78070b4c55a |
53 | 54 |
54 */ | 55 */ |
55 | 56 |
| 57 #ifdef HAVE_CONFIG_H |
| 58 #include <config.h> |
| 59 #endif |
| 60 |
56 #include "aes.h" | 61 #include "aes.h" |
57 #include <stdio.h> | 62 #include <stdio.h> |
58 #include <string.h> | 63 #include <string.h> |
59 | 64 |
60 void | 65 void |
61 usage(char *prog_name) { | 66 usage(char *prog_name) { |
62 printf("usage: %s <key> <plaintext> [-v]\n", prog_name); | 67 printf("usage: %s <key> <plaintext> [-v]\n", prog_name); |
63 exit(255); | 68 exit(255); |
64 } | 69 } |
65 | 70 |
66 #define AES_MAX_KEY_LEN 32 | 71 #define AES_MAX_KEY_LEN 32 |
67 | 72 |
68 int | 73 int |
69 main (int argc, char *argv[]) { | 74 main (int argc, char *argv[]) { |
70 v128_t data; | 75 v128_t data; |
71 uint8_t key[AES_MAX_KEY_LEN]; | 76 uint8_t key[AES_MAX_KEY_LEN]; |
72 aes_expanded_key_t exp_key; | 77 aes_expanded_key_t exp_key; |
73 int key_len, len; | 78 int key_len, len; |
74 int verbose; | 79 int verbose = 0; |
75 err_status_t status; | 80 err_status_t status; |
76 | 81 |
77 if (argc == 3) { | 82 if (argc == 3) { |
78 /* we're not in verbose mode */ | 83 /* we're not in verbose mode */ |
79 verbose = 0; | 84 verbose = 0; |
80 } else if (argc == 4) { | 85 } else if (argc == 4) { |
81 if (strncmp(argv[3], "-v", 2) == 0) { | 86 if (strncmp(argv[3], "-v", 2) == 0) { |
82 /* we're in verbose mode */ | 87 /* we're in verbose mode */ |
83 verbose = 1; | 88 verbose = 1; |
84 } else { | 89 } else { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 /* write ciphertext to output */ | 150 /* write ciphertext to output */ |
146 if (verbose) { | 151 if (verbose) { |
147 printf("key:\t\t%s\n", octet_string_hex_string(key, key_len)); | 152 printf("key:\t\t%s\n", octet_string_hex_string(key, key_len)); |
148 printf("ciphertext:\t"); | 153 printf("ciphertext:\t"); |
149 } | 154 } |
150 printf("%s\n", v128_hex_string(&data)); | 155 printf("%s\n", v128_hex_string(&data)); |
151 | 156 |
152 return 0; | 157 return 0; |
153 } | 158 } |
154 | 159 |
OLD | NEW |