I need to interact with Hyperledger Fabric in an iOS application, and I've run into a problem when creating the proposal signature. Fabric requires low-s ECDSA, but I can't find a way to specify that in Apple's crypto functions. Without specifying low-s, my calls fail about %50 of the time, when S is higher than R.
My signing code is pretty simple:
static func sign(data:Data, withPrivateKey:SecKey) throws -> Data {
var error: Unmanaged<CFError>?
guard
let signature = SecKeyCreateSignature(
withPrivateKey,
.ecdsaSignatureMessageX962SHA256,
data as CFData,
&error
) as Data?
else {
throw error!.takeRetainedValue()
}
return signature
}