/* * Encode to/from byteRep. */ static void ECDSA_encode( feeSigFormat format, // Signature format DER 9.62 / RAW unsigned groupBytesLen, giant c, giant d, unsigned char **sigData, // malloc'd and RETURNED unsigned *sigDataLen) // RETURNED { #if CRYPTKIT_DER_ENABLE if (format==FSF_RAW) { feeRAWEncodeECDSASignature(groupBytesLen,c, d, sigData, sigDataLen); } else { feeDEREncodeECDSASignature(c, d, sigData, sigDataLen); } #else *sigDataLen = lengthOfByteRepSig(c, d); *sigData = (unsigned char*) fmalloc(*sigDataLen); sigToByteRep(FEE_ECDSA_MAGIC, FEE_ECDSA_VERSION, FEE_ECDSA_VERSION_MIN, c, d, *sigData); #endif }
/* * For given key, calculate maximum signature size. */ feeReturn feeSigSize( feePubKey pubKey, unsigned *maxSigLen) { /* For now, assume that u and Pm.x in the signature are * same size as the key's associated curveParams->basePrime. * We might have to pad this a bit.... */ curveParams *cp = feePubKeyCurveParams(pubKey); if(cp == NULL) { return FR_BadPubKey; } #if CRYPTKIT_DER_ENABLE *maxSigLen = feeSizeOfDERSig(cp->basePrime, cp->basePrime); #else *maxSigLen = (unsigned)lengthOfByteRepSig(cp->basePrime, cp->basePrime); #endif return FR_Success; }
/* * Given a feeSig processed by feeSigSign, obtain a malloc'd byte * array representing the signature. * See ByteRep.doc for info on the format of the signature string; * PLEASE UPDATE THIS DOCUMENT WHEN YOU MAKE CHANGES TO THE STRING FORMAT. */ feeReturn feeSigData(feeSig sig, unsigned char **sigData, // IGNORED....malloc'd and RETURNED unsigned *sigDataLen) // RETURNED { sigInst *sinst = (sigInst*) sig; #if CRYPTKIT_DER_ENABLE return feeDEREncodeElGamalSignature(sinst->u, sinst->PmX, sigData, sigDataLen); #else *sigDataLen = lengthOfByteRepSig(sinst->u, sinst->PmX); *sigData = (unsigned char*) fmalloc(*sigDataLen); sigToByteRep(FEE_SIG_MAGIC, FEE_SIG_VERSION, FEE_SIG_VERSION_MIN, sinst->u, sinst->PmX, *sigData); return FR_Success; #endif }