Coder Social home page Coder Social logo

swifthpke's Introduction

SwiftHPKE

SwiftHPKE implements the Hybrid Public Key Encryption standard as defined in RFC 9180 including all four modes of operation:

  • Base mode
  • Preshared key mode
  • Authenticated mode
  • Authenticated, preshared key mode

SwiftHPKE requires Swift 5.0. It also requires that the Int and UInt types be 64 bit types.

Its documentation is build with the DocC plugin and published on GitHub Pages at this location:

https://leif-ibsen.github.io/SwiftHPKE/documentation/swifthpke

The documentation is also available in the SwiftHPKE.doccarchive file.

swifthpke's People

Contributors

leif-ibsen avatar

Stargazers

 avatar

Watchers

 avatar

swifthpke's Issues

PublicKey constructor failure

In the PublicKey constructor init(kem:bytes:) bytes represents either
an uncompressed curve point or a compressed curve point.

The constructor fails if bytes is a compressed curve point.

To be corrected in a coming release.

Algorithm not compatible with newest apple version

I was testing the repository to check compatibility with the new apple implementation of HPKE but seems is not compatible.
When running this MVE

func letsTest() {
     let cypher = HPKE.Ciphersuite(
        kem: .P384_HKDF_SHA384,
        kdf: .HKDF_SHA384,
        aead: .AES_GCM_256
    )
    let cypherLegacy = SwiftHPKE.CipherSuite(
        kem: .P384,
        kdf: .KDF384,
        aead: .AESGCM256
    )
    let privateKey = P384.KeyAgreement.PrivateKey(compactRepresentable: false)
    let bePrivateKey = P384.KeyAgreement.PrivateKey(compactRepresentable: false)
    let privateKeyLegacy = try! PrivateKey(der: Bytes(privateKey.derRepresentation))
    let publicKeyLegacy = try! PublicKey(der: Bytes(privateKey.publicKey.derRepresentation))
    let bePrivateKeyLegacy = try! PrivateKey(der: Bytes(bePrivateKey.derRepresentation))
    let bePublicKeyLegacy = try! PublicKey(der: Bytes(bePrivateKey.publicKey.derRepresentation))

    let message = "Hello World"
    var sender = try! HPKE.Sender(
        recipientKey: privateKey.publicKey,
        ciphersuite: cypher,
        info: "info".data(using: .utf8)!,
        authenticatedBy: bePrivateKey
    )
    let encryptedMessage = try! sender.seal(
        message.data(using: .utf8)!,
        authenticating: "auth".data(using: .utf8)!
    )
    let decrypted = try! cypherLegacy.open(
        privateKey: privateKeyLegacy,
        info: Bytes("info".data(using: .utf8)!),
        authentication: bePublicKeyLegacy,
        ct: Bytes(encryptedMessage),
        aad: Bytes("auth".data(using: .utf8)!),
        encap: Bytes(sender.encapsulatedKey)
    )
    print(String(bytes: decrypted, encoding: .utf8)!)
}

In this example I've created two pair of keys, converted them fo use this library following the documentation and tried to encrypt a simple message with the new Apple API.
When decoding it using this library, an error is thrown
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: CryptoKit.CryptoKitError.authenticationFailure

Screenshot 2024-04-23 at 16 55 58

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.