/** Sign a hash with DSA @param in The hash to sign @param inlen The length of the hash to sign @param out [out] Where to store the signature @param outlen [in/out] The max size and resulting size of the signature @param prng An active PRNG state @param wprng The index of the PRNG desired @param key A private DSA key @return CRYPT_OK if successful */ int dsa_sign_hash(const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen, prng_state *prng, int wprng, dsa_key *key) { void *r, *s; int err; LTC_ARGCHK(in != NULL); LTC_ARGCHK(out != NULL); LTC_ARGCHK(outlen != NULL); LTC_ARGCHK(key != NULL); if (mp_init_multi(&r, &s, NULL) != CRYPT_OK) { return CRYPT_MEM; } if ((err = dsa_sign_hash_raw(in, inlen, r, s, prng, wprng, key)) != CRYPT_OK) { goto error; } err = der_encode_sequence_multi(out, outlen, LTC_ASN1_INTEGER, 1UL, r, LTC_ASN1_INTEGER, 1UL, s, LTC_ASN1_EOL, 0UL, NULL); error: mp_clear_multi(r, s, NULL); return err; }
static int rpmltcSignDSA(pgpDig dig) /*@*/ { rpmltc ltc = dig->impl; int rc = 0; /* assume failure */ int xx; if (ltc->digest == NULL || ltc->digestlen == 0) goto exit; _initBN(ltc->r); _initBN(ltc->s); rc = rpmltcErr(ltc, "dsa_sign_hash_raw", dsa_sign_hash_raw(ltc->digest, ltc->digestlen, ltc->r, ltc->s, &yarrow_prng, find_prng("yarrow"), <c->dsa)); #ifdef DYING rpmltcDumpDSA(__FUNCTION__, ltc); #endif rc = (rc == CRYPT_OK); exit: SPEW(!rc, rc, dig); return rc; }