Hi there
TL;DR : I have a Data object which contains data that is already hashed. I need a Digest object, how should I proceed ?
I am developing an OSX Smart Card Token Extension to handle certificates linked to private keys in the Secure Enclave (using CryptoKit).
So far my first tests are pretty successful as my extension already answered to various signature requests successfully... until now.
So far I was receiving signature requests for ecdsaSignatureMessageX962SHA256 algorithm.
All I had to do with was something like this:
func tokenSession(_ session: TKTokenSession, sign dataToSign: Data, keyObjectID: Any, algorithm: TKTokenKeyAlgorithm) throws -> Data {
if let privateKey = try? SecureEnclave.P256.Signing.PrivateKey.init(dataRepresentation: keyObjectID as! Data) {
let rawsignature = try? privateKey.signature(for: dataToSign)
return rawsignature!.derRepresentation
}
}
Now I receive requests for ecdsaSignatureDigestX962SHA256 signatures. I noticed that there is a
public func signature<D>(for digest: D) throws -> P256.Signing.ECDSASignature where D : Digest
function that can be called but in the tokenSession i am only given Data...
Looking at SHA256Digest documentation I can't find anything to create the digest from bytes. It seems that it can only be the result of a SHA256.hash operation.
I thought of using older API like SecKeyCreateSignature but I don't think I can retrieve a SecKey from a private key generated with CryptoKit SecureEnclave.P256.Signing.PrivateKey.init
I feel like I may be missing something really simple...