From 10a3f8ead30376ab6056e38621a758696af4cd48 Mon Sep 17 00:00:00 2001 From: toddouska Date: Wed, 20 Nov 2013 15:12:33 -0800 Subject: [PATCH 1/3] make cert names more consistent with str type that openssl uses --- ctaocrypt/src/asn.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ctaocrypt/src/asn.c b/ctaocrypt/src/asn.c index ce5ccc988..13c3a1850 100644 --- a/ctaocrypt/src/asn.c +++ b/ctaocrypt/src/asn.c @@ -4266,12 +4266,16 @@ static int SetName(byte* output, CertName* name) } else { /* joint id */ + byte bType = GetNameId(i); names[i].encoded[idx++] = 0x55; names[i].encoded[idx++] = 0x04; /* id type */ - names[i].encoded[idx++] = GetNameId(i); + names[i].encoded[idx++] = bType; /* str type */ - names[i].encoded[idx++] = 0x13; + if (bType == ASN_COUNTRY_NAME) + names[i].encoded[idx++] = 0x13; /* printable */ + else + names[i].encoded[idx++] = 0x0c; /* utf8 */ } /* second length */ XMEMCPY(names[i].encoded + idx, secondLen, secondSz); From 2f7970ab6551b5de5d46b4bf2859230d1daa8e6f Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Wed, 20 Nov 2013 17:03:58 -0700 Subject: [PATCH 2/3] add FREERTOS current_time() to benchmark.c --- ctaocrypt/benchmark/benchmark.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ctaocrypt/benchmark/benchmark.c b/ctaocrypt/benchmark/benchmark.c index f1264a7c7..64e85327e 100644 --- a/ctaocrypt/benchmark/benchmark.c +++ b/ctaocrypt/benchmark/benchmark.c @@ -1087,7 +1087,22 @@ void bench_eccKeyAgree(void) } #elif defined CYASSL_MDK_ARM + extern double current_time(int reset) ; + +#elif defined FREERTOS + + double current_time(int reset) + { + (void) reset; + + portTickType tickCount; + + /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */ + tickCount = xTaskGetTickCount(); + return (double)tickCount / 1000; + } + #else #include From 8bf18d31c9fdbae605a6d272d784e89b9206e3f7 Mon Sep 17 00:00:00 2001 From: toddouska Date: Wed, 20 Nov 2013 17:03:19 -0800 Subject: [PATCH 3/3] fix smartos warnings --- ctaocrypt/benchmark/benchmark.c | 28 ++++++++++++++-------------- ctaocrypt/src/asn.c | 8 +++++--- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/ctaocrypt/benchmark/benchmark.c b/ctaocrypt/benchmark/benchmark.c index f1264a7c7..e941671e0 100644 --- a/ctaocrypt/benchmark/benchmark.c +++ b/ctaocrypt/benchmark/benchmark.c @@ -221,13 +221,13 @@ int benchmark_test(void *args) #ifdef BENCH_EMBEDDED const int numBlocks = 25; /* how many kB/megs to test (en/de)cryption */ const char blockType[] = "kB"; /* used in printf output */ -const int times = 1; /* public key iterations */ +const int ntimes = 1; /* public key iterations */ const int genTimes = 5; const int agreeTimes = 5; #else const int numBlocks = 5; const char blockType[] = "megs"; -const int times = 100; +const int ntimes = 100; const int genTimes = 100; const int agreeTimes = 100; #endif @@ -742,15 +742,15 @@ void bench_rsa(void) start = current_time(1); - for (i = 0; i < times; i++) + for (i = 0; i < ntimes; i++) ret = RsaPublicEncrypt(message,len,enc,sizeof(enc), &rsaKey, &rng); total = current_time(0) - start; - each = total / times; /* per second */ + each = total / ntimes; /* per second */ milliEach = each * 1000; /* milliseconds */ printf("RSA %d encryption took %6.2f milliseconds, avg over %d" - " iterations\n", rsaKeySz, milliEach, times); + " iterations\n", rsaKeySz, milliEach, ntimes); if (ret < 0) { printf("Rsa Public Encrypt failed\n"); @@ -759,17 +759,17 @@ void bench_rsa(void) start = current_time(1); - for (i = 0; i < times; i++) { + for (i = 0; i < ntimes; i++) { byte out[512]; /* for up to 4096 bit */ RsaPrivateDecrypt(enc, (word32)ret, out, sizeof(out), &rsaKey); } total = current_time(0) - start; - each = total / times; /* per second */ + each = total / ntimes; /* per second */ milliEach = each * 1000; /* milliseconds */ printf("RSA %d decryption took %6.2f milliseconds, avg over %d" - " iterations\n", rsaKeySz, milliEach, times); + " iterations\n", rsaKeySz, milliEach, ntimes); FreeRsaKey(&rsaKey); #ifdef HAVE_CAVIUM @@ -847,28 +847,28 @@ void bench_dh(void) start = current_time(1); - for (i = 0; i < times; i++) + for (i = 0; i < ntimes; i++) DhGenerateKeyPair(&dhKey, &rng, priv, &privSz, pub, &pubSz); total = current_time(0) - start; - each = total / times; /* per second */ + each = total / ntimes; /* per second */ milliEach = each * 1000; /* milliseconds */ printf("DH %d key generation %6.2f milliseconds, avg over %d" - " iterations\n", dhKeySz, milliEach, times); + " iterations\n", dhKeySz, milliEach, ntimes); DhGenerateKeyPair(&dhKey, &rng, priv2, &privSz2, pub2, &pubSz2); start = current_time(1); - for (i = 0; i < times; i++) + for (i = 0; i < ntimes; i++) DhAgree(&dhKey, agree, &agreeSz, priv, privSz, pub2, pubSz2); total = current_time(0) - start; - each = total / times; /* per second */ + each = total / ntimes; /* per second */ milliEach = each * 1000; /* milliseconds */ printf("DH %d key agreement %6.2f milliseconds, avg over %d" - " iterations\n", dhKeySz, milliEach, times); + " iterations\n", dhKeySz, milliEach, ntimes); #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) fclose(file); diff --git a/ctaocrypt/src/asn.c b/ctaocrypt/src/asn.c index 3cd2e33dc..f19ce79b0 100644 --- a/ctaocrypt/src/asn.c +++ b/ctaocrypt/src/asn.c @@ -3226,6 +3226,8 @@ static void DecodeCertExtensions(DecodedCert* cert) word32 oid; byte critical; + (void)critical; + CYASSL_ENTER("DecodeCertExtensions"); if (input == NULL || sz == 0) return; @@ -4601,7 +4603,7 @@ int MakeNtruCert(Cert* cert, byte* derBuffer, word32 derSz, #endif /* HAVE_NTRU */ -int SignCert(int requestSz, int sigType, byte* buffer, word32 buffSz, +int SignCert(int requestSz, int sType, byte* buffer, word32 buffSz, RsaKey* rsaKey, ecc_key* eccKey, RNG* rng) { byte sig[MAX_ENCODED_SIG_SZ]; @@ -4611,14 +4613,14 @@ int SignCert(int requestSz, int sigType, byte* buffer, word32 buffSz, return requestSz; sigSz = MakeSignature(buffer, requestSz, sig, sizeof(sig), rsaKey, eccKey, - rng, sigType); + rng, sType); if (sigSz < 0) return sigSz; if (requestSz + MAX_SEQ_SZ * 2 + sigSz > (int)buffSz) return BUFFER_E; - return AddSignature(buffer, requestSz, sig, sigSz, sigType); + return AddSignature(buffer, requestSz, sig, sigSz, sType); }