in TPM Parser/Tpm2Lib/CryptoAsym.cs [309:363]
public ISignatureUnion SignData(byte[] data, TpmAlgId sigHash)
{
var rsaParams = PublicParms.parameters as RsaParms;
if (rsaParams != null)
{
TpmAlgId sigScheme = rsaParams.scheme.GetUnionSelector();
switch (sigScheme)
{
case TpmAlgId.Rsassa:
{
if (sigHash == TpmAlgId.Null)
{
sigHash = (rsaParams.scheme as SigSchemeRsassa).hashAlg;
}
byte[] digest = CryptoLib.HashData(sigHash, data);
IBuffer sigBuffer = CryptographicEngine.SignHashedData(Key, CryptographicBuffer.CreateFromByteArray(digest));
byte[] sig;
CryptographicBuffer.CopyToByteArray(sigBuffer, out sig);
return new SignatureRsassa(sigHash, sig);
}
case TpmAlgId.Rsapss:
{
Globs.Throw<ArgumentException>("SignData(): PSS scheme is not supported");
return null;
}
}
Globs.Throw<ArgumentException>("Unsupported signature scheme");
return null;
}
var eccParms = PublicParms.parameters as EccParms;
if (eccParms != null)
{
if (eccParms.scheme.GetUnionSelector() != TpmAlgId.Ecdsa)
{
Globs.Throw<ArgumentException>("Unsupported ECC sig scheme");
return null;
}
if (sigHash == TpmAlgId.Null)
{
sigHash = (eccParms.scheme as SigSchemeEcdsa).hashAlg;
}
byte[] digest = CryptoLib.HashData(sigHash, data);
IBuffer buf = CryptographicEngine.SignHashedData(Key, CryptographicBuffer.CreateFromByteArray(digest));
byte[] sig;
CryptographicBuffer.CopyToByteArray(buf, out sig);
int len = sig.Length / 2;
return new SignatureEcdsa(sigHash, Globs.CopyData(sig, 0, len), Globs.CopyData(sig, len, len));
}
// Should never be here
Globs.Throw("VerifySignature: Unrecognized asymmetric algorithm");
return null;
} // SignData()