You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2020/06/23 14:06:49 UTC

[GitHub] [mynewt-core] nkaje commented on a change in pull request #2294: mbedtls_aes_alt: add setkey for decyption, validate input, fix data type and return type

nkaje commented on a change in pull request #2294:
URL: https://github.com/apache/mynewt-core/pull/2294#discussion_r444251350



##########
File path: hw/drivers/crypto/src/mbedtls_aes_alt.c
##########
@@ -53,15 +54,59 @@ mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
         return 0;
     }
 
-    return -1;
+    return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH;
+}
+
+int
+mbedtls_aes_validate_input(mbedtls_aes_context *ctx, const unsigned char *key,
+                           unsigned int keybits)
+{
+    assert(ctx);
+
+    if (key == NULL) {
+        return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH;
+    }
+
+    return 0;
+}
+
+int
+mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
+                       unsigned int keybits)
+{
+    int ret = mbedtls_aes_validate_input(ctx, key, keybits);
+
+    if (ret != 0) {
+        return ret;
+    }
+
+    return mbedtls_aes_setkey(ctx, key, keybits);
+}
+
+int
+mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
+                       unsigned int keybits)
+{
+    int ret = mbedtls_aes_validate_input(ctx, key, keybits);
+
+    if (ret != 0) {
+        return ret;
+    }
+
+    return mbedtls_aes_setkey(ctx, key, keybits);
 }
 
 int
 mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx, int mode,
-        const unsigned char input[16], unsigned char output[16])
+                      const unsigned char input[16], unsigned char output[16])
 {
-    return crypto_encrypt_aes_ecb(ctx->crypto, ctx->key, ctx->keylen,
-            (const uint8_t *)input, (uint8_t *)output, AES_BLOCK_LEN);
+    int ret = crypto_encrypt_aes_ecb(ctx->crypto, ctx->key, ctx->keylen,
+                                     (const uint8_t *)input, (uint8_t *)output, AES_BLOCK_LEN);
+    if (ret == AES_BLOCK_LEN) {

Review comment:
       done

##########
File path: hw/drivers/crypto/src/mbedtls_aes_alt.c
##########
@@ -53,15 +54,59 @@ mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
         return 0;
     }
 
-    return -1;
+    return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH;
+}
+
+int

Review comment:
       done




----------------------------------------------------------------
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:
users@infra.apache.org