mkiiskila commented on a change in pull request #1649: [WIP] [RFC] Add initial 
crypto driver framework
URL: https://github.com/apache/mynewt-core/pull/1649#discussion_r258386655
 
 

 ##########
 File path: hw/drivers/crypto/crypto_stm32/src/crypto_stm32.c
 ##########
 @@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <string.h>
+#include "mcu/cmsis_nvic.h"
+#include <os/mynewt.h>
+#include "mcu/stm32_hal.h"
+#include "crypto/crypto.h"
+#include "crypto_stm32/crypto_stm32.h"
+
+/* TODO: make this re-entrant */
+static struct os_eventq isr_evtq;
+static CRYP_HandleTypeDef g_hcryp;
+
+static void
+stm32_cryp_irq_handler(void)
+{
+    struct os_event evt;
+
+    HAL_CRYP_IRQHandler(&g_hcryp);
+
+    evt.ev_queued = 0;
+    evt.ev_arg = NULL;
+    (void)os_eventq_put(&isr_evtq, &evt);
+}
+
+static int
+stm32_crypto_encrypt_ecb(uint8_t algo, const uint8_t *key, uint8_t keylen,
+        const uint8_t *inbuf, uint8_t *outbuf, size_t len)
+{
+    int rc;
+
+    switch (algo) {
+    case CRYPTO_ALGO_AES_128_ECB:
+        g_hcryp.Init.KeySize = CRYP_KEYSIZE_128B;
+        break;
+#if 0
+    case CRYPTO_ALGO_AES_192_ECB:
+        g_hcryp.Init.KeySize = CRYP_KEYSIZE_192B;
+        break;
+    case CRYPTO_ALGO_AES_256_ECB:
+        g_hcryp.Init.KeySize = CRYP_KEYSIZE_256B;
+        break;
+#endif
+    default:
+        return -1;
+    }
+
+    g_hcryp.Init.pKey = (uint8_t *)key;
+    assert(HAL_CRYP_Init(&g_hcryp) == HAL_OK);
 
 Review comment:
   This will call HAL_CRYP_Init() only if assert() is compiled in. Should have 
the assert() on a separate line.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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

Reply via email to