예제 #1
0
static feeReturn ECDSA_decode(
    feeSigFormat format,          // Signature format DER 9.62 / RAW
    unsigned groupBytesLen,
    const unsigned char *sigData,
	size_t sigDataLen,
	giant *c,						// alloc'd  & RETURNED
	giant *d,						// alloc'd  & RETURNED
	unsigned *sigVersion)			// RETURNED
{
	#if	CRYPTKIT_DER_ENABLE
    feeReturn frtn;
    if (format==FSF_RAW) {
        frtn = feeRAWDecodeECDSASignature(groupBytesLen, sigData, sigDataLen, c, d);
    } else {
        frtn = feeDERDecodeECDSASignature(sigData, sigDataLen, c, d);
    }
	if(frtn == FR_Success) {
		*sigVersion = FEE_ECDSA_VERSION;
	}
	return frtn;
	#else
	int		magic;
	int		minVersion;
	int		rtn;

	rtn = byteRepToSig(sigData,
		sigDataLen,
		FEE_ECDSA_VERSION,
		&magic,
		(int *)sigVersion,
		&minVersion,
		c,
		d);
	if(rtn == 0) {
		return FR_BadSignatureFormat;
	}
	switch(magic) {
	    case FEE_ECDSA_MAGIC:
		return FR_Success;
	    case FEE_SIG_MAGIC:		// ElGamal sig!
	    	return FR_WrongSignatureType;
	    default:
	    	return FR_BadSignatureFormat;
	}
	#endif
}
/*
 * Obtain a feeSig object by parsing an existing signature block.
 * Note that if Pm is used to salt a hash of the signed data, this must
 * function must be called prior to hashing.
 */
feeReturn feeSigParse(const unsigned char *sigData,
	size_t sigDataLen,
	feeSig *sig)				// RETURNED
{
	sigInst		*sinst = NULL;
	feeReturn	frtn;
	#if	!CRYPTKIT_DER_ENABLE
	int			version;
	int			magic;
	int			minVersion;
	int			rtn;
	#endif
	
	sinst = sinstAlloc();
	#if		CRYPTKIT_DER_ENABLE
	frtn = feeDERDecodeElGamalSignature(sigData, sigDataLen, &sinst->u, &sinst->PmX);
	if(frtn) {
		goto abort;
	}
	#else
	rtn = byteRepToSig(sigData,
		sigDataLen,
		FEE_SIG_VERSION,
		&magic,
		&version,
		&minVersion,
		&sinst->u,
		&sinst->PmX);
	if(rtn == 0) {
		frtn = FR_BadSignatureFormat;
		goto abort;
	}
	switch(magic) {
	    case FEE_ECDSA_MAGIC:
	    	frtn = FR_WrongSignatureType;		// ECDSA!
		goto abort;
	    case FEE_SIG_MAGIC:
	    	break;					// proceed
	    default:
	    	frtn = FR_BadSignatureFormat;
		goto abort;
	}
	#endif		/* CRYPTKIT_DER_ENABLE */
	
	#if	SIG_DEBUG
	if(sigDebug) {
		printf("sigParse: \n");
		printf("u: ");
		printGiant(sinst->u);
	}
	#endif	// SIG_DEBUG

	*sig = sinst;
	return FR_Success;

abort:
	if(sinst) {
		feeSigFree(sinst);
	}
	return frtn;
}