Require compressed encoding when deserializing OPRF elements (#479)

### Motivation:

`P384._VOPRF.BlindedElement(oprfRepresentation:)` accepts uncompressed
x9.63 encoded inputs, but RFC 9497 states
only inputs using compressed encoding should be accepted:

```
SerializeElement(A): Implemented using the compressed Elliptic-Curve-Point-to-Octet-String method...

DeserializeElement(buf): Implemented by attempting to deserialize a 49-byte array to a public key
                         using the compressed Octet-String-to-Elliptic-Curve-Point method...
```

### Modifications:

- Add input guard to only accept points using compressed representation.
- Extend the tests.

### Result:

- OPRF element deserialization accepts only the compressed encoding.
- Uncompressed encodings now throw
`CryptoKitError.incorrectParameterSize`.
This commit is contained in:
Si Beaumont authored and GitHub committed 2026-10-09 11:38:27 +00:00
1 parent 25847ff705
commit 1c80d3aff5
2 files changed
+20

No files matched your search

@@ -276,6 +276,9 @@ extension OpenSSLCurvePoint {
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
extension OpenSSLCurvePoint: OPRFGroupElement {
init(oprfRepresentation data: Data) throws {
guard data.count == C.compressedx962PointByteCount else {
throw CryptoKitError.incorrectParameterSize
}
let point = try EllipticCurvePoint(x962Representation: data, on: C.group, context: C.__ffac)
self.init(ecPoint: point)
}
@@ -79,4 +79,21 @@ final class VOPRFPublicAPITests: XCTestCase {
// [Server] Compute the PRF for the input, without blinding or proof generation.
let _: Data = try privateKey.evaluate(input)
}
func testBlindedElementRejectsUncompressedOPRFRepresentation() throws {
/// Check we only accept compressed encoded elements, as per RFC 9497:
///
/// > SerializeElement(A): Implemented using the compressed Elliptic-Curve-Point-to-Octet-String method...
/// >
/// > DeserializeElement(buf): Implemented by attempting to deserialize a 49-byte array to a public key
/// using the compressed Octet-String-to-Elliptic-Curve-Point method...
///
/// - See: https://www.rfc-editor.org/rfc/rfc9497.html#name-oprfp-384-sha-384
let publicKey = P384._VOPRF.PrivateKey().publicKey
let blindedElement = try publicKey.blind(Data("This is some input data".utf8)).blindedElement
let compressed = blindedElement.oprfRepresentation
let uncompressed = try P384.Signing.PublicKey(compressedRepresentation: compressed).x963Representation
XCTAssertThrowsError(try P384._VOPRF.BlindedElement(oprfRepresentation: uncompressed))
}
}