feat_expose_several_extra_cipher_functions.patch 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Shelley Vohr <[email protected]>
  3. Date: Wed, 31 May 2023 11:36:48 +0200
  4. Subject: feat: expose several extra cipher functions
  5. This patch exposes the following ciphers:
  6. AES_CFB Ciphers: aes-128-cfb, aes-256-cfb
  7. Implementations for these ciphers exist but aren't exposed, so they're
  8. unusable without this patch. We should upstream this as similar
  9. patches for implemented cipher functions have been accepted.
  10. Blowfish Ciphers: bf-cbc, bf-cfb, bf-ecb
  11. The addition of Blowfish ciphers adds references decrepit code
  12. from non-decrepit code, so upstream is unlikely to take the patch.
  13. DES Ciphers: des-ede3
  14. An implementation for this cipher exists but isn't exposed, so it's
  15. unusable without this patch. Akin to the AES_CFB exposures, we should
  16. upstream this as similar patches for implemented cipher functions have
  17. been accepted.
  18. RC2 Ciphers: rc2-40-cbc
  19. It's unclear whether this would be accepted upstream. We should try regardless.
  20. diff --git a/crypto/cipher/get_cipher.cc b/crypto/cipher/get_cipher.cc
  21. index 2d0f369bdeba84b157db82bd87c293ae2344c560..9088a0f29a95fe7abbb98cbf7e8be2577e5617ac 100644
  22. --- a/crypto/cipher/get_cipher.cc
  23. +++ b/crypto/cipher/get_cipher.cc
  24. @@ -26,6 +26,7 @@ static const struct {
  25. const EVP_CIPHER *(*func)(void);
  26. } kCiphers[] = {
  27. {NID_aes_128_cbc, "aes-128-cbc", EVP_aes_128_cbc},
  28. + {NID_aes_128_cfb128, "aes-128-cfb", EVP_aes_128_cfb128},
  29. {NID_aes_128_ctr, "aes-128-ctr", EVP_aes_128_ctr},
  30. {NID_aes_128_ecb, "aes-128-ecb", EVP_aes_128_ecb},
  31. {NID_aes_128_gcm, "aes-128-gcm", EVP_aes_128_gcm},
  32. @@ -36,17 +37,23 @@ static const struct {
  33. {NID_aes_192_gcm, "aes-192-gcm", EVP_aes_192_gcm},
  34. {NID_aes_192_ofb128, "aes-192-ofb", EVP_aes_192_ofb},
  35. {NID_aes_256_cbc, "aes-256-cbc", EVP_aes_256_cbc},
  36. + {NID_aes_256_cfb128, "aes-256-cfb", EVP_aes_256_cfb128},
  37. {NID_aes_256_ctr, "aes-256-ctr", EVP_aes_256_ctr},
  38. {NID_aes_256_ecb, "aes-256-ecb", EVP_aes_256_ecb},
  39. {NID_aes_256_gcm, "aes-256-gcm", EVP_aes_256_gcm},
  40. {NID_aes_256_ofb128, "aes-256-ofb", EVP_aes_256_ofb},
  41. + {NID_bf_cbc, "bf-cbc", EVP_bf_cbc},
  42. + {NID_bf_cfb64, "bf-cfb", EVP_bf_cfb},
  43. + {NID_bf_ecb, "bf-ecb", EVP_bf_ecb},
  44. {NID_des_cbc, "des-cbc", EVP_des_cbc},
  45. {NID_des_ecb, "des-ecb", EVP_des_ecb},
  46. {NID_des_ede_cbc, "des-ede-cbc", EVP_des_ede_cbc},
  47. {NID_des_ede_ecb, "des-ede", EVP_des_ede},
  48. + {NID_des_ede3_ecb, "des-ede3", EVP_des_ede3},
  49. {NID_des_ede3_cbc, "des-ede3-cbc", EVP_des_ede3_cbc},
  50. {NID_rc2_cbc, "rc2-cbc", EVP_rc2_cbc},
  51. {NID_rc4, "rc4", EVP_rc4},
  52. + {NID_rc2_40_cbc, "rc2-40-cbc", EVP_rc2_40_cbc}
  53. };
  54. const EVP_CIPHER *EVP_get_cipherbynid(int nid) {
  55. diff --git a/decrepit/evp/evp_do_all.cc b/decrepit/evp/evp_do_all.cc
  56. index 9fd0e0225fa48b0afb90b525236e54cff17c1c84..dded715011ac8c1dd9e4525f0bdd64088f8007cf 100644
  57. --- a/decrepit/evp/evp_do_all.cc
  58. +++ b/decrepit/evp/evp_do_all.cc
  59. @@ -20,8 +20,10 @@ void EVP_CIPHER_do_all_sorted(void (*callback)(const EVP_CIPHER *cipher,
  60. const char *unused, void *arg),
  61. void *arg) {
  62. callback(EVP_aes_128_cbc(), "AES-128-CBC", NULL, arg);
  63. + callback(EVP_aes_128_cfb128(), "AES-128-CFB", NULL, arg);
  64. callback(EVP_aes_192_cbc(), "AES-192-CBC", NULL, arg);
  65. callback(EVP_aes_256_cbc(), "AES-256-CBC", NULL, arg);
  66. + callback(EVP_aes_256_cfb128(), "AES-256-CFB", NULL, arg);
  67. callback(EVP_aes_128_ctr(), "AES-128-CTR", NULL, arg);
  68. callback(EVP_aes_192_ctr(), "AES-192-CTR", NULL, arg);
  69. callback(EVP_aes_256_ctr(), "AES-256-CTR", NULL, arg);
  70. @@ -34,9 +36,13 @@ void EVP_CIPHER_do_all_sorted(void (*callback)(const EVP_CIPHER *cipher,
  71. callback(EVP_aes_128_gcm(), "AES-128-GCM", NULL, arg);
  72. callback(EVP_aes_192_gcm(), "AES-192-GCM", NULL, arg);
  73. callback(EVP_aes_256_gcm(), "AES-256-GCM", NULL, arg);
  74. + callback(EVP_bf_cbc(), "BF-CBC", NULL, arg);
  75. + callback(EVP_bf_cfb(), "BF-CFB", NULL, arg);
  76. + callback(EVP_bf_ecb(), "BF-ECB", NULL, arg);
  77. callback(EVP_des_cbc(), "DES-CBC", NULL, arg);
  78. callback(EVP_des_ecb(), "DES-ECB", NULL, arg);
  79. callback(EVP_des_ede(), "DES-EDE", NULL, arg);
  80. + callback(EVP_des_ede3(), "DES-EDE3", NULL, arg);
  81. callback(EVP_des_ede_cbc(), "DES-EDE-CBC", NULL, arg);
  82. callback(EVP_des_ede3_cbc(), "DES-EDE3-CBC", NULL, arg);
  83. callback(EVP_rc2_cbc(), "RC2-CBC", NULL, arg);
  84. @@ -44,8 +50,10 @@ void EVP_CIPHER_do_all_sorted(void (*callback)(const EVP_CIPHER *cipher,
  85. // OpenSSL returns everything twice, the second time in lower case.
  86. callback(EVP_aes_128_cbc(), "aes-128-cbc", NULL, arg);
  87. + callback(EVP_aes_128_cfb128(), "aes-128-cfb", NULL, arg);
  88. callback(EVP_aes_192_cbc(), "aes-192-cbc", NULL, arg);
  89. callback(EVP_aes_256_cbc(), "aes-256-cbc", NULL, arg);
  90. + callback(EVP_aes_256_cfb128(), "aes-256-cfb", NULL, arg);
  91. callback(EVP_aes_128_ctr(), "aes-128-ctr", NULL, arg);
  92. callback(EVP_aes_192_ctr(), "aes-192-ctr", NULL, arg);
  93. callback(EVP_aes_256_ctr(), "aes-256-ctr", NULL, arg);
  94. @@ -58,9 +66,13 @@ void EVP_CIPHER_do_all_sorted(void (*callback)(const EVP_CIPHER *cipher,
  95. callback(EVP_aes_128_gcm(), "aes-128-gcm", NULL, arg);
  96. callback(EVP_aes_192_gcm(), "aes-192-gcm", NULL, arg);
  97. callback(EVP_aes_256_gcm(), "aes-256-gcm", NULL, arg);
  98. + callback(EVP_bf_cbc(), "bf-cbc", NULL, arg);
  99. + callback(EVP_bf_cfb(), "bf-cfb", NULL, arg);
  100. + callback(EVP_bf_ecb(), "bf-ecb", NULL, arg);
  101. callback(EVP_des_cbc(), "des-cbc", NULL, arg);
  102. callback(EVP_des_ecb(), "des-ecb", NULL, arg);
  103. callback(EVP_des_ede(), "des-ede", NULL, arg);
  104. + callback(EVP_des_ede3(), "des-ede3", NULL, arg);
  105. callback(EVP_des_ede_cbc(), "des-ede-cbc", NULL, arg);
  106. callback(EVP_des_ede3_cbc(), "des-ede3-cbc", NULL, arg);
  107. callback(EVP_rc2_cbc(), "rc2-cbc", NULL, arg);
  108. diff --git a/include/openssl/cipher.h b/include/openssl/cipher.h
  109. index ad0f13919299a036d1e1121a05f62e096406a6c5..7baea6a73d3da02e2834c33e5579b8ad2b984221 100644
  110. --- a/include/openssl/cipher.h
  111. +++ b/include/openssl/cipher.h
  112. @@ -429,6 +429,7 @@ OPENSSL_EXPORT const EVP_CIPHER *EVP_des_ede3_ecb(void);
  113. // EVP_aes_128_cfb128 is only available in decrepit.
  114. OPENSSL_EXPORT const EVP_CIPHER *EVP_aes_128_cfb128(void);
  115. +OPENSSL_EXPORT const EVP_CIPHER *EVP_aes_256_cfb128(void);
  116. // EVP_aes_128_cfb is an alias for |EVP_aes_128_cfb128| and is only available in
  117. // decrepit.