Files
swift-crypto/Sources/_CryptoExtras/ARC/ARC.swift
T
Si Beaumont b81059d507 extras: Add API for Anonymous Rate-Limited Credentials, ARC(P-384) (#328)
## Motivation

We would like to provide support for ARCV1(P-384), as defined in [IETF
Internet Draft: Anonymous Rate-Limited
Credentials](https://datatracker.ietf.org/doc/draft-yun-cfrg-arc/).

## Modifications

- Add internal implementation, generic over the NIST curves.
- Add public API for ARC(P-384), under `P384._ARCV1`.

## Result

New API for current draft of ARC.

## Tests

- End to end tests of internal implementation and API surface.
- Test vector tests of internal implementation and API surface, from the
spec draft.
2025-02-14 10:49:59 +00:00

64 lines
2.2 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftCrypto open source project
//
// Copyright (c) 2024 Apple Inc. and the SwiftCrypto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import Crypto
import Foundation
/// Anonymous Rate-Limited Credentials (ARC) using the CMZ14 MACGGM construction, as defined in
/// https://chris-wood.github.io/draft-arc/draft-yun-cfrg-arc.html
enum ARC {}
extension ARC {
static let domain = "ARCV1-P384"
enum Errors: Error {
case invalidProof
case invalidPresentationLimit
case presentationLimitExceeded
case incorrectRequestDataSize
case incorrectResponseDataSize
case incorrectCredentialDataSize
case incorrectPresentationDataSize
case incorrectProofDataSize
case incorrectServerCommitmentsSize
case incorrectPrivateKeyDataSize
case incorrectPublicKeyDataSize
}
/// Ciphersuites for Anonymous Rate-Limited Credentials (ARC)
struct Ciphersuite<H2G: HashToGroup> {
let suiteID: Int
init(_ h2g: H2G.Type) {
switch h2g.self {
case is HashToCurveImpl<P256>.Type:
self.suiteID = 3
case is HashToCurveImpl<P384>.Type:
self.suiteID = 4
case is HashToCurveImpl<P521>.Type:
self.suiteID = 5
default:
fatalError("Anonymous Rate-Limited Credentials (ARC) only support corecrypto H2G.")
}
}
}
static func getGenerators<H2G: HashToGroup>(suite _: Ciphersuite<H2G>) -> (
generatorG: H2G.G.Element, generatorH: H2G.G.Element
) {
let generatorG = H2G.G.Element.generator
let generatorH = H2G.hashToGroup(generatorG.oprfRepresentation, domainSeparationString: Data(("HashToGroup-" + ARC.domain + "generatorH").utf8))
return (generatorG, generatorH)
}
}