From: couturier Date: Tue, 21 Jun 2022 09:39:45 +0000 (+0200) Subject: new X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/commitdiff_plain/fd03c6c18761aedcf1616b4dadc316fbb07ebde3?ds=sidebyside new --- diff --git a/other_ciphers/grain-128aead/Implementations/crypto_aead/grain128aead/opt32/raph.c b/other_ciphers/grain-128aead/Implementations/crypto_aead/grain128aead/opt32/raph.c new file mode 100644 index 0000000..94dd741 --- /dev/null +++ b/other_ciphers/grain-128aead/Implementations/crypto_aead/grain128aead/opt32/raph.c @@ -0,0 +1,188 @@ + +// disable deprecation for sprintf and fopen +#ifdef _MSC_VER +#define _CRT_SECURE_NO_WARNINGS +#endif + +#include +#include +#include +#include +#include +#include +#include +#include "grain128aead_32p.h" + +#define KAT_SUCCESS 0 +#define KAT_FILE_OPEN_ERROR -1 +#define KAT_DATA_ERROR -3 +#define KAT_CRYPTO_FAILURE -4 + +//#define MAX_MESSAGE_LENGTH 512*512 +#define MAX_ASSOCIATED_DATA_LENGTH 32 + + +double TimeStart() +{ + struct timeval tstart; + gettimeofday(&tstart,0); + return( (double) (tstart.tv_sec + tstart.tv_usec*1e-6) ); +} + +double TimeStop(double t) +{ + struct timeval tend; + + gettimeofday(&tend,0); + t = (double) (tend.tv_sec + tend.tv_usec*1e-6) - t; + return (t); +} + + + +int crypto_aead_encrypt( + unsigned char *c, unsigned long long *clen, + const unsigned char *m, unsigned long long mlen, + const unsigned char *ad, unsigned long long adlen, + const unsigned char *nsec, + const unsigned char *npub, + const unsigned char *k); +int crypto_aead_decrypt( + unsigned char *m, unsigned long long *mlen, + unsigned char *nsec, + const unsigned char *c, unsigned long long clen, + const unsigned char *ad, unsigned long long adlen, + const unsigned char *npub, + const unsigned char *k); + + +void init_buffer(unsigned char *buffer, unsigned long long numbytes); + +void print_bstr(const char *label, const unsigned char *data, unsigned long long length); + +int generate_test_vectors(); + +int main(int argc, char** argv) +{ + + int size_buf=1; + int nb_test=1; + + + for(int i=1; i\n", func_ret); + ret_val = KAT_CRYPTO_FAILURE; + }*/ + + //print_bstr("CT = ", ct, clen); + + // printf("\n"); + + + double time_decrypt=0; + t=TimeStart(); + + for(int i=0;i\n", func_ret); + ret_val = KAT_CRYPTO_FAILURE; + + } + */ + if (mlen != mlen2) { + printf("crypto_aead_decrypt returned bad 'mlen': Got <%llu>, expected <%llu>\n", mlen2, mlen); + ret_val = KAT_CRYPTO_FAILURE; + } + + if (memcmp(msg, msg2, mlen)) { + printf("crypto_aead_decrypt did not recover the plaintext\n"); + ret_val = KAT_CRYPTO_FAILURE; + } + + // print_bstr("MSG = ", msg, mlen); + // print_bstr("MSG2 = ", msg2, mlen); + + return ret_val; +} + + +void print_bstr(const char *label, const unsigned char *data, unsigned long long length) +{ + printf( "%s", label); + + for (unsigned long long i = 0; i < length; i++) + printf("%02X", data[i]); + + printf("\n"); +} + +void init_buffer(unsigned char *buffer, unsigned long long numbytes) +{ + for (unsigned long long i = 0; i < numbytes; i++) + buffer[i] = (unsigned char)i; +}