Use high-level APIs in tests

This commit is contained in:
Frank Denis
2014-09-13 13:56:41 -07:00
parent 21a5e5accb
commit 3b680e0a52
18 changed files with 26 additions and 26 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ unsigned char a[32];
int main(void)
{
int i;
crypto_auth_hmacsha512256(a,c,sizeof c - 1U,key);
crypto_auth(a,c,sizeof c - 1U,key);
for (i = 0;i < 32;++i) {
printf(",0x%02x",(unsigned int) a[i]);
if (i % 8 == 7) printf("\n");
+4 -4
View File
@@ -15,19 +15,19 @@ int main(void)
for (clen = 0;clen < 10000;++clen) {
randombytes(key,sizeof key);
randombytes(c,clen);
crypto_auth_hmacsha512256(a,c,clen,key);
if (crypto_auth_hmacsha512256_verify(a,c,clen,key) != 0) {
crypto_auth(a,c,clen,key);
if (crypto_auth_verify(a,c,clen,key) != 0) {
printf("fail %d\n",clen);
return 100;
}
if (clen > 0) {
c[rand() % clen] += 1 + (rand() % 255);
if (crypto_auth_hmacsha512256_verify(a,c,clen,key) == 0) {
if (crypto_auth_verify(a,c,clen,key) == 0) {
printf("forgery %d\n",clen);
return 100;
}
a[rand() % sizeof a] += 1 + (rand() % 255);
if (crypto_auth_hmacsha512256_verify(a,c,clen,key) == 0) {
if (crypto_auth_verify(a,c,clen,key) == 0) {
printf("forgery %d\n",clen);
return 100;
}
+1 -1
View File
@@ -53,7 +53,7 @@ unsigned char c[163];
int main(void)
{
int i;
crypto_box_curve25519xsalsa20poly1305(
crypto_box(
c,m,163,nonce,bobpk,alicesk
);
for (i = 16;i < 163;++i) {
+1 -1
View File
@@ -53,7 +53,7 @@ unsigned char m[163];
int main(void)
{
int i;
if (crypto_box_curve25519xsalsa20poly1305_open(
if (crypto_box_open(
m,c,163,nonce,alicepk,bobsk
) == 0) {
for (i = 32;i < 163;++i) {
+1 -1
View File
@@ -15,7 +15,7 @@ int main(void)
int i;
unsigned char sk[32];
unsigned char pk[32];
crypto_box_curve25519xsalsa20poly1305_seed_keypair(pk, sk, seed);
crypto_box_seed_keypair(pk, sk, seed);
for (i = 0;i < 32;++i) {
printf(",0x%02x",(unsigned int) pk[i]);
if (i % 8 == 7) printf("\n");
+3 -3
View File
@@ -4,13 +4,13 @@
#include "cmptest.h"
unsigned char x[] = "testing\n";
unsigned char h[crypto_hash_sha512_BYTES];
unsigned char h[crypto_hash_BYTES];
int main(void)
{
size_t i;
crypto_hash_sha512(h,x,sizeof x - 1U);
for (i = 0;i < crypto_hash_sha512_BYTES;++i) printf("%02x",(unsigned int) h[i]);
crypto_hash(h,x,sizeof x - 1U);
for (i = 0;i < crypto_hash_BYTES;++i) printf("%02x",(unsigned int) h[i]);
printf("\n");
return 0;
}
+1 -1
View File
@@ -35,7 +35,7 @@ unsigned char a[16];
int main(void)
{
int i;
crypto_onetimeauth_poly1305(a,c,131,rs);
crypto_onetimeauth(a,c,131,rs);
for (i = 0;i < 16;++i) {
printf(",0x%02x",(unsigned int) a[i]);
if (i % 8 == 7) printf("\n");
+1 -1
View File
@@ -37,6 +37,6 @@ unsigned char a[16] = {
int main(void)
{
printf("%d\n",crypto_onetimeauth_poly1305_verify(a,c,131,rs));
printf("%d\n",crypto_onetimeauth_verify(a,c,131,rs));
return 0;
}
+4 -4
View File
@@ -15,19 +15,19 @@ int main(void)
for (clen = 0;clen < 10000;++clen) {
randombytes(key,sizeof key);
randombytes(c,clen);
crypto_onetimeauth_poly1305(a,c,clen,key);
if (crypto_onetimeauth_poly1305_verify(a,c,clen,key) != 0) {
crypto_onetimeauth(a,c,clen,key);
if (crypto_onetimeauth_verify(a,c,clen,key) != 0) {
printf("fail %d\n",clen);
return 100;
}
if (clen > 0) {
c[rand() % clen] += 1 + (rand() % 255);
if (crypto_onetimeauth_poly1305_verify(a,c,clen,key) == 0) {
if (crypto_onetimeauth_verify(a,c,clen,key) == 0) {
printf("forgery %d\n",clen);
return 100;
}
a[rand() % sizeof a] += 1 + (rand() % 255);
if (crypto_onetimeauth_poly1305_verify(a,c,clen,key) == 0) {
if (crypto_onetimeauth_verify(a,c,clen,key) == 0) {
printf("forgery %d\n",clen);
return 100;
}
+1 -1
View File
@@ -15,7 +15,7 @@ unsigned char alicepk[32];
int main(void)
{
int i;
crypto_scalarmult_curve25519_base(alicepk,alicesk);
crypto_scalarmult_base(alicepk,alicesk);
for (i = 0;i < 32;++i) {
if (i > 0) printf(","); else printf(" ");
printf("0x%02x",(unsigned int) alicepk[i]);
+1 -1
View File
@@ -15,7 +15,7 @@ unsigned char bobpk[32];
int main(void)
{
int i;
crypto_scalarmult_curve25519_base(bobpk,bobsk);
crypto_scalarmult_base(bobpk,bobsk);
for (i = 0;i < 32;++i) {
if (i > 0) printf(","); else printf(" ");
printf("0x%02x",(unsigned int) bobpk[i]);
+1 -1
View File
@@ -22,7 +22,7 @@ unsigned char k[32];
int main(void)
{
int i;
crypto_scalarmult_curve25519(k,alicesk,bobpk);
crypto_scalarmult(k,alicesk,bobpk);
for (i = 0;i < 32;++i) {
if (i > 0) printf(","); else printf(" ");
printf("0x%02x",(unsigned int) k[i]);
+1 -1
View File
@@ -22,7 +22,7 @@ unsigned char k[32];
int main(void)
{
int i;
crypto_scalarmult_curve25519(k,bobsk,alicepk);
crypto_scalarmult(k,bobsk,alicepk);
for (i = 0;i < 32;++i) {
if (i > 0) printf(","); else printf(" ");
printf("0x%02x",(unsigned int) k[i]);
+1 -1
View File
@@ -46,7 +46,7 @@ unsigned char c[163];
int main(void)
{
int i;
crypto_secretbox_xsalsa20poly1305(
crypto_secretbox(
c,m,163,nonce,firstkey
);
for (i = 16;i < 163;++i) {
+1 -1
View File
@@ -46,7 +46,7 @@ unsigned char m[163];
int main(void)
{
int i;
if (crypto_secretbox_xsalsa20poly1305_open(
if (crypto_secretbox_open(
m,c,163,nonce,firstkey
) == 0) {
for (i = 32;i < 163;++i) {
+1 -1
View File
@@ -23,7 +23,7 @@ unsigned char h[32];
int main(void)
{
int i;
crypto_stream_xsalsa20(output,4194304,nonce,firstkey);
crypto_stream(output,4194304,nonce,firstkey);
crypto_hash_sha256(h,output,sizeof output);
for (i = 0;i < 32;++i) printf("%02x",h[i]); printf("\n");
return 0;
+1 -1
View File
@@ -21,7 +21,7 @@ unsigned char rs[32];
int main(void)
{
int i;
crypto_stream_xsalsa20(rs,32,nonce,firstkey);
crypto_stream(rs,32,nonce,firstkey);
for (i = 0;i < 32;++i) {
printf(",0x%02x",(unsigned int) rs[i]);
if (i % 8 == 7) printf("\n");
+1 -1
View File
@@ -45,7 +45,7 @@ unsigned char c[163];
int main(void)
{
int i;
crypto_stream_xsalsa20_xor(c,m,163,nonce,firstkey);
crypto_stream_xor(c,m,163,nonce,firstkey);
for (i = 32;i < 163;++i) {
printf(",0x%02x",(unsigned int) c[i]);
if (i % 8 == 7) printf("\n");