Skip to content

Commit

Permalink
fix: c20p and xc20p had the wrong algorithm name
Browse files Browse the repository at this point in the history
  • Loading branch information
beatt83 committed Sep 14, 2024
1 parent 3aa354f commit 9f26041
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 49 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ This library provides comprehensive support for the Jose suite of standards, inc
| A128GCMKW |:white_check_mark:|
| A192GCMKW |:white_check_mark:|
| A256GCMKW |:white_check_mark:|
| C20PKW |:white_check_mark:|
| XC20PKW |:white_check_mark:|
| C20P |:white_check_mark:|
| XC20P |:white_check_mark:|

</td></tr> </table>

Expand Down Expand Up @@ -359,8 +359,8 @@ Please check our documentation for more on [JWE Encryption](https://beatt83.gith
- A128GCM (AES GCM using 128-bit key)
- A192GCM (AES GCM using 192-bit key)
- A256GCM (AES GCM using 256-bit key)
- C20PKW (ChaCha20-Poly1305)
- XC20PKW (XChaCha20-Poly1305)
- C20P (ChaCha20-Poly1305)
- XC20P (XChaCha20-Poly1305)
- Note: ChaChaPoly20-Poly1305 and XChaChaPoly20-Poly1305 is specified in [draft-amringer-jose-chacha-02](https://datatracker.ietf.org/doc/html/draft-amringer-jose-chacha-02)

3. **Compression Algorithms**:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import CryptoKit
import Foundation

/// `C20PKW` provides methods to encrypt and decrypt data using the ChaCha20-Poly1305 algorithm.
public struct C20PKW: ContentEncryptor, ContentDecryptor {
/// `C20P` provides methods to encrypt and decrypt data using the ChaCha20-Poly1305 algorithm.
public struct C20P: ContentEncryptor, ContentDecryptor {
/// The content encryption algorithm used, represented as a string.
public let contentEncryptionAlgorithm: String = ContentEncryptionAlgorithm.c20PKW.rawValue
public let contentEncryptionAlgorithm: String = ContentEncryptionAlgorithm.c20P.rawValue
/// The size of the initialization vector in bits.
public let initializationVectorSizeInBits: Int = ContentEncryptionAlgorithm.c20PKW.initializationVectorSizeInBits
public let initializationVectorSizeInBits: Int = ContentEncryptionAlgorithm.c20P.initializationVectorSizeInBits
/// The size of the content encryption key (CEK) in bits.
public let cekKeySize: Int = ContentEncryptionAlgorithm.c20PKW.keySizeInBits
public let cekKeySize: Int = ContentEncryptionAlgorithm.c20P.keySizeInBits

/// Generates a random initialization vector.
/// - Throws: An error if the random data generation fails.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import CryptoSwift
import Foundation

/// `XC20PKW` provides methods to encrypt and decrypt data using the XChaCha20-Poly1305 algorithm.
public struct XC20PKW: ContentEncryptor, ContentDecryptor {
/// `XC20P` provides methods to encrypt and decrypt data using the XChaCha20-Poly1305 algorithm.
public struct XC20P: ContentEncryptor, ContentDecryptor {
/// The content encryption algorithm used, represented as a string.
public let contentEncryptionAlgorithm: String = ContentEncryptionAlgorithm.xC20PKW.rawValue
public let contentEncryptionAlgorithm: String = ContentEncryptionAlgorithm.xC20P.rawValue
/// The size of the initialization vector in bits.
public let initializationVectorSizeInBits: Int = ContentEncryptionAlgorithm.xC20PKW.initializationVectorSizeInBits
public let initializationVectorSizeInBits: Int = ContentEncryptionAlgorithm.xC20P.initializationVectorSizeInBits
/// The size of the content encryption key (CEK) in bits.
public let cekKeySize: Int = ContentEncryptionAlgorithm.xC20PKW.keySizeInBits
public let cekKeySize: Int = ContentEncryptionAlgorithm.xC20P.keySizeInBits

/// Generates a random initialization vector.
/// - Throws: An error if the random data generation fails.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public enum ContentEncryptionAlgorithm: String, Codable, Equatable, CaseIterable

/// ChaCha20-Poly1305 with a 256-bit key and 96 bit IV.
/// This algorithm provides robust security and is widely used in various security protocols and systems, it is faster than AES in mobile devices.
case c20PKW = "C20PKW"
case c20P = "C20P"

/// XChaCha20-Poly1305 with a 256-bit key and 192 bit IV.
/// This algorithm provides robust security and is widely used in various security protocols and systems, it is faster than AES in mobile devices.
case xC20PKW = "XC20PKW"
case xC20P = "XC20P"



Expand All @@ -54,16 +54,16 @@ public enum ContentEncryptionAlgorithm: String, Codable, Equatable, CaseIterable
case .a128CBCHS256: return 256
case .a192CBCHS384: return 384
case .a256CBCHS512: return 512
case .c20PKW, .xC20PKW: return 256
case .c20P, .xC20P: return 256
}
}

/// Returns the initialization vector size in bits suitable for the encryption algorithm.
/// - Returns: The size of the initialization vector in bits.
public var initializationVectorSizeInBits: Int {
switch self {
case .c20PKW: return 96
case .xC20PKW: return 192
case .c20P: return 96
case .xC20P: return 192
case .a128CBCHS256, .a192CBCHS384, .a256CBCHS512: return 128
case .a128GCM, .a192GCM, .a256GCM: return 96
}
Expand All @@ -85,10 +85,10 @@ public enum ContentEncryptionAlgorithm: String, Codable, Equatable, CaseIterable
return AES192GCM()
case .a256GCM:
return AES256GCM()
case .c20PKW:
return C20PKW()
case .xC20PKW:
return XC20PKW()
case .c20P:
return C20P()
case .xC20P:
return XC20P()
}
}

Expand All @@ -108,10 +108,10 @@ public enum ContentEncryptionAlgorithm: String, Codable, Equatable, CaseIterable
return AES192GCM()
case .a256GCM:
return AES256GCM()
case .c20PKW:
return C20PKW()
case .xC20PKW:
return XC20PKW()
case .c20P:
return C20P()
case .xC20P:
return XC20P()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ struct ECDH1PUJWEDecryptor: JWEDecryptor {
.a128CBCHS256,
.a192CBCHS384,
.a256CBCHS512,
.c20PKW,
.xC20PKW
.c20P,
.xC20P
]

func decrypt<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ struct ECDHJWEDecryptor: JWEDecryptor {
.a128CBCHS256,
.a192CBCHS384,
.a256CBCHS512,
.c20PKW,
.xC20PKW
.c20P,
.xC20P
]

func decrypt<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ struct ECDH1PUJWEEncryptor: JWEEncryptor {
.a128CBCHS256,
.a192CBCHS384,
.a256CBCHS512,
.c20PKW,
.xC20PKW
.c20P,
.xC20P
]

init(masterEphemeralKey: Bool = false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ struct ECDHJWEEncryptor: JWEEncryptor {
.a128CBCHS256,
.a192CBCHS384,
.a256CBCHS512,
.c20PKW,
.xC20PKW
.c20P,
.xC20P
]

init(masterEphemeralKey: Bool = false) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/jose-swift/jose-swift.docc/Articles/JWEEncryption.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ The **jose-swift** library supports a wide range of cryptographic algorithms for
- **A128GCM**: AES GCM using 128-bit key
- **A192GCM**: AES GCM using 192-bit key
- **A256GCM**: AES GCM using 256-bit key
- **C20PKW**: ChaCha20-Poly1305
- **XC20PKW**: XChaCha20-Poly1305
- **C20P**: ChaCha20-Poly1305
- **XC20P**: XChaCha20-Poly1305
- Note: ChaChaPoly20-Poly1305 and XChaChaPoly20-Poly1305 is specified in [draft-amringer-jose-chacha-02](https://datatracker.ietf.org/doc/html/draft-amringer-jose-chacha-02)

### Compression Algorithms
Expand Down
4 changes: 2 additions & 2 deletions Tests/JWATests/C20PTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ final class C20PTests: XCTestCase {

func testC20PCycle() throws {
let payload = "Test".data(using: .utf8)!
let encryptor = ContentEncryptionAlgorithm.c20PKW.encryptor
let decryptor = ContentEncryptionAlgorithm.c20PKW.decryptor
let encryptor = ContentEncryptionAlgorithm.c20P.encryptor
let decryptor = ContentEncryptionAlgorithm.c20P.decryptor
let key = try encryptor.generateCEK()
let iv = try encryptor.generateInitializationVector()
let aad = Data()
Expand Down
4 changes: 2 additions & 2 deletions Tests/JWATests/XC20PTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ final class XC20PTests: XCTestCase {

func testXC20PCycle() throws {
let payload = "Test".data(using: .utf8)!
let encryptor = ContentEncryptionAlgorithm.xC20PKW.encryptor
let decryptor = ContentEncryptionAlgorithm.xC20PKW.decryptor
let encryptor = ContentEncryptionAlgorithm.xC20P.encryptor
let decryptor = ContentEncryptionAlgorithm.xC20P.decryptor
let key = try encryptor.generateCEK()
let iv = try encryptor.generateInitializationVector()
let aad = Data()
Expand Down
8 changes: 4 additions & 4 deletions Tests/JWETests/ECDH1PUTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ final class ECDH1PUTests: XCTestCase {
XCTAssertEqual(payload.toHexString(), decrypted.toHexString())
}

func testECDH1PUA256KW_C20PKWCycle() throws {
func testECDH1PUA256KW_C20PCycle() throws {
let payload = try "Test".tryToData()
let aliceKey = JWK.testingCurve25519KPair
let bobKey = JWK.testingCurve25519KPair

let keyAlg = KeyManagementAlgorithm.ecdh1PUA256KW
let encAlg = ContentEncryptionAlgorithm.c20PKW
let encAlg = ContentEncryptionAlgorithm.c20P

let header = try DefaultJWEHeaderImpl(
keyManagementAlgorithm: keyAlg,
Expand Down Expand Up @@ -238,13 +238,13 @@ final class ECDH1PUTests: XCTestCase {
XCTAssertEqual(payload.toHexString(), decrypted.toHexString())
}

func testECDH1PUA256KW_XC20PKWCycle() throws {
func testECDH1PUA256KW_XC20PCycle() throws {
let payload = try "Test".tryToData()
let aliceKey = JWK.testingCurve25519KPair
let bobKey = JWK.testingCurve25519KPair

let keyAlg = KeyManagementAlgorithm.ecdh1PUA256KW
let encAlg = ContentEncryptionAlgorithm.xC20PKW
let encAlg = ContentEncryptionAlgorithm.xC20P

let header = try DefaultJWEHeaderImpl(
keyManagementAlgorithm: keyAlg,
Expand Down
8 changes: 4 additions & 4 deletions Tests/JWETests/ECDHESTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ final class ECDHESTests: XCTestCase {
XCTAssertEqual(payload, decrypted)
}

func testECDHESA256KW_C20PKWCycle() throws {
func testECDHESA256KW_C20PCycle() throws {
let payload = try "Test".tryToData()
let aliceKey = JWK.testingES256Pair
let bobKey = JWK.testingES256Pair

let keyAlg = KeyManagementAlgorithm.ecdhESA128KW
let encAlg = ContentEncryptionAlgorithm.c20PKW
let encAlg = ContentEncryptionAlgorithm.c20P

let header = try DefaultJWEHeaderImpl(
keyManagementAlgorithm: keyAlg,
Expand Down Expand Up @@ -129,13 +129,13 @@ final class ECDHESTests: XCTestCase {
XCTAssertEqual(payload, decrypted)
}

func testECDHESA256KW_XC20PKWCycle() throws {
func testECDHESA256KW_XC20PCycle() throws {
let payload = try "Test".tryToData()
let aliceKey = JWK.testingES256Pair
let bobKey = JWK.testingES256Pair

let keyAlg = KeyManagementAlgorithm.ecdhESA128KW
let encAlg = ContentEncryptionAlgorithm.xC20PKW
let encAlg = ContentEncryptionAlgorithm.xC20P

let header = try DefaultJWEHeaderImpl(
keyManagementAlgorithm: keyAlg,
Expand Down

0 comments on commit 9f26041

Please sign in to comment.