/*-1* Copyright (c) 2003 Poul-Henning Kamp2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*25* This test checks for inplace decryption working. This is the case26* where the same buffer is passed as input and output to27* rijndael_blockDecrypt().28*/2930#include <stdio.h>31#include <sys/param.h>32#include <sys/types.h>3334#include <crypto/rijndael/rijndael-api-fst.h>3536#define LL 3237int38main(int argc, char **argv)39{40keyInstance ki;41cipherInstance ci;42uint8_t key[16];43uint8_t in[LL];44uint8_t out[LL];45int i, j;4647rijndael_cipherInit(&ci, MODE_CBC, NULL);48for (i = 0; i < 16; i++)49key[i] = i;50rijndael_makeKey(&ki, DIR_DECRYPT, 128, key);51for (i = 0; i < LL; i++)52in[i] = i;53rijndael_blockDecrypt(&ci, &ki, in, LL * 8, out);54for (i = 0; i < LL; i++)55printf("%02x", out[i]);56putchar('\n');57rijndael_blockDecrypt(&ci, &ki, in, LL * 8, in);58j = 0;59for (i = 0; i < LL; i++) {60printf("%02x", in[i]);61if (in[i] != out[i])62j++;63}64putchar('\n');65if (j != 0) {66fprintf(stderr,67"Error: inplace decryption fails in %d places\n", j);68return (1);69} else {70return (0);71}72}737475