[njs] WebCrypto: sorted njs_webcrypto_alg accoding to njs_webcrypto_alg_t.

Dmitry Volyntsev xeioex at nginx.com
Wed May 24 04:21:25 UTC 2023


details:   https://hg.nginx.org/njs/rev/510d8ebedfba
branches:  
changeset: 2130:510d8ebedfba
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon May 22 22:48:58 2023 -0700
description:
WebCrypto: sorted njs_webcrypto_alg accoding to njs_webcrypto_alg_t.

So njs_webcrypto_alg[alg->type] can be used to get the algorithm name.

diffstat:

 external/njs_webcrypto_module.c |  68 +++++++++++++++++++++-------------------
 1 files changed, 35 insertions(+), 33 deletions(-)

diffs (120 lines):

diff -r 08a912ab9520 -r 510d8ebedfba external/njs_webcrypto_module.c
--- a/external/njs_webcrypto_module.c	Mon May 22 17:59:47 2023 -0700
+++ b/external/njs_webcrypto_module.c	Mon May 22 22:48:58 2023 -0700
@@ -45,6 +45,7 @@ typedef enum {
     NJS_ALGORITHM_ECDH,
     NJS_ALGORITHM_PBKDF2,
     NJS_ALGORITHM_HKDF,
+    NJS_ALGORITHM_MAX,
 } njs_webcrypto_alg_t;
 
 
@@ -54,6 +55,7 @@ typedef enum {
     NJS_HASH_SHA256,
     NJS_HASH_SHA384,
     NJS_HASH_SHA512,
+    NJS_HASH_MAX,
 } njs_webcrypto_hash_t;
 
 
@@ -153,6 +155,28 @@ static njs_webcrypto_entry_t njs_webcryp
     (uintptr_t) & (njs_webcrypto_algorithm_t) { type, usage_mask, fmt_mask }
 
     {
+      njs_str("RSASSA-PKCS1-v1_5"),
+      njs_webcrypto_algorithm(NJS_ALGORITHM_RSASSA_PKCS1_v1_5,
+                              NJS_KEY_USAGE_SIGN |
+                              NJS_KEY_USAGE_VERIFY |
+                              NJS_KEY_USAGE_GENERATE_KEY,
+                              NJS_KEY_FORMAT_PKCS8 |
+                              NJS_KEY_FORMAT_SPKI |
+                              NJS_KEY_FORMAT_JWK)
+    },
+
+    {
+      njs_str("RSA-PSS"),
+      njs_webcrypto_algorithm(NJS_ALGORITHM_RSA_PSS,
+                              NJS_KEY_USAGE_SIGN |
+                              NJS_KEY_USAGE_VERIFY |
+                              NJS_KEY_USAGE_GENERATE_KEY,
+                              NJS_KEY_FORMAT_PKCS8 |
+                              NJS_KEY_FORMAT_SPKI |
+                              NJS_KEY_FORMAT_JWK)
+    },
+
+    {
       njs_str("RSA-OAEP"),
       njs_webcrypto_algorithm(NJS_ALGORITHM_RSA_OAEP,
                               NJS_KEY_USAGE_ENCRYPT |
@@ -166,6 +190,16 @@ static njs_webcrypto_entry_t njs_webcryp
     },
 
     {
+      njs_str("HMAC"),
+      njs_webcrypto_algorithm(NJS_ALGORITHM_HMAC,
+                              NJS_KEY_USAGE_GENERATE_KEY |
+                              NJS_KEY_USAGE_SIGN |
+                              NJS_KEY_USAGE_VERIFY,
+                              NJS_KEY_FORMAT_RAW |
+                              NJS_KEY_FORMAT_JWK)
+    },
+
+    {
       njs_str("AES-GCM"),
       njs_webcrypto_algorithm(NJS_ALGORITHM_AES_GCM,
                               NJS_KEY_USAGE_ENCRYPT |
@@ -202,28 +236,6 @@ static njs_webcrypto_entry_t njs_webcryp
     },
 
     {
-      njs_str("RSASSA-PKCS1-v1_5"),
-      njs_webcrypto_algorithm(NJS_ALGORITHM_RSASSA_PKCS1_v1_5,
-                              NJS_KEY_USAGE_SIGN |
-                              NJS_KEY_USAGE_VERIFY |
-                              NJS_KEY_USAGE_GENERATE_KEY,
-                              NJS_KEY_FORMAT_PKCS8 |
-                              NJS_KEY_FORMAT_SPKI |
-                              NJS_KEY_FORMAT_JWK)
-    },
-
-    {
-      njs_str("RSA-PSS"),
-      njs_webcrypto_algorithm(NJS_ALGORITHM_RSA_PSS,
-                              NJS_KEY_USAGE_SIGN |
-                              NJS_KEY_USAGE_VERIFY |
-                              NJS_KEY_USAGE_GENERATE_KEY,
-                              NJS_KEY_FORMAT_PKCS8 |
-                              NJS_KEY_FORMAT_SPKI |
-                              NJS_KEY_FORMAT_JWK)
-    },
-
-    {
       njs_str("ECDSA"),
       njs_webcrypto_algorithm(NJS_ALGORITHM_ECDSA,
                               NJS_KEY_USAGE_SIGN |
@@ -262,16 +274,6 @@ static njs_webcrypto_entry_t njs_webcryp
     },
 
     {
-      njs_str("HMAC"),
-      njs_webcrypto_algorithm(NJS_ALGORITHM_HMAC,
-                              NJS_KEY_USAGE_GENERATE_KEY |
-                              NJS_KEY_USAGE_SIGN |
-                              NJS_KEY_USAGE_VERIFY,
-                              NJS_KEY_FORMAT_RAW |
-                              NJS_KEY_FORMAT_JWK)
-    },
-
-    {
         njs_null_str,
         0
     }
@@ -335,7 +337,7 @@ static njs_webcrypto_entry_t njs_webcryp
 
 
 static njs_str_t
-    njs_webcrypto_alg_name[NJS_ALGORITHM_HMAC + 1][NJS_HASH_SHA512 + 1] = {
+    njs_webcrypto_alg_name[NJS_ALGORITHM_HMAC + 1][NJS_HASH_MAX] = {
     {
         njs_null_str,
         njs_str("RS1"),


More information about the nginx-devel mailing list