Search in sources :

Example 1 with CryptoEngine

use of com.swirlds.common.crypto.engine.CryptoEngine in project hedera-services by hashgraph.

the class HederaKeyActivationTest method canMatchCompressedEcdsaSecp256k1Key.

@Test
void canMatchCompressedEcdsaSecp256k1Key() throws Exception {
    final var mockTxnBytes = "012345789012345789012345789012345789012345789012345789012345789012345789012345789012345789".getBytes();
    final var explicitList = keyList.getKeyList().getKeysList();
    final var secp256k1Key = explicitList.get(0);
    final var ed25519Key = explicitList.get(1);
    final var keyFactory = KeyFactory.getDefaultInstance();
    final var mockSigs = mock(PubKeyToSigBytes.class);
    given(mockSigs.sigBytesFor(explicitList.get(0).getECDSASecp256k1Key())).willReturn(signBytes(keccak256DigestOf(mockTxnBytes), keyFactory.lookupPrivateKey(hex(secp256k1Key.getECDSASecp256k1Key()))));
    given(mockSigs.sigBytesFor(explicitList.get(1).getEd25519())).willReturn(signBytes(mockTxnBytes, keyFactory.lookupPrivateKey(hex(ed25519Key.getEd25519()))));
    final var accessor = mock(TxnAccessor.class);
    given(accessor.getTxnBytes()).willReturn(mockTxnBytes);
    final var cryptoSigs = createCryptoSigsFrom(explicitList, mockSigs, new ReusableBodySigningFactory(accessor)).getPlatformSigs();
    new CryptoEngine().verifySync(cryptoSigs);
    final var subject = pkToSigMapFrom(cryptoSigs);
    final var ed25519Sig = subject.apply(ed25519Key.getEd25519());
    assertEquals(SignatureType.ED25519, ed25519Sig.getSignatureType());
    assertEquals(VerificationStatus.VALID, ed25519Sig.getSignatureStatus());
    final var secp256k1Sig = subject.apply(secp256k1Key.getECDSASecp256k1Key());
    assertEquals(SignatureType.ECDSA_SECP256K1, secp256k1Sig.getSignatureType());
}
Also used : CryptoEngine(com.swirlds.common.crypto.engine.CryptoEngine) ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory) Test(org.junit.jupiter.api.Test)

Example 2 with CryptoEngine

use of com.swirlds.common.crypto.engine.CryptoEngine in project hedera-services by hashgraph.

the class SigOpsRegressionTest method invokeRationalizationScenario.

private Rationalization invokeRationalizationScenario() {
    // setup:
    SyncVerifier syncVerifier = new CryptoEngine()::verifySync;
    final var hfsSigMetaLookup = new HfsSigMetaLookup(hfs, fileNumbers);
    SigMetadataLookup sigMetaLookups = defaultLookupsFor(aliasManager, hfsSigMetaLookup, () -> accounts, () -> null, ref -> null, ref -> null);
    SigRequirements keyOrder = new SigRequirements(sigMetaLookups, mockSignatureWaivers);
    // given:
    final var rationalization = new Rationalization(syncVerifier, keyOrder, new ReusableBodySigningFactory());
    rationalization.performFor(platformTxn);
    return rationalization;
}
Also used : SyncVerifier(com.hedera.services.sigs.verification.SyncVerifier) SigRequirements(com.hedera.services.sigs.order.SigRequirements) CryptoEngine(com.swirlds.common.crypto.engine.CryptoEngine) HfsSigMetaLookup(com.hedera.services.sigs.metadata.lookups.HfsSigMetaLookup) SigMetadataLookup(com.hedera.services.sigs.metadata.SigMetadataLookup) ReusableBodySigningFactory(com.hedera.services.sigs.factories.ReusableBodySigningFactory)

Example 3 with CryptoEngine

use of com.swirlds.common.crypto.engine.CryptoEngine in project hedera-services by hashgraph.

the class SigVerifierRegressionTest method setupFor.

private void setupFor(TxnHandlingScenario scenario) throws Throwable {
    accounts = scenario.accounts();
    platformTxn = scenario.platformTxn();
    aliasManager = mock(AliasManager.class);
    keyOrder = new SigRequirements(defaultLookupsFor(aliasManager, null, () -> accounts, () -> null, ref -> null, ref -> null), mockSignatureWaivers);
    final var nodeInfo = mock(NodeInfo.class);
    given(nodeInfo.selfAccount()).willReturn(DEFAULT_NODE);
    isQueryPayment = PrecheckUtils.queryPaymentTestFor(nodeInfo);
    SyncVerifier syncVerifier = new CryptoEngine()::verifySync;
    precheckKeyReqs = new PrecheckKeyReqs(keyOrder, isQueryPayment);
    precheckVerifier = new PrecheckVerifier(syncVerifier, precheckKeyReqs);
}
Also used : SyncVerifier(com.hedera.services.sigs.verification.SyncVerifier) AliasManager(com.hedera.services.ledger.accounts.AliasManager) SigRequirements(com.hedera.services.sigs.order.SigRequirements) PrecheckKeyReqs(com.hedera.services.sigs.verification.PrecheckKeyReqs) PrecheckVerifier(com.hedera.services.sigs.verification.PrecheckVerifier) CryptoEngine(com.swirlds.common.crypto.engine.CryptoEngine)

Aggregations

CryptoEngine (com.swirlds.common.crypto.engine.CryptoEngine)3 ReusableBodySigningFactory (com.hedera.services.sigs.factories.ReusableBodySigningFactory)2 SigRequirements (com.hedera.services.sigs.order.SigRequirements)2 SyncVerifier (com.hedera.services.sigs.verification.SyncVerifier)2 AliasManager (com.hedera.services.ledger.accounts.AliasManager)1 SigMetadataLookup (com.hedera.services.sigs.metadata.SigMetadataLookup)1 HfsSigMetaLookup (com.hedera.services.sigs.metadata.lookups.HfsSigMetaLookup)1 PrecheckKeyReqs (com.hedera.services.sigs.verification.PrecheckKeyReqs)1 PrecheckVerifier (com.hedera.services.sigs.verification.PrecheckVerifier)1 Test (org.junit.jupiter.api.Test)1