[GitHub] [mynewt-core] kasjer commented on a change in pull request #2174: Updates to crypto_test app; STM32 crypto HW driver; CBC/CTR speed

2020-02-25 Thread GitBox
kasjer commented on a change in pull request #2174: Updates to crypto_test app; 
STM32 crypto HW driver; CBC/CTR speed
URL: https://github.com/apache/mynewt-core/pull/2174#discussion_r384192790
 
 

 ##
 File path: hw/drivers/crypto/src/crypto.c
 ##
 @@ -56,8 +61,20 @@ crypto_do_ctr(struct crypto_dev *crypto, const void *key, 
uint16_t keylen,
 return sz + rc;
 }
 
-for (i = 0; i < len; i++) {
-outbuf8[i] = inbuf8[i] ^ _out[i];
+/*
+ * For full blocks increase speed by doing 32-bit XOR; maintain the
+ * stream semantics doing byte XORs for smaller sizes (end of buffer).
+ */
+if (len == AES_BLOCK_LEN) {
+inbuf32 = (uint32_t *)inbuf8;
+outbuf32 = (uint32_t *)outbuf8;
+for (i = 0; i < len / 4; i++) {
+outbuf32[i] = inbuf32[i] ^ _out32[i];
 
 Review comment:
   I'm not sure what is the usage of this function but unaligned access here 
could crash Cortex-M0


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [mynewt-core] kasjer commented on a change in pull request #2174: Updates to crypto_test app; STM32 crypto HW driver; CBC/CTR speed

2020-02-25 Thread GitBox
kasjer commented on a change in pull request #2174: Updates to crypto_test app; 
STM32 crypto HW driver; CBC/CTR speed
URL: https://github.com/apache/mynewt-core/pull/2174#discussion_r384193747
 
 

 ##
 File path: apps/crypto_test/src/main.c
 ##
 @@ -282,6 +286,66 @@ run_benchmark(char *name, block_encrypt_func_t encfn, 
void *data, uint8_t iter)
 }
 printf("done in %lu ticks\n", os_time_get() - t);
 }
+
+static void
+run_cbc_bench(struct crypto_dev *crypto, uint8_t iter)
+{
+int i, j;
+uint8_t iv[AES_BLOCK_LEN];
+uint8_t output[AES_BLOCK_LEN];
+uint16_t blkidx;
+os_time_t t;
+
+printf("AES-128-CBC - running %d iterations of 4096 block encrypt... ", 
iter);
+t = os_time_get();
+for (i = 0; i < iter; i++) {
+memcpy(iv, aes_128_cbc_iv, AES_BLOCK_LEN);
+for (blkidx = 0; blkidx < 4096; blkidx += AES_BLOCK_LEN) {
+(void)crypto_encrypt_aes_cbc(crypto, aes_128_key, 128, iv,
+_128_input[blkidx], output, AES_BLOCK_LEN);
+if (memcmp(output, _128_cbc_expected[blkidx],
+AES_BLOCK_LEN)) {
+printf("fail... blkidx=%u\n", blkidx);
+for (j = 0; j < AES_BLOCK_LEN; j++) {
+printf("[%02x]<%02x> ", output[j],
+aes_128_cbc_expected[blkidx + j]);
+}
+return;
+}
+}
+}
+printf("done in %lu ticks\n", os_time_get() - t);
 
 Review comment:
   I would not use ticks to display time, you could not compare results of two 
different boards not knowing what tick mean on each one.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services