2 * Copyright (c) 2009, 2010 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 hex_to_uint8(const char *input, uint8_t *output, size_t n)
27 if (strlen(input) != n * 2) {
30 for (i = 0; i < n; i++) {
33 output[i] = hexits_value(&input[i * 2], 2, &ok);
41 ovs_fatal(0, "\"%s\" is not exactly %zu hex digits", input, n * 2);
45 main(int argc, char *argv[])
48 uint8_t plaintext[16];
49 uint8_t ciphertext[16];
54 ovs_fatal(0, "usage: %s KEY PLAINTEXT, where KEY and PLAINTEXT each "
55 "consist of 32 hex digits", argv[0]);
58 hex_to_uint8(argv[1], key, 16);
59 hex_to_uint8(argv[2], plaintext, 16);
61 aes128_schedule(&aes, key);
62 aes128_encrypt(&aes, plaintext, ciphertext);
63 for (i = 0; i < 16; i++) {
64 printf("%02x", ciphertext[i]);