diff --git a/JOSESwift/Sources/CryptoImplementation/RSA.swift b/JOSESwift/Sources/CryptoImplementation/RSA.swift index 77fffa53..27bc2c15 100644 --- a/JOSESwift/Sources/CryptoImplementation/RSA.swift +++ b/JOSESwift/Sources/CryptoImplementation/RSA.swift @@ -69,9 +69,9 @@ internal extension AsymmetricKeyAlgorithm { /// /// - RSA1_5: For detailed information about the allowed plain text length for RSAES-PKCS1-v1_5, /// please refer to [RFC-3447, Section 7.2](https://tools.ietf.org/html/rfc3447#section-7.2). - /// - RSAOAEP: For detailed information about the allowed plain text length for RSA-OAEP, + /// - RSAOAEP: For detailed information about the allowed plain text length for RSAES-OAEP, /// please refer to [RFC-3447, Section 7.1](https://tools.ietf.org/html/rfc3447#section-7.1). - /// - RSAOAEP256: For detailed information about the allowed plain text length for RSA-OAEP-256, + /// - RSAOAEP256: For detailed information about the allowed plain text length for RSAES-OAEP-256, /// please refer to [RFC-3447, Section 7.1](https://tools.ietf.org/html/rfc3447#section-7.1). func maxMessageLength(for publicKey: SecKey) -> Int { let k = SecKeyGetBlockSize(publicKey) @@ -122,10 +122,10 @@ fileprivate extension AsymmetricKeyAlgorithm { // please refer to the RFC(https://tools.ietf.org/html/rfc3447#section-7.2.2). return cipherText.count == SecKeyGetBlockSize(privateKey) case .RSAOAEP, .RSAOAEP256: - // For detailed information about the allowed cipher length for RSA-OAEP and RSA-OAEP-256, + // For detailed information about the allowed cipher length for RSAES-OAEP and RSAES-OAEP-256, // please refer to RFC-3447 (https://tools.ietf.org/html/rfc3447#section-7.1.2, // https://www.rfc-editor.org/errata_search.php?rfc=3447): - // The ciphertext to be decrypted is an an octet string of length k, + // The ciphertext to be decrypted is an octet string of length k, // where k is the length in octets of the RSA modulus, // and k >= 2hLen + 2 return cipherText.count == SecKeyGetBlockSize(privateKey) diff --git a/JOSESwift/Sources/Decrypter.swift b/JOSESwift/Sources/Decrypter.swift index 375f3c28..4c6182b1 100644 --- a/JOSESwift/Sources/Decrypter.swift +++ b/JOSESwift/Sources/Decrypter.swift @@ -137,7 +137,7 @@ public struct Decrypter { cek = symmetricKey } else { // Generate a random CEK to substitue in case we fail to decrypt the CEK. - // This is to prevent the to prevent MMA (Million Message Attack) against RSA. + // This is to prevent the MMA (Million Message Attack) against RSA. // For detailed information, please refer to RFC-3218 (https://tools.ietf.org/html/rfc3218#section-2.3.2), // RFC-5246 (https://tools.ietf.org/html/rfc5246#appendix-F.1.1.2), // and http://www.ietf.org/mail-archive/web/jose/current/msg01832.html. diff --git a/Tests/JWERSATests.swift b/Tests/JWERSATests.swift index bbefe972..8b812b93 100644 --- a/Tests/JWERSATests.swift +++ b/Tests/JWERSATests.swift @@ -49,7 +49,7 @@ class JWERSATests: RSACryptoTestCase { // // System.out.println(jwe.serialize()); - let compactSerializedJWERSA1 = """ + let compactSerializedJWERSHA1 = """ eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0.Od5AMgOHu6rcEYWkX7w_x_wnMlM5JfZaszCC4xtLGYU9d0BnPm95UWUrgSh\ StGH6LHMxpGdru6gXpdxfhhrji12vUIzmkbyNW5M9wjx2t0e4pzzBSYxgOzFoa3jT9a0PcZfyqHIeTrcrTHtpSJ_CIDiZ3MIeqA7hjuRqu2YcTA\ E0v5TPLhHDVRBptkOggA5SL2-gRuUuYoWdanMw_JTHK4utXQZoSY1LTdub_Fh5ez1RqOouc3an5Hx6ImzyJS_cbO_l9xHpHjE7in6SeV9bAZTaY\ @@ -57,7 +57,7 @@ class JWERSATests: RSACryptoTestCase { YP_e_rhz0PVg9QnJXiRl030ggI9GGs3E_0pEPBs9_WJ3E60qQVoXTIMbJXSQ.bQc-W1Ph_0_3kX570pT8gjDlGyiK3kF8PlHiT7GWfMo """.data(using: .utf8)! - let compactSerializedJWERSAOAEPSHA = """ + let compactSerializedJWERSAOAEPSHA1 = """ eyJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwiYWxnIjoiUlNBLU9BRVAifQ.VjoovzQfSQ9zRbPxFR-7suNJesM9yVQrH7tqvEWospcIuYBSQjPTBE6j\ m32iqx9YQd3LiCLqDwz9fzn6_FANSGAYrVgibYX0BqCzN_l83t7YWIa_h43TCgE4sRestYasbqwXY-EfLNK2u37tRxCxxLKDtyugujxNZyQxpOh\ gEA0TzJwwPa2ITX37Z0zF_sAEp_09lF0jWm9u4cVSt-mIIYcpgh5c3sIw1IWs7ynPNWn9Y68YmXJhgeZkIzDiLNGhf3KesH9to4z-EvIyXVBIWl\ @@ -75,8 +75,8 @@ class JWERSATests: RSACryptoTestCase { lazy var compactSerializedData: [String: Data] = { [ - AsymmetricKeyAlgorithm.RSA1_5.rawValue: compactSerializedJWERSA1, - AsymmetricKeyAlgorithm.RSAOAEP.rawValue: compactSerializedJWERSAOAEPSHA, + AsymmetricKeyAlgorithm.RSA1_5.rawValue: compactSerializedJWERSHA1, + AsymmetricKeyAlgorithm.RSAOAEP.rawValue: compactSerializedJWERSAOAEPSHA1, AsymmetricKeyAlgorithm.RSAOAEP256.rawValue: compactSerializedJWERSAOAEPSHA256 ] }() diff --git a/Tests/RSADecrypterTests.swift b/Tests/RSADecrypterTests.swift index 63fa0a57..ca7afdf6 100644 --- a/Tests/RSADecrypterTests.swift +++ b/Tests/RSADecrypterTests.swift @@ -26,8 +26,8 @@ import XCTest class RSADecrypterTests: RSACryptoTestCase { - // Cipher texts are generated with `openssl rsautl` - // `printf` is used because `echo` appends a newline at the end of the string + // Cipher texts are generated with `openssl rsautl`. + // `printf` is used because `echo` appends a newline at the end of the string. // printf "The true sign of intelligence is not knowledge but imagination." | openssl rsautl -encrypt -pubin -inkey alice.pub.pem -out >(base64) let cipherTextWithAliceKeyBase64 = """ @@ -38,7 +38,7 @@ class RSADecrypterTests: RSACryptoTestCase { """ // printf "The true sign of intelligence is not knowledge but imagination." | openssl pkeyutl -encrypt -pubin -inkey alice.pub.pem -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256 -pkeyopt rsa_mgf1_md:sha256 -out >(base64) - // *NOTE*: openssl v1.1.x is required to encrypt data using RSA-OAEP with SHA256 digest + // *NOTE*: openssl v1.1.x is required to encrypt data using RSAES-OAEP with SHA256 digest. let cipherTextWithAliceOAEPSHA256Base64 = """ HtL3/k9aiCzON4dEAK930LXvxoWgu2cXHj011FAY4Z++CikiPn5gt/TLFEEV6c4MyMUN8Pj796XwO5a9LRfsV+XWjb5WIAUXewgdKYC1NBFf/q\ Ip+NixeO6oo0nh5NlApJgphRIy1en9ARoz0rIzayt0Py4QOEse7OHLUnDA7PP8vp0X1pyqEG9FZaPViH4+/1zwvEjBVo4N5K4Zl4jqzFYTOkm4\ @@ -47,7 +47,7 @@ class RSADecrypterTests: RSACryptoTestCase { """ // printf "The true sign of intelligence is not knowledge but imagination." | openssl pkeyutl -encrypt -pubin -inkey alice.pub.pem -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha1 -pkeyopt rsa_mgf1_md:sha1 -out >(base64) - // *NOTE*: openssl v1.1.x is required to encrypt data using RSA-OAEP with SHA256 digest + // *NOTE*: openssl v1.1.x is required to encrypt data using RSAES-OAEP with SHA256 digest. let cipherTextWithAliceOAEPSHA1Base64 = """ bx+Sg8AfSLUGUL/ogL6LZLJdX62N7sYA413SG5sfaAunpyrH3/SCJNTsjQow8zk99jbbiSABWKowDb8tfIwY0SHiU/aKW46f7FeP/70vF2zOefr\ LnVjw1hE9mJi/P7qP66Md8lNC7iRRDtluAHzPE7Hr8E4Xam2lEmZOXsE0lFnHf0eyG23rezGfnJ4lIY40GK926qyjTkSvtHJa57bzfP3Bxj61NK\ @@ -64,7 +64,7 @@ class RSADecrypterTests: RSACryptoTestCase { """ // printf "The true sign of intelligence is not knowledge but imagination." | openssl pkeyutl -encrypt -pubin -inkey bob.pub.pem -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256 -pkeyopt rsa_mgf1_md:sha256 -out >(base64) - // *NOTE*: openssl v1.1.x is required to encrypt data using RSA-OAEP with SHA256 digest + // *NOTE*: openssl v1.1.x is required to encrypt data using RSAES-OAEP with SHA256 digest. let cipherTextWithBobKeyOAEPSHA256Base64 = """ IUCsUQzcyL/iuwWpgXK/TgyrsxuSbKKAXq1bd6wlRf7O+9UBlQAenAzXkhRchBOrCYbS1Bs2IwN3gu51RiVsuOg5oHxxKIbtfnbqwtw9beV02oR\ ETCSZ5wPFC/tlYYYloGYR3O47VF5o+NV4qKOE6jbjBEknMAwdN1eoGb0LmF9kUvt9jCLkI1Jt3Cqs8fV9nxqI4Iyzn6hjlvRJk82Ah/q86XfNCQ\