Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public class NativeCryptoEngine
- Object
- CryptoEngine
- 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.
Constructors
protected NativeCryptoEngine(CryptoEngine next) | Creates the engine over the one that handles what the kernels do not. |
Methods
Inherited fields
Inherited methods
Constructor details
NativeCryptoEngine
protected NativeCryptoEngine(CryptoEngine next)Creates the engine over the one that handles what the kernels do not.
Method details
create
public static CryptoEngine create(CryptoEngine next)This engine over
next when the kernels are linked, otherwise
next itself. Call it only on a ParparVM target: elsewhere the
native methods have no implementation.randomBytes
public boolean randomBytes(byte[] out)Fills
out with bytes from the platform’s CSPRNG, answering false when this engine
has no source. Every installed engine has one: the client’s draws on the port, the
backend’s on the server runtime.pbkdf2
public byte[] pbkdf2(String hashAlgorithm, byte[] password, byte[] salt, int iterations, int length)PBKDF2 (RFC 8018) with HMAC over
hashAlgorithm (Hash.SHA256 or
Hash.SHA512), or null to use the Java derivation. The arguments
are already validated.secpPublicKey
public byte[] secpPublicKey(byte[] privateKey, boolean compressed)A secp256k1 public key (
Secp256k1.publicKey), or null to derive it
in Java. The private key has not been range checked: answer null
for one that is out of range and Java reports the error.secpSign
public byte[] secpSign(byte[] hash, byte[] privateKey)An ECDSA signature over a 32-byte hash as
r || s || recoveryId
(65 bytes, RFC 6979 nonce, low S), or null to sign in Java.secpVerify
public int secpVerify(byte[] hash, byte[] compactSignature, byte[] publicKey)An ECDSA verification of
r || s (64 bytes): 1 valid, 0 invalid, or
-1 to verify in Java.secpRecover
public byte[] secpRecover(byte[] hash, byte[] compactSignature, int recoveryId, boolean compressed)The public key recovered from
r || s and a recovery id, or null
to recover in Java (which also decides that no key exists).secpPrivateKeyTweakAdd
public byte[] secpPrivateKeyTweakAdd(byte[] privateKey, byte[] tweak)(privateKey + tweak) mod n, or null to compute it in Java.secpPublicKeyTweakAdd
public byte[] secpPublicKeyTweakAdd(byte[] publicKey, byte[] tweak, boolean compressed)publicKey + tweak * G, or null to compute it in Java.schnorrPublicKey
public byte[] schnorrPublicKey(byte[] privateKey)A BIP-340 x-only public key, or
null to derive it in Java.schnorrSign
public byte[] schnorrSign(byte[] message, byte[] privateKey, byte[] auxRand)A BIP-340 signature;
auxRand is 32 bytes or null for zeros.
Answers null to sign in Java.schnorrVerify
public int schnorrVerify(byte[] message, byte[] signature, byte[] publicKey)A BIP-340 verification: 1 valid, 0 invalid, or -1 to verify in Java.
The key is 32 bytes and the signature 64.
ed25519PublicKey
public byte[] ed25519PublicKey(byte[] privateKey)The Ed25519 public key of a 32-byte seed, or
null to derive it in
Java.ed25519Sign
public byte[] ed25519Sign(byte[] privateKey, byte[] publicKey, byte[] message)An Ed25519 signature ([Ed25519#sign(byte[], byte[], byte[])]), or
null to sign in Java. The arguments are already validated.ed25519Verify
public int ed25519Verify(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.
keccak256
public byte[] keccak256(byte[] data)Keccak-256 of
data, or null to hash in Java.sha256
public byte[] sha256(byte[] data, int offset, int length)SHA-256 of
length bytes of data from offset, or null to hash
in Java. The range is already validated.sha512
public byte[] sha512(byte[] data, int offset, int length)SHA-512 of a range of
data, or null to hash in Java.ripemd160
public byte[] ripemd160(byte[] data, int offset, int length)RIPEMD-160 of a range of
data, or null to hash in Java.hmac
public byte[] hmac(String hashAlgorithm, byte[] key, byte[] data)HMAC over
hashAlgorithm (Hash.SHA256 or Hash.SHA512), or null
to compute it in Java. Neither array is null.verifyBatch
public void verifyBatch(int algorithm, byte[][] messages, byte[][] signatures, byte[][] publicKeys, byte[] results)Verifies a batch of signatures of one algorithm (
BATCH_SECP256K1,
BATCH_SCHNORR, BATCH_ED25519). Only the entries whose result
byte is 2 are to be verified: the engine writes 1 (valid), 0
(invalid) or 0xff (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.verifyPacked
public void verifyPacked(int algorithm, byte[] messages, int messageLength, byte[] signatures, byte[] keys, int keyLength, byte[] results, int count)verifyBatch over packed arrays: entry i is messageLength bytes
of messages from messageLength * i, 64 bytes of signatures from
64 * i and keyLength bytes of keys from keyLength * i. The same
result bytes as verifyBatch, and every range is already validated.
An engine that can should read the arrays in place.hashPacked
public boolean hashPacked(String algorithm, byte[] inputs, int inputLength, int count, byte[] digests)hashBatch over packed arrays: digest i is of inputLength bytes of
inputs from inputLength * i, written at 32 * i of digests.
Answers false to hash in Java. The ranges are already validated.hashBatch
public byte[][] hashBatch(String algorithm, byte[][] inputs)The digests of
inputs under Hash.SHA256 or Hash.KECCAK256, a
null for each null input, or null to hash them in Java.