Beispiel #1
0
Signature SignerReal::sign( PrivateKey privkey, Digest hash, Monitor& monitor )
{
	if (!check_interface(monitor)) return Signature();

	Parameters params = privkey.getAlgParams(acSign, Monitor());
	if (params) setAlgParams(params,monitor);

	Padder curpad = padder;
	if (privkey.getPadder(Monitor()))
	{
		curpad = privkey.getPadder(monitor);
	} else {
		//TODO: find default padder
	}

	Error error;
	if (random)
	{
		IRef<eprovider::ProviderInterface> randomer = creator.getCreatureCurrentInterface(random);
		if (randomer) iface->setRandom(session, randomer.cast<eprovider::RandomGenerator>().get(), error);
	}

	eprovider::TheKey thekey = creator.getCreatureCurrentTheKey(privkey);

	Size hashsize = iface->getMaxHashSize(thekey, error);
	if (curpad.ok() && hashsize.bits()) hash = curpad.pad(hash, hashsize, monitor); if (!monitor) return Signature();
	Data hashblock = hash.asData();

	eprovider::Block binsign;
	RECOVER_CALL( (binsign = iface->signHash(session, hashblock.get(), hashblock.size(), thekey, error)) );

	Snapshot snapshot = creator.createSnapshot(binsign.get(), binsign.size(), binsign.encid(), iface->getKeyId(kcSignature));
	return snapshot.reviveSignature(monitor);
}
Beispiel #2
0
Signature SignerReal::sign( PrivateKey privkey, const void* data, Size size, Monitor& monitor )
{
	if (!check_interface(monitor)) return Signature();
	if (!hasher)
	{
		// TODO: find default hasher for this sign algid
	}

	if (hasher)
	{
		Digest digest = hasher.hash(data,size,monitor);
		return sign(privkey,data,size,monitor);
	} else {
		eprovider::TheKey thekey = creator.getCreatureCurrentTheKey(privkey);

		eprovider::Block binsign;
		RECOVER_CALL( (iface->signStart(session, thekey, error)) );
		RECOVER_CALL( (iface->signProcess(session, data, size, error)) );
		RECOVER_CALL( (binsign = iface->signStop(session, error)) );

		Snapshot snapshot = creator.createSnapshot(binsign.get(), binsign.size(), binsign.encid(), iface->getKeyId(kcSignature));
		return snapshot.reviveSignature(monitor);
	}
}