]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
mbedtls: add support to mbedtls3 1846/head
authorSeo Suchan <tjtncks@gmail.com>
Thu, 9 May 2024 10:10:59 +0000 (19:10 +0900)
committerSeo Suchan <tjtncks@gmail.com>
Thu, 9 May 2024 12:51:38 +0000 (21:51 +0900)
Signed-off-by: Seo Suchan <tjtncks@gmail.com>
common.c
player.c
player.h

index 4dc75bc7f07df6eda1a209348cf4174b7ac81895..0e2a07243bfccac2956d31daa8c52d7b904f79e8 100644 (file)
--- a/common.c
+++ b/common.c
 #include <mbedtls/md.h>
 #include <mbedtls/version.h>
 #include <mbedtls/x509.h>
+
+#if MBEDTLS_VERSION_MAJOR == 3
+#define MBEDTLS_PRIVATE_V3_ONLY(_q) MBEDTLS_PRIVATE(_q)
+#else
+#define MBEDTLS_PRIVATE_V3_ONLY(_q) _q
+#endif
 #endif
 
 #ifdef CONFIG_LIBDAEMON
@@ -910,8 +916,14 @@ uint8_t *rsa_apply(uint8_t *input, int inlen, int *outlen, int mode) {
 
   mbedtls_pk_init(&pkctx);
 
+#if MBEDTLS_VERSION_MAJOR == 3
   rc = mbedtls_pk_parse_key(&pkctx, (unsigned char *)super_secret_key, sizeof(super_secret_key),
+                            NULL, 0, mbedtls_ctr_drbg_random, &ctr_drbg);
+#else
+  rc = mbedtls_pk_parse_key(&pkctx, (unsigned char *)super_secret_key, sizeof(super_secret_key), 
                             NULL, 0);
+
+#endif
   if (rc != 0)
     debug(1, "Error %d reading the private key.", rc);
 
@@ -920,19 +932,29 @@ uint8_t *rsa_apply(uint8_t *input, int inlen, int *outlen, int mode) {
 
   switch (mode) {
   case RSA_MODE_AUTH:
-    mbedtls_rsa_set_padding(trsa, MBEDTLS_RSA_PKCS_V15, MBEDTLS_MD_NONE);
-    outbuf = malloc(trsa->len);
+    mbedtls_rsa_set_padding(trsa, MBEDTLS_RSA_PKCS_V15, MBEDTLS_MD_NONE);    
+    outbuf = malloc(trsa->MBEDTLS_PRIVATE_V3_ONLY(len));
+#if MBEDTLS_VERSION_MAJOR == 3
+    rc = mbedtls_rsa_pkcs1_encrypt(trsa, mbedtls_ctr_drbg_random, &ctr_drbg,
+                                   inlen, input, outbuf);
+#else
     rc = mbedtls_rsa_pkcs1_encrypt(trsa, mbedtls_ctr_drbg_random, &ctr_drbg, MBEDTLS_RSA_PRIVATE,
                                    inlen, input, outbuf);
+#endif
     if (rc != 0)
       debug(1, "mbedtls_pk_encrypt error %d.", rc);
-    *outlen = trsa->len;
+    *outlen = trsa->MBEDTLS_PRIVATE_V3_ONLY(len);
     break;
   case RSA_MODE_KEY:
     mbedtls_rsa_set_padding(trsa, MBEDTLS_RSA_PKCS_V21, MBEDTLS_MD_SHA1);
-    outbuf = malloc(trsa->len);
+    outbuf = malloc(trsa->MBEDTLS_PRIVATE_V3_ONLY(len));
+#if MBEDTLS_VERSION_MAJOR == 3
+    rc = mbedtls_rsa_pkcs1_decrypt(trsa, mbedtls_ctr_drbg_random, &ctr_drbg,
+                                   &olen, input, outbuf, trsa->MBEDTLS_PRIVATE_V3_ONLY(len));
+#else
     rc = mbedtls_rsa_pkcs1_decrypt(trsa, mbedtls_ctr_drbg_random, &ctr_drbg, MBEDTLS_RSA_PRIVATE,
                                    &olen, input, outbuf, trsa->len);
+#endif
     if (rc != 0)
       debug(1, "mbedtls_pk_decrypt error %d.", rc);
     *outlen = olen;
index 8c17527222558545e5d00746947bb5d65c374dd0..d023d269c6a5532e0426c50b9fbb658a47490dfa 100644 (file)
--- a/player.c
+++ b/player.c
@@ -48,7 +48,6 @@
 
 #ifdef CONFIG_MBEDTLS
 #include <mbedtls/aes.h>
-#include <mbedtls/havege.h>
 #endif
 
 #ifdef CONFIG_POLARSSL
index 11435bf91db1d685691be9f35792627f6927c8ed..b35eb7652aeee77869cf15e3ebf0bf71b9ae43fd 100644 (file)
--- a/player.h
+++ b/player.h
@@ -9,7 +9,6 @@
 
 #ifdef CONFIG_MBEDTLS
 #include <mbedtls/aes.h>
-#include <mbedtls/havege.h>
 #endif
 
 #ifdef CONFIG_POLARSSL