Class NativeCryptoEngine
java.lang.Object
com.codename1.security.CryptoEngine
com.codename1.security.NativeCryptoEngine
The CryptoEngine of the ParparVM targets (iOS, macOS, native Windows and
Linux, and the backend): secp256k1, Schnorr, Ed25519 and Keccak run in
the linked C kernels, everything else goes to the engine it wraps.
The kernels are linked only into a build whose classes use these APIs,
so a port creates this engine through create(CryptoEngine), which
answers the wrapped engine when they are absent.
-
Field Summary
Fields inherited from class CryptoEngine
BATCH_ED25519, BATCH_SCHNORR, BATCH_SECP256K1 -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates the engine over the one that handles what the kernels do not. -
Method Summary
Modifier and TypeMethodDescriptionstatic CryptoEnginecreate(CryptoEngine next) This engine overnextwhen the kernels are linked, otherwisenextitself.byte[]ed25519PublicKey(byte[] privateKey) The Ed25519 public key of a 32-byte seed, ornullto derive it in Java.byte[]ed25519Sign(byte[] privateKey, byte[] publicKey, byte[] message) An Ed25519 signature ([Ed25519#sign(byte[], byte[], byte[])]), ornullto sign in Java.inted25519Verify(byte[] message, byte[] signature, byte[] publicKey) An Ed25519 verification: 1 for a valid signature, 0 for an invalid one, or -1 to verify in Java.byte[][]The digests ofinputsunderHash.SHA256orHash.KECCAK256, anullfor eachnullinput, ornullto hash them in Java.booleanhashPacked(String algorithm, byte[] inputs, int inputLength, int count, byte[] digests) CryptoEngine.hashBatch(String, byte[][])over packed arrays: digestiis ofinputLengthbytes ofinputsfrominputLength * i, written at32 * iofdigests.byte[]byte[]keccak256(byte[] data) Keccak-256 ofdata, ornullto hash in Java.byte[]PBKDF2 (RFC 8018) with HMAC overhashAlgorithm(Hash.SHA256orHash.SHA512), ornullto use the Java derivation.booleanrandomBytes(byte[] out) Fillsoutwith bytes from the platform's CSPRNG, answeringfalsewhen this engine has no source.byte[]ripemd160(byte[] data, int offset, int length) RIPEMD-160 of a range ofdata, ornullto hash in Java.byte[]schnorrPublicKey(byte[] privateKey) A BIP-340 x-only public key, ornullto derive it in Java.byte[]schnorrSign(byte[] message, byte[] privateKey, byte[] auxRand) A BIP-340 signature;auxRandis 32 bytes ornullfor zeros.intschnorrVerify(byte[] message, byte[] signature, byte[] publicKey) A BIP-340 verification: 1 valid, 0 invalid, or -1 to verify in Java.byte[]secpPrivateKeyTweakAdd(byte[] privateKey, byte[] tweak) (privateKey + tweak) mod n, ornullto compute it in Java.byte[]secpPublicKey(byte[] privateKey, boolean compressed) A secp256k1 public key (Secp256k1.publicKey(byte[], boolean)), ornullto derive it in Java.byte[]secpPublicKeyTweakAdd(byte[] publicKey, byte[] tweak, boolean compressed) publicKey + tweak * G, ornullto compute it in Java.byte[]secpRecover(byte[] hash, byte[] compactSignature, int recoveryId, boolean compressed) The public key recovered fromr || sand a recovery id, ornullto recover in Java (which also decides that no key exists).byte[]secpSign(byte[] hash, byte[] privateKey) An ECDSA signature over a 32-byte hash asr || s || recoveryId(65 bytes, RFC 6979 nonce, low S), ornullto sign in Java.intsecpVerify(byte[] hash, byte[] compactSignature, byte[] publicKey) An ECDSA verification ofr || s(64 bytes): 1 valid, 0 invalid, orbyte[]sha256(byte[] data, int offset, int length) SHA-256 oflengthbytes ofdatafromoffset, ornullto hash in Java.byte[]sha512(byte[] data, int offset, int length) SHA-512 of a range ofdata, ornullto hash in Java.voidverifyBatch(int algorithm, byte[][] messages, byte[][] signatures, byte[][] publicKeys, byte[] results) Verifies a batch of signatures of one algorithm (CryptoEngine.BATCH_SECP256K1,CryptoEngine.BATCH_SCHNORR,CryptoEngine.BATCH_ED25519).voidverifyPacked(int algorithm, byte[] messages, int messageLength, byte[] signatures, byte[] keys, int keyLength, byte[] results, int count) CryptoEngine.verifyBatch(int, byte[][], byte[][], byte[][], byte[])over packed arrays: entryiismessageLengthbytes ofmessagesfrommessageLength * i, 64 bytes ofsignaturesfrom64 * iandkeyLengthbytes ofkeysfromkeyLength * i.Methods inherited from class CryptoEngine
deliver, get, gpuRecord, gpuRecordWords, install, random, runInBackground
-
Constructor Details
-
NativeCryptoEngine
Creates the engine over the one that handles what the kernels do not.
-
-
Method Details
-
create
This engine overnextwhen the kernels are linked, otherwisenextitself. Call it only on a ParparVM target: elsewhere the native methods have no implementation. -
randomBytes
public boolean randomBytes(byte[] out) Description copied from class:CryptoEngineFillsoutwith bytes from the platform's CSPRNG, answeringfalsewhen this engine has no source. Every installed engine has one: the client's draws on the port, the backend's on the server runtime.- Overrides:
randomBytesin classCryptoEngine
-
pbkdf2
public byte[] pbkdf2(String hashAlgorithm, byte[] password, byte[] salt, int iterations, int length) Description copied from class:CryptoEnginePBKDF2 (RFC 8018) with HMAC overhashAlgorithm(Hash.SHA256orHash.SHA512), ornullto use the Java derivation. The arguments are already validated.- Overrides:
pbkdf2in classCryptoEngine
-
secpPublicKey
public byte[] secpPublicKey(byte[] privateKey, boolean compressed) Description copied from class:CryptoEngineA secp256k1 public key (Secp256k1.publicKey(byte[], boolean)), ornullto derive it in Java. The private key has not been range checked: answernullfor one that is out of range and Java reports the error.- Overrides:
secpPublicKeyin classCryptoEngine
-
secpSign
public byte[] secpSign(byte[] hash, byte[] privateKey) Description copied from class:CryptoEngineAn ECDSA signature over a 32-byte hash asr || s || recoveryId(65 bytes, RFC 6979 nonce, low S), ornullto sign in Java.- Overrides:
secpSignin classCryptoEngine
-
secpVerify
public int secpVerify(byte[] hash, byte[] compactSignature, byte[] publicKey) Description copied from class:CryptoEngineAn ECDSA verification ofr || s(64 bytes): 1 valid, 0 invalid, or -1 to verify in Java.- Overrides:
secpVerifyin classCryptoEngine
-
secpRecover
public byte[] secpRecover(byte[] hash, byte[] compactSignature, int recoveryId, boolean compressed) Description copied from class:CryptoEngineThe public key recovered fromr || sand a recovery id, ornullto recover in Java (which also decides that no key exists).- Overrides:
secpRecoverin classCryptoEngine
-
secpPrivateKeyTweakAdd
public byte[] secpPrivateKeyTweakAdd(byte[] privateKey, byte[] tweak) Description copied from class:CryptoEngine(privateKey + tweak) mod n, ornullto compute it in Java.- Overrides:
secpPrivateKeyTweakAddin classCryptoEngine
-
secpPublicKeyTweakAdd
public byte[] secpPublicKeyTweakAdd(byte[] publicKey, byte[] tweak, boolean compressed) Description copied from class:CryptoEnginepublicKey + tweak * G, ornullto compute it in Java.- Overrides:
secpPublicKeyTweakAddin classCryptoEngine
-
schnorrPublicKey
public byte[] schnorrPublicKey(byte[] privateKey) Description copied from class:CryptoEngineA BIP-340 x-only public key, ornullto derive it in Java.- Overrides:
schnorrPublicKeyin classCryptoEngine
-
schnorrSign
public byte[] schnorrSign(byte[] message, byte[] privateKey, byte[] auxRand) Description copied from class:CryptoEngineA BIP-340 signature;auxRandis 32 bytes ornullfor zeros. Answersnullto sign in Java.- Overrides:
schnorrSignin classCryptoEngine
-
schnorrVerify
public int schnorrVerify(byte[] message, byte[] signature, byte[] publicKey) Description copied from class:CryptoEngineA BIP-340 verification: 1 valid, 0 invalid, or -1 to verify in Java. The key is 32 bytes and the signature 64.- Overrides:
schnorrVerifyin classCryptoEngine
-
ed25519PublicKey
public byte[] ed25519PublicKey(byte[] privateKey) Description copied from class:CryptoEngineThe Ed25519 public key of a 32-byte seed, ornullto derive it in Java.- Overrides:
ed25519PublicKeyin classCryptoEngine
-
ed25519Sign
public byte[] ed25519Sign(byte[] privateKey, byte[] publicKey, byte[] message) Description copied from class:CryptoEngineAn Ed25519 signature ([Ed25519#sign(byte[], byte[], byte[])]), ornullto sign in Java. The arguments are already validated.- Overrides:
ed25519Signin classCryptoEngine
-
ed25519Verify
public int ed25519Verify(byte[] message, byte[] signature, byte[] publicKey) Description copied from class:CryptoEngineAn Ed25519 verification: 1 for a valid signature, 0 for an invalid one, or -1 to verify in Java.- Overrides:
ed25519Verifyin classCryptoEngine
-
keccak256
public byte[] keccak256(byte[] data) Description copied from class:CryptoEngineKeccak-256 ofdata, ornullto hash in Java.- Overrides:
keccak256in classCryptoEngine
-
sha256
public byte[] sha256(byte[] data, int offset, int length) Description copied from class:CryptoEngineSHA-256 oflengthbytes ofdatafromoffset, ornullto hash in Java. The range is already validated.- Overrides:
sha256in classCryptoEngine
-
sha512
public byte[] sha512(byte[] data, int offset, int length) Description copied from class:CryptoEngineSHA-512 of a range ofdata, ornullto hash in Java.- Overrides:
sha512in classCryptoEngine
-
ripemd160
public byte[] ripemd160(byte[] data, int offset, int length) Description copied from class:CryptoEngineRIPEMD-160 of a range ofdata, ornullto hash in Java.- Overrides:
ripemd160in classCryptoEngine
-
hmac
Description copied from class:CryptoEngineHMAC overhashAlgorithm(Hash.SHA256orHash.SHA512), ornullto compute it in Java. Neither array is null.- Overrides:
hmacin classCryptoEngine
-
verifyBatch
public void verifyBatch(int algorithm, byte[][] messages, byte[][] signatures, byte[][] publicKeys, byte[] results) Description copied from class:CryptoEngineVerifies a batch of signatures of one algorithm (CryptoEngine.BATCH_SECP256K1,CryptoEngine.BATCH_SCHNORR,CryptoEngine.BATCH_ED25519). Only the entries whose result byte is 2 are to be verified: the engine writes 1 (valid), 0 (invalid) or0xff(verify this one in Java) over them, and leaves any it does not reach at 2, which the caller also verifies in Java. Those entries have non-null arrays; signatures are 64 bytes, messages 32 for ECDSA, keys 32 except for ECDSA's SEC1 keys.- Overrides:
verifyBatchin classCryptoEngine
-
verifyPacked
public void verifyPacked(int algorithm, byte[] messages, int messageLength, byte[] signatures, byte[] keys, int keyLength, byte[] results, int count) Description copied from class:CryptoEngineCryptoEngine.verifyBatch(int, byte[][], byte[][], byte[][], byte[])over packed arrays: entryiismessageLengthbytes ofmessagesfrommessageLength * i, 64 bytes ofsignaturesfrom64 * iandkeyLengthbytes ofkeysfromkeyLength * i. The same result bytes asCryptoEngine.verifyBatch(int, byte[][], byte[][], byte[][], byte[]), and every range is already validated. An engine that can should read the arrays in place.- Overrides:
verifyPackedin classCryptoEngine
-
hashPacked
public boolean hashPacked(String algorithm, byte[] inputs, int inputLength, int count, byte[] digests) Description copied from class:CryptoEngineCryptoEngine.hashBatch(String, byte[][])over packed arrays: digestiis ofinputLengthbytes ofinputsfrominputLength * i, written at32 * iofdigests. Answers false to hash in Java. The ranges are already validated.- Overrides:
hashPackedin classCryptoEngine
-
hashBatch
Description copied from class:CryptoEngineThe digests ofinputsunderHash.SHA256orHash.KECCAK256, anullfor eachnullinput, ornullto hash them in Java.- Overrides:
hashBatchin classCryptoEngine
-