Commit 7d8e19a5 authored by James Almer's avatar James Almer

avutil: make crypto testprogs include headers only

Reviewed-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
Signed-off-by: 's avatarJames Almer <jamrial@gmail.com>
parent f6931845
......@@ -16,18 +16,17 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "aes.c"
// LCOV_EXCL_START
#include <string.h>
#include "aes.h"
#include "lfg.h"
#include "log.h"
int main(int argc, char **argv)
{
int i, j;
AVAES b;
struct AVAES *b;
uint8_t rkey[2][16] = {
{ 0 },
{ 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3,
......@@ -48,11 +47,15 @@ int main(int argc, char **argv)
uint8_t iv[2][16];
int err = 0;
b = av_aes_alloc();
if (!b)
return 1;
av_log_set_level(AV_LOG_DEBUG);
for (i = 0; i < 2; i++) {
av_aes_init(&b, rkey[i], 128, 1);
av_aes_crypt(&b, temp, rct[i], 1, NULL, 1);
av_aes_init(b, rkey[i], 128, 1);
av_aes_crypt(b, temp, rct[i], 1, NULL, 1);
for (j = 0; j < 16; j++) {
if (rpt[i][j] != temp[j]) {
av_log(NULL, AV_LOG_ERROR, "%d %02X %02X\n",
......@@ -63,11 +66,20 @@ int main(int argc, char **argv)
}
if (argc > 1 && !strcmp(argv[1], "-t")) {
AVAES ae, ad;
struct AVAES *ae, *ad;
AVLFG prng;
av_aes_init(&ae, (const uint8_t*)"PI=3.141592654..", 128, 0);
av_aes_init(&ad, (const uint8_t*)"PI=3.141592654..", 128, 1);
ae = av_aes_alloc();
ad = av_aes_alloc();
if (!ae || !ad) {
av_free(ae);
av_free(ad);
return 1;
}
av_aes_init(ae, (const uint8_t*)"PI=3.141592654..", 128, 0);
av_aes_init(ad, (const uint8_t*)"PI=3.141592654..", 128, 1);
av_lfg_init(&prng, 1);
for (i = 0; i < 10000; i++) {
......@@ -77,16 +89,16 @@ int main(int argc, char **argv)
iv[0][j] = iv[1][j] = av_lfg_get(&prng);
{
START_TIMER;
av_aes_crypt(&ae, temp, pt, 2, iv[0], 0);
av_aes_crypt(ae, temp, pt, 2, iv[0], 0);
if (!(i & (i - 1)))
av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n",
temp[0], temp[5], temp[10], temp[15]);
av_aes_crypt(&ad, temp, temp, 2, iv[1], 1);
av_aes_crypt(&ae, temp, pt, 2, NULL, 0);
av_aes_crypt(ad, temp, temp, 2, iv[1], 1);
av_aes_crypt(ae, temp, pt, 2, NULL, 0);
if (!(i & (i - 1)))
av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n",
temp[0], temp[5], temp[10], temp[15]);
av_aes_crypt(&ad, temp, temp, 2, NULL, 1);
av_aes_crypt(ad, temp, temp, 2, NULL, 1);
STOP_TIMER("aes");
}
for (j = 0; j < 16; j++) {
......
......@@ -19,12 +19,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "camellia.c"
#include "camellia.h"
#include "log.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
const uint8_t Key[3][32] = {
......@@ -41,7 +38,7 @@ int main(int argc, char *argv[])
const int kbits[3] = {128, 192, 256};
int i, j, err = 0;
uint8_t temp[32], iv[16];
AVCAMELLIA *cs;
struct AVCAMELLIA *cs;
cs = av_camellia_alloc();
if (!cs)
return 1;
......
......@@ -19,12 +19,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "cast5.c"
#include "cast5.h"
#include "log.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
......@@ -48,7 +45,7 @@ int main(int argc, char** argv)
int i, j, err = 0;
static const int key_bits[3] = {128, 80, 40};
uint8_t temp[8];
AVCAST5 *cs;
struct AVCAST5 *cs;
cs = av_cast5_alloc();
if (!cs)
return 1;
......
......@@ -18,7 +18,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "hash.c"
#include <stdio.h>
#include <string.h>
#include "hash.h"
#define SRC_BUF_SIZE 64
#define DST_BUF_SIZE (AV_HASH_MAX_SIZE * 8)
......@@ -26,10 +29,14 @@
int main(void)
{
struct AVHashContext *ctx = NULL;
int i, j;
int i, j, numhashes = 0;
static const uint8_t src[SRC_BUF_SIZE] = { 0 };
uint8_t dst[DST_BUF_SIZE];
for (i = 0; i < NUM_HASHES; i++) {
while (av_hash_names(numhashes))
numhashes++;
for (i = 0; i < numhashes; i++) {
if (av_hash_alloc(&ctx, av_hash_names(i)) < 0)
return 1;
......
......@@ -18,13 +18,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "murmur3.c"
#include "intreadwrite.h"
#include "mem.h"
#include "murmur3.h"
int main(void)
{
int i;
uint8_t hash_result[16] = {0};
AVMurMur3 *ctx = av_murmur3_alloc();
struct AVMurMur3 *ctx = av_murmur3_alloc();
#if 1
uint8_t in[256] = {0};
uint8_t *hashes = av_mallocz(256 * 16);
......
......@@ -19,29 +19,33 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "ripemd.c"
#include <stdio.h>
#include "ripemd.h"
int main(void)
{
int i, j, k;
AVRIPEMD ctx;
struct AVRIPEMD *ctx;
unsigned char digest[40];
static const int lengths[4] = { 128, 160, 256, 320 };
ctx = av_ripemd_alloc();
if (!ctx)
return 1;
for (j = 0; j < 4; j++) {
printf("Testing RIPEMD-%d\n", lengths[j]);
for (k = 0; k < 3; k++) {
av_ripemd_init(&ctx, lengths[j]);
av_ripemd_init(ctx, lengths[j]);
if (k == 0)
av_ripemd_update(&ctx, "abc", 3);
av_ripemd_update(ctx, "abc", 3);
else if (k == 1)
av_ripemd_update(&ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
av_ripemd_update(ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
else
for (i = 0; i < 1000*1000; i++)
av_ripemd_update(&ctx, "a", 1);
av_ripemd_final(&ctx, digest);
av_ripemd_update(ctx, "a", 1);
av_ripemd_final(ctx, digest);
for (i = 0; i < lengths[j] >> 3; i++)
printf("%02X", digest[i]);
putchar('\n');
......
......@@ -16,29 +16,33 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "sha.c"
#include <stdio.h>
#include "sha.h"
int main(void)
{
int i, j, k;
AVSHA ctx;
struct AVSHA *ctx;
unsigned char digest[32];
static const int lengths[3] = { 160, 224, 256 };
ctx = av_sha_alloc();
if (!ctx)
return 1;
for (j = 0; j < 3; j++) {
printf("Testing SHA-%d\n", lengths[j]);
for (k = 0; k < 3; k++) {
av_sha_init(&ctx, lengths[j]);
av_sha_init(ctx, lengths[j]);
if (k == 0)
av_sha_update(&ctx, "abc", 3);
av_sha_update(ctx, "abc", 3);
else if (k == 1)
av_sha_update(&ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
av_sha_update(ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
else
for (i = 0; i < 1000*1000; i++)
av_sha_update(&ctx, "a", 1);
av_sha_final(&ctx, digest);
av_sha_update(ctx, "a", 1);
av_sha_final(ctx, digest);
for (i = 0; i < lengths[j] >> 3; i++)
printf("%02X", digest[i]);
putchar('\n');
......
......@@ -21,31 +21,35 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "sha512.c"
#include <stdio.h>
#include "sha512.h"
int main(void)
{
int i, j, k;
AVSHA512 ctx;
struct AVSHA512 *ctx;
unsigned char digest[64];
static const int lengths[4] = { 224, 256, 384, 512 };
ctx = av_sha512_alloc();
if (!ctx)
return 1;
for (j = 0; j < 4; j++) {
if (j < 2) printf("Testing SHA-512/%d\n", lengths[j]);
else printf("Testing SHA-%d\n", lengths[j]);
for (k = 0; k < 3; k++) {
av_sha512_init(&ctx, lengths[j]);
av_sha512_init(ctx, lengths[j]);
if (k == 0)
av_sha512_update(&ctx, "abc", 3);
av_sha512_update(ctx, "abc", 3);
else if (k == 1)
av_sha512_update(&ctx, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
av_sha512_update(ctx, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", 112);
else
for (i = 0; i < 1000*1000; i++)
av_sha512_update(&ctx, "a", 1);
av_sha512_final(&ctx, digest);
av_sha512_update(ctx, "a", 1);
av_sha512_final(ctx, digest);
for (i = 0; i < lengths[j] >> 3; i++)
printf("%02X", digest[i]);
putchar('\n');
......
......@@ -22,10 +22,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "tea.c"
#include <stdio.h>
#include "common.h"
#include "tea.h"
#define TEA_NUM_TESTS 4
// https://github.com/logandrews/TeaCrypt/blob/master/tea/tea_test.go
......@@ -58,7 +59,7 @@ static const uint8_t tea_test_ct[TEA_NUM_TESTS][8] = {
{ 0x12, 0x6C, 0x6B, 0x92, 0xC0, 0x65, 0x3A, 0x3E }
};
static void test_tea(AVTEA *ctx, uint8_t *dst, const uint8_t *src,
static void test_tea(struct AVTEA *ctx, uint8_t *dst, const uint8_t *src,
const uint8_t *ref, int len, uint8_t *iv, int dir,
const char *test)
{
......@@ -78,7 +79,7 @@ static void test_tea(AVTEA *ctx, uint8_t *dst, const uint8_t *src,
int main(void)
{
AVTEA *ctx;
struct AVTEA *ctx;
uint8_t buf[8], iv[8];
int i;
static const uint8_t src[32] = "HelloWorldHelloWorldHelloWorld";
......
......@@ -19,8 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "twofish.c"
#include "log.h"
#include "twofish.h"
#include <stdio.h>
#include <stdlib.h>
......@@ -40,7 +40,7 @@ int main(int argc, char *argv[])
uint8_t temp[32], iv[16], rpt[32] = {0};
const int kbits[3] = {128, 192, 256};
int i, j, err = 0;
AVTWOFISH *cs;
struct AVTWOFISH *cs;
cs = av_twofish_alloc();
if (!cs)
return 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment