Browse Source

add: crypto支持zero对齐等模式

Wendal Chen 3 years ago
parent
commit
bc86073687
1 changed files with 16 additions and 3 deletions
  1. 16 3
      application/src/luat_crypto_air105.c

+ 16 - 3
application/src/luat_crypto_air105.c

@@ -108,8 +108,7 @@ int l_crypto_cipher_xxx(lua_State *L, uint8_t flags) {
         LLOGE("mbedtls_cipher_setkey fail %ld", ret);
         LLOGE("mbedtls_cipher_setkey fail %ld", ret);
         goto _exit;
         goto _exit;
     }
     }
-    // TODO 设置padding mode
-    // mbedtls_cipher_set_padding_mode
+
     if (iv_size) {
     if (iv_size) {
         ret = mbedtls_cipher_set_iv(&ctx, iv, iv_size);
         ret = mbedtls_cipher_set_iv(&ctx, iv, iv_size);
         if (ret) {
         if (ret) {
@@ -120,7 +119,21 @@ int l_crypto_cipher_xxx(lua_State *L, uint8_t flags) {
 
 
     mbedtls_cipher_reset(&ctx);
     mbedtls_cipher_reset(&ctx);
 
 
-    //mbedtls_cipher_set_padding_mode(&ctx, MBEDTLS_PADDING_PKCS7);
+    if (!strcmp("PKCS7", pad)) {
+        mbedtls_cipher_set_padding_mode(&ctx, MBEDTLS_PADDING_PKCS7);
+    }
+    else if (!strcmp("ZERO", pad) || !strcmp("ZEROS", pad)) {
+        mbedtls_cipher_set_padding_mode(&ctx, MBEDTLS_PADDING_ZEROS);
+    }
+    else if (!strcmp("ONE_AND_ZEROS", pad)) {
+        mbedtls_cipher_set_padding_mode(&ctx, MBEDTLS_PADDING_ONE_AND_ZEROS);
+    }
+    else if (!strcmp("ZEROS_AND_LEN", pad)) {
+        mbedtls_cipher_set_padding_mode(&ctx, MBEDTLS_PADDING_ZEROS_AND_LEN);
+    }
+    else {
+        mbedtls_cipher_set_padding_mode(&ctx, MBEDTLS_PADDING_NONE);
+    }
 
 
     // 开始注入数据
     // 开始注入数据
     luaL_buffinit(L, &buff);
     luaL_buffinit(L, &buff);