Overview

Stream Ciphers are supported via the GordianCipherFactory interface.

GordianKnot supports most Symmetric Stream Ciphers available from BouncyCastle plus some additional ciphers.

A key for stream encryption is created by specifying the algorithm and keySize as a GordianStreamKeySpec.

A cipher for stream encryption is created by specifying the GordianStreamKeySpec (plus variant details eg AEAD) as a GordianStreamCipherSpec and can be used similarly to a blockCipher.

A keyGenerator for a GordianStreamKeySpec can be created, which can be used to generate random keys for the keySpec

JCA provides a subset of available algorithms as indicated

Key Generation

Algorithms are represented by GordianSymKeySpec. A GordianKeyGenerator is obtained via the keySpec, and then keys are generated by the generator.

Sample

                    /* Access factory */
                    final GordianFactory myBaseFactory = GordianGenerator.createFactory();
                    final GordianCipherFactory myCipherFactory = myBaseFactory.getCipherFactory();

                    /* Access keyGenerator */
                    final GordianStreamKeySpec mySpec = GordianStreamKeySpec.hc(GordianLength.LEN_256);
                    final GordianKeyGenerator<GordianStreamKeySpec> myGenerator = myCipherFactory.getKeyGenerator(mySpec);
                    final GordianKey<GordianStreamKeySpec> myKey = myGenerator.generateKey();
                

Algorithms

The following streamKey algorithms are supported.

Algorithm Variant JCA 128 192 256 512 1024 Notes
ChaCha20 Standard Y Y Y
ChaCha7359 Y Y
XChaCha20 Y
Salsa20 Standard Y Y Y
XSalsa20 Y Y
HC Y Y Y HC128/HC256 as appropriate
VMPC Y Y Y Y Y Y
ISAAC Y Y Y Y Y
RC4 Y Y Y Y Y Y
Grain128 Y Y
Rabbit Y
Sosemanuk Y
Snow3G Y
Zuc Y Y Zuc-128/Zuc-256 as appropriate
SkeinXof Skein-256 Y Y Y Y Y
Skein-512 Y Y Y Y Y
Skein-1024 Y Y Y Y Y
Blake2X Blake2Xs Y Y Y
Blake2Xb Y Y Y Y
Blake3Xof Y
KMACXof KMAC128 Y Y Y Y Y
KMAC256 Y Y Y

Cipher Usage

Cipher Algorithms are represented by GordianStreamCipherSpec. A GordianStreamCipher is obtained via the cipherSpec, and then messages are encrypted/decrypted by the cipher.

Sample

                    /* Access factory */
                    final GordianFactory myBaseFactory = GordianGenerator.createFactory();
                    final GordianCipherFactory myCipherFactory = myBaseFactory.getCipherFactory();

                    /* Create key */
                    final GordianStreamKeySpec myKeySpec = GordianStreamKeySpec.hc(GordianLength.LEN_256);
                    final GordianKeyGenerator<GordianStreamKeySpec> myGenerator = myCipherFactory.getKeyGenerator(myKeySpec);
                    final GordianKey<GordianStreamKeySpec> myKey = myGenerator.generateKey();

                    /* Create cipher */
                    final GordianStreamCipherSpec myCipherSpec = GordianStreamCipherSpec.stream(myKeySpec);
                    final GordianStreamCipher myCipher = myCipherFactory.createStreamKeyCipher(myCipherSpec);

                    /* Encrypt message with random nonce */
                    GordianCipherParameters myParams = GordianCipherParameters.keyWithRandomNonce(myKey);
                    myCipher.initForEncrypt(myParams);
                    final byte[] myMessage = ...
                    int myOutLen = myCipher.getOutputLength(myMessage.length);
                    final byte[] myEncrypted = new byte[myOutLen];
                    int myProcessed = myCipher.update(myMessage, 0, myMessage.length, myEncrypted);
                    myCipher.finish(myEncrypted, myProcessed);

                    /* Decrypt message */
                    myParams = GordianCipherParameters.keyWithNonce(myKey, myCipher.getNonce());
                    myCipher.initForDecrypt(myParams);
                    myOutLen = myCipher.getOutputLength(myEncrypted.length);
                    final byte[] myResult = new byte[myOutLen];
                    myProcessed = myCipher.update(myEncrypted, 0, myEncrypted.length, myResult);
                    myCipher.finish(myResult, myProcessed);