CPD Results

The following document contains the results of PMD's CPD 7.20.0.

Duplications

File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianBlake2Tree.java 597
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianSkeinTree.java 668
theDigest.doFinal(theResult, 0);
            myLevel.setElementAt(Arrays.clone(theResult), myParentIndex);
            return myParentIndex;
        }
    }

    /**
     * Simple Vector class.
     * <p>This is a cut down version of the java Vector class to avoid use of synchronised.
     */
    private static class SimpleVector {
        /**
         * The initial capacity.
         */
        private static final int INITCAPACITY = 8;

        /**
         * The array buffer holding elements.
         */
        private Object[] elementData;

        /**
         * The number of valid components in this {@code SimpleVector} object.
         */
        private int elementCount;

        /**
         * Constructor.
         */
        SimpleVector() {
            elementData = new Object[INITCAPACITY];
        }

        /**
         * Returns the number of components in this vector.
         *
         * @return the vector size
         */
        int size() {
            return elementCount;
        }

        /**
         * Tests if this vector has no components.
         *
         * @return true/false
         */
        boolean isEmpty() {
            return elementCount == 0;
        }

        /**
         * Returns the first component of the vector.
         *
         * @return the first component of the vector
         * @throws NoSuchElementException if this vector is empty
         */
        Object firstElement() {
            if (elementCount == 0) {
                throw new NoSuchElementException();
            }
            return elementData[0];
        }

        /**
         * Returns the last component of the vector.
         *
         * @return the last component of the vector, i.e., the component at index
         * <code>size()&nbsp;-&nbsp;1</code>.
         * @throws NoSuchElementException if this vector is empty
         */
        Object lastElement() {
            if (elementCount == 0) {
                throw new NoSuchElementException();
            }
            return elementData[elementCount - 1];
        }

        /**
         * Returns the component at the specified index.
         *
         * @param index an index into this vector
         * @return the component at the specified index
         * @throws ArrayIndexOutOfBoundsException if the index is out of range
         *                                        ({@code index < 0 || index >= size()})
         */
        Object elementAt(final int index) {
            if (index >= elementCount) {
                throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);
            }

            return elementData[index];
        }

        /**
         * Sets the component at the specified {@code index} of this
         * vector to be the specified object. The previous component at that
         * position is discarded.
         *
         * <p>The index must be a value greater than or equal to {@code 0}
         * and less than the current size of the vector.
         *
         * @param obj   what the component is to be set to
         * @param index the specified index
         * @throws ArrayIndexOutOfBoundsException if the index is out of range
         *                                        ({@code index < 0 || index >= size()})
         */
        void setElementAt(final Object obj,
                          final int index) {
            if (index >= elementCount) {
                throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);
            }
            elementData[index] = obj;
        }

        /**
         * Adds the specified component to the end of this vector,
         * increasing its size by one. The capacity of this vector is
         * increased if its size becomes greater than its capacity.
         *
         * @param obj the component to be added
         */
        void addElement(final Object obj) {
            if (elementCount == elementData.length) {
                final Object[] newData = new Object[elementData.length << 1];
                System.arraycopy(elementData, 0, newData, 0, elementCount);
                elementData = newData;
            }
            elementData[elementCount++] = obj;
        }

        /**
         * Removes all of the elements from this Vector.  The Vector will
         * be empty after this call returns (unless it throws an exception).
         */
        void clear() {
            for (int i = 0; i < elementCount; i++) {
                elementData[i] = null;
            }
            elementCount = 0;
        }

        /**
         * Returns an enumeration of the components of this vector.
         *
         * @return the enumeration
         */
        Enumeration<Object> elements() {
            return new Enumeration<>() {
                private int count;

                public boolean hasMoreElements() {
                    return count < elementCount;
                }

                public Object nextElement() {
                    if (count < elementCount) {
                        return elementData[count++];
                    }
                    throw new NoSuchElementException("Vector Enumeration");
                }
            };
        }
    }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\jca\JcaEncryptor.java 72
io\github\tonywasher\joceanus\gordianknot\impl\jca\JcaEncryptor.java 240
JcaBlockEncryptor(final GordianBaseFactory pFactory,
                          final GordianEncryptorSpec pSpec) throws GordianException {
            /* Initialise underlying cipher */
            super(pFactory, pSpec);
            theEncryptor = getJavaEncryptor(getAlgorithmName(pSpec), false);
        }

        @Override
        protected JcaPublicKey getPublicKey() {
            return (JcaPublicKey) super.getPublicKey();
        }

        @Override
        protected JcaPrivateKey getPrivateKey() {
            return (JcaPrivateKey) super.getPrivateKey();
        }

        @Override
        public void initForEncrypt(final GordianKeyPair pKeyPair) throws GordianException {
            try {
                /* Initialise underlying cipher */
                JcaKeyPair.checkKeyPair(pKeyPair);
                super.initForEncrypt(pKeyPair);

                /* Initialise for encryption */
                theEncryptor.init(Cipher.ENCRYPT_MODE, getPublicKey().getPublicKey(), getRandom());
            } catch (InvalidKeyException e) {
                throw new GordianCryptoException(ERROR_INIT, e);
            }
        }

        @Override
        public void initForDecrypt(final GordianKeyPair pKeyPair) throws GordianException {
            try {
                /* Initialise underlying cipher */
                JcaKeyPair.checkKeyPair(pKeyPair);
                super.initForDecrypt(pKeyPair);

                /* Initialise for decryption */
                theEncryptor.init(Cipher.DECRYPT_MODE, getPrivateKey().getPrivateKey());
            } catch (InvalidKeyException e) {
                throw new GordianCryptoException(ERROR_INIT, e);
            }
        }

        @Override
        public byte[] encrypt(final byte[] pBytes) throws GordianException {
            /* Check that we are in encryption mode */
            checkMode(GordianEncryptMode.ENCRYPT);

            /* Encrypt the message */
            return processData(pBytes);
        }

        @Override
        public byte[] decrypt(final byte[] pBytes) throws GordianException {
            /* Check that we are in decryption mode */
            checkMode(GordianEncryptMode.DECRYPT);

            /* Decrypt the message */
            return processData(pBytes);
        }

        /**
         * Process a data buffer.
         *
         * @param pData the buffer to process
         * @return the processed buffer
         * @throws GordianException on error
         */
        private byte[] processData(final byte[] pData) throws GordianException {
            try {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyDSTUKeyPair.java 347
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyEllipticKeyPair.java 360
theCoder = new BouncyDSTUCoder();
        }

        @Override
        public void initForSigning(final GordianSignParams pParams) throws GordianException {
            /* Initialise detail */
            super.initForSigning(pParams);
            final BouncyKeyPair myPair = getKeyPair();
            BouncyKeyPair.checkKeyPair(myPair);

            /* Initialise and set the signer */
            final BouncyECPrivateKey myPrivate = (BouncyECPrivateKey) myPair.getPrivateKey();
            final ParametersWithRandom myParms = new ParametersWithRandom(myPrivate.getPrivateKey(), getRandom());
            theSigner.init(true, myParms);
        }

        @Override
        public void initForVerify(final GordianSignParams pParams) throws GordianException {
            /* Initialise detail */
            super.initForVerify(pParams);
            final BouncyKeyPair myPair = getKeyPair();
            BouncyKeyPair.checkKeyPair(myPair);

            /* Initialise and set the signer */
            final BouncyECPublicKey myPublic = (BouncyECPublicKey) myPair.getPublicKey();
            theSigner.init(false, myPublic.getPublicKey());
        }

        @Override
        public byte[] sign() throws GordianException {
            /* Check that we are in signing mode */
            checkMode(GordianSignatureMode.SIGN);

            /* Sign the message */
            final BigInteger[] myValues = theSigner.generateSignature(getDigest());
            return theCoder.dsaEncode(myValues[0], myValues[1]);
        }

        @Override
        public boolean verify(final byte[] pSignature) throws GordianException {
            /* Check that we are in verify mode */
            checkMode(GordianSignatureMode.VERIFY);

            /* Verify the message */
            final BigInteger[] myValues = theCoder.dsaDecode(pSignature);
            return theSigner.verifySignature(getDigest(), myValues[0], myValues[1]);
        }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyEllipticKeyPair.java 360
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyGOSTKeyPair.java 391
theCoder = new BouncyDERCoder();
        }

        @Override
        public void initForSigning(final GordianSignParams pParams) throws GordianException {
            /* Initialise detail */
            super.initForSigning(pParams);
            final BouncyKeyPair myPair = getKeyPair();
            BouncyKeyPair.checkKeyPair(myPair);

            /* Initialise and set the signer */
            final BouncyECPrivateKey myPrivate = (BouncyECPrivateKey) myPair.getPrivateKey();
            final ParametersWithRandom myParms = new ParametersWithRandom(myPrivate.getPrivateKey(), getRandom());
            theSigner.init(true, myParms);
        }

        @Override
        public void initForVerify(final GordianSignParams pParams) throws GordianException {
            /* Initialise detail */
            super.initForVerify(pParams);
            final BouncyKeyPair myPair = getKeyPair();
            BouncyKeyPair.checkKeyPair(myPair);

            /* Initialise and set the signer */
            final BouncyECPublicKey myPublic = (BouncyECPublicKey) myPair.getPublicKey();
            theSigner.init(false, myPublic.getPublicKey());
        }

        @Override
        public byte[] sign() throws GordianException {
            /* Check that we are in signing mode */
            checkMode(GordianSignatureMode.SIGN);

            /* Sign the message */
            final BigInteger[] myValues = theSigner.generateSignature(getDigest());
            return theCoder.dsaEncode(myValues[0], myValues[1]);
        }

        @Override
        public boolean verify(final byte[] pSignature) throws GordianException {
            /* Check that we are in verify mode */
            checkMode(GordianSignatureMode.VERIFY);

            /* Verify the message */
            final BigInteger[] myValues = theCoder.dsaDecode(pSignature);
            return theSigner.verifySignature(getDigest(), myValues[0], myValues[1]);
        }
    }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyDSTUKeyPair.java 347
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyGOSTKeyPair.java 391
theCoder = new BouncyDSTUCoder();
        }

        @Override
        public void initForSigning(final GordianSignParams pParams) throws GordianException {
            /* Initialise detail */
            super.initForSigning(pParams);
            final BouncyKeyPair myPair = getKeyPair();
            BouncyKeyPair.checkKeyPair(myPair);

            /* Initialise and set the signer */
            final BouncyECPrivateKey myPrivate = (BouncyECPrivateKey) myPair.getPrivateKey();
            final ParametersWithRandom myParms = new ParametersWithRandom(myPrivate.getPrivateKey(), getRandom());
            theSigner.init(true, myParms);
        }

        @Override
        public void initForVerify(final GordianSignParams pParams) throws GordianException {
            /* Initialise detail */
            super.initForVerify(pParams);
            final BouncyKeyPair myPair = getKeyPair();
            BouncyKeyPair.checkKeyPair(myPair);

            /* Initialise and set the signer */
            final BouncyECPublicKey myPublic = (BouncyECPublicKey) myPair.getPublicKey();
            theSigner.init(false, myPublic.getPublicKey());
        }

        @Override
        public byte[] sign() throws GordianException {
            /* Check that we are in signing mode */
            checkMode(GordianSignatureMode.SIGN);

            /* Sign the message */
            final BigInteger[] myValues = theSigner.generateSignature(getDigest());
            return theCoder.dsaEncode(myValues[0], myValues[1]);
        }

        @Override
        public boolean verify(final byte[] pSignature) throws GordianException {
            /* Check that we are in verify mode */
            checkMode(GordianSignatureMode.VERIFY);

            /* Verify the message */
            final BigInteger[] myValues = theCoder.dsaDecode(pSignature);
            return theSigner.verifySignature(getDigest(), myValues[0], myValues[1]);
        }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\jca\JcaKeyPairGenerator.java 1337
io\github\tonywasher\joceanus\gordianknot\impl\jca\JcaKeyPairGenerator.java 1553
}

        @Override
        public JcaKeyPair generateKeyPair() {
            /* Generate and return the keyPair */
            final KeyPair myPair = theGenerator.generateKeyPair();
            final JcaPublicKey myPublic = createPublic(myPair.getPublic());
            final JcaStateAwarePrivateKey myPrivate = createPrivate(myPair.getPrivate());
            return new JcaStateAwareKeyPair(myPublic, myPrivate);
        }

        @Override
        protected JcaStateAwarePrivateKey createPrivate(final PrivateKey pPrivateKey) {
            return new JcaStateAwarePrivateKey(getKeySpec(), pPrivateKey);
        }

        @Override
        public JcaKeyPair deriveKeyPair(final X509EncodedKeySpec pPublicKey,
                                        final PKCS8EncodedKeySpec pPrivateKey) throws GordianException {
            /* Protect against exceptions */
            try {
                /* Check the keySpecs */
                checkKeySpec(pPrivateKey);

                /* derive keyPair */
                final JcaPublicKey myPublic = derivePublicKey(pPublicKey);
                JcaStateAwarePrivateKey myPrivate = createPrivate(getKeyFactory().generatePrivate(pPrivateKey));
                final JcaKeyPair myPair = new JcaStateAwareKeyPair(myPublic, myPrivate);

                /* Check that we have a matching pair */
                GordianKeyPairValidity.checkValidity(getFactory(), myPair);

                /* Rebuild and return the keyPair to avoid incrementing usage count */
                myPrivate = createPrivate(getKeyFactory().generatePrivate(pPrivateKey));
                return new JcaStateAwareKeyPair(myPublic, myPrivate);

            } catch (InvalidKeySpecException e) {
                throw new GordianCryptoException(PARSE_ERROR, e);
            }
        }
    }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\macs\GordianBlake2XMac.java 75
io\github\tonywasher\joceanus\gordianknot\impl\ext\macs\GordianSkeinXMac.java 129
return theXof.getDigestSize();
    }

    @Override
    public void update(final byte in) {
        theXof.update(in);
    }

    @Override
    public void update(final byte[] in, final int inOff, final int len) {
        theXof.update(in, inOff, len);
    }

    @Override
    public int doFinal(final byte[] out, final int outOff) {
        return theXof.doFinal(out, outOff);
    }

    @Override
    public int doFinal(final byte[] out, final int outOff, final int outLen) {
        return theXof.doFinal(out, outOff, outLen);
    }

    @Override
    public int doOutput(final byte[] out, final int outOff, final int outLen) {
        return theXof.doOutput(out, outOff, outLen);
    }

    @Override
    public int getByteLength() {
        return theXof.getByteLength();
    }

    @Override
    public int getDigestSize() {
        return theXof.getDigestSize();
    }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSimonEngine.java 149
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSpeckEngine.java 103
}

    @Override
    public int getBlockSize() {
        return BLOCKSIZE;
    }

    @Override
    public int processBlock(final byte[] pInput,
                            final int pInOff,
                            final byte[] pOutput,
                            final int pOutOff) {
        /* Check buffers */
        if (pInput == null || pInput.length - pInOff < BLOCKSIZE) {
            throw new IllegalArgumentException("Invalid input buffer");
        }
        if (pOutput == null || pOutput.length - pOutOff < BLOCKSIZE) {
            throw new IllegalArgumentException("Invalid output buffer");
        }

        /* Perform the encryption/decryption */
        return forEncryption
                ? encryptBlock(pInput, pInOff, pOutput, pOutOff)
                : decryptBlock(pInput, pInOff, pOutput, pOutOff);
    }

    /**
     * Encrypt a block.
     *
     * @param pInput  the input buffer
     * @param pInOff  the input offset
     * @param pOutput the output offset
     * @param pOutOff the output offset
     * @return the bytes processed
     */
    private int encryptBlock(final byte[] pInput,
                             final int pInOff,
                             final byte[] pOutput,
                             final int pOutOff) {
        /* Load the bytes into the block */
        long myX = Pack.bigEndianToLong(pInput, pInOff);
        long myY = Pack.bigEndianToLong(pInput, pInOff + Long.BYTES);

        /* Loop through the rounds */
        for (int i = 0; i < theRounds; i++) {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianBlake2Xof.java 160
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianSkeinXof.java 167
return theUnderlying.getByteLength();
    }

    @Override
    public void update(final byte b) {
        singleByte[0] = b;
        update(singleByte, 0, 1);
    }

    @Override
    public void update(final byte[] pMessage,
                       final int pOffset,
                       final int pLen) {
        if (theXofRemaining != -1) {
            throw new IllegalStateException("Already outputting");
        }
        theUnderlying.update(pMessage, pOffset, pLen);
    }

    @Override
    public int doFinal(final byte[] pOut,
                       final int pOutOffset) {
        return doFinal(pOut, pOutOffset, getDigestSize());
    }

    @Override
    public int doFinal(final byte[] pOut,
                       final int pOutOffset,
                       final int pOutLen) {
        /* Build the required output */
        final int length = doOutput(pOut, pOutOffset, pOutLen);

        /* reset the underlying digest and return the length */
        reset();
        return length;
    }

    @Override
    public int doOutput(final byte[] pOut,
                        final int pOutOffset,
                        final int pOutLen) {
        /* If we have not created the root hash yet */
        if (theRoot == null) {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyEdDSAKeyPair.java 476
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyMLDSAKeyPair.java 347
theSigner.init(false, myPublic.getPublicKey());
        }

        @Override
        public void update(final byte[] pBytes,
                           final int pOffset,
                           final int pLength) {
            theSigner.update(pBytes, pOffset, pLength);
        }

        @Override
        public void update(final byte pByte) {
            theSigner.update(pByte);
        }

        @Override
        public void update(final byte[] pBytes) {
            theSigner.update(pBytes, 0, pBytes.length);
        }

        @Override
        public void reset() {
            theSigner.reset();
        }

        @Override
        protected BouncyKeyPair getKeyPair() {
            return (BouncyKeyPair) super.getKeyPair();
        }

        @Override
        public GordianBaseFactory getFactory() {
            return (GordianBaseFactory) super.getFactory();
        }

        @Override
        public byte[] sign() throws GordianException {
            /* Check that we are in signing mode */
            checkMode(GordianSignatureMode.SIGN);

            /* Sign the message */
            try {
                return theSigner.generateSignature();
            } catch (CryptoException e) {
                throw new GordianCryptoException(BouncySignature.ERROR_SIGGEN, e);
File Line
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyRSAKeyPair.java 608
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncySM2KeyPair.java 301
theEncryptor = new OAEPEncoding(pEngine, myDigest.getDigest(), PSource.PSpecified.DEFAULT.getValue());
        }

        @Override
        protected BouncyPublicKey<?> getPublicKey() {
            return (BouncyPublicKey<?>) super.getPublicKey();
        }

        @Override
        protected BouncyPrivateKey<?> getPrivateKey() {
            return (BouncyPrivateKey<?>) super.getPrivateKey();
        }

        @Override
        public void initForEncrypt(final GordianKeyPair pKeyPair) throws GordianException {
            /* Initialise underlying cipher */
            BouncyKeyPair.checkKeyPair(pKeyPair);
            super.initForEncrypt(pKeyPair);

            /* Initialise for encryption */
            final ParametersWithRandom myParms = new ParametersWithRandom(getPublicKey().getPublicKey(), getRandom());
            theEncryptor.init(true, myParms);
        }

        @Override
        public void initForDecrypt(final GordianKeyPair pKeyPair) throws GordianException {
            /* Initialise underlying cipher */
            BouncyKeyPair.checkKeyPair(pKeyPair);
            super.initForDecrypt(pKeyPair);

            /* Initialise for decryption */
            theEncryptor.init(false, getPrivateKey().getPrivateKey());
        }

        @Override
        public byte[] encrypt(final byte[] pBytes) throws GordianException {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianBlake2Tree.java 492
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianSkeinTree.java 570
theDigest.doFinal(theResult, 0);
            myResults.addElement(Arrays.clone(theResult));

            /* Return the results */
            return myResults;
        }

        /**
         * Check the leaf index.
         *
         * @param pIndex the index of the element
         * @return is this the last element in the tree? true/false
         */
        boolean checkLeafIndex(final int pIndex) {
            /* Cannot replace leaf if not built */
            if (!treeBuilt) {
                throw new IllegalStateException("Tree has not been built");
            }

            /* Check that the index is valid */
            final SimpleVector myLevel = (SimpleVector) theHashes.firstElement();
            if (pIndex < 0 || pIndex >= myLevel.size()) {
                throw new IllegalArgumentException("Invalid index");
            }

            /* Return whether this is the last index */
            return pIndex == myLevel.size() - 1;
        }

        /**
         * Replace the hash for a leaf node.
         *
         * @param pIndex the index of the element
         * @param pHash  the new hashValue
         */
        void replaceElement(final int pIndex,
                            final byte[] pHash) {
            /* Check that the index is correct */
            final SimpleVector myLevel = (SimpleVector) theHashes.firstElement();
            if (pIndex < 0 || pIndex >= myLevel.size()) {
                throw new IllegalArgumentException("Invalid index");
            }

            /* Replace the element */
            myLevel.setElementAt(Arrays.clone(pHash), pIndex);

            /* Loop through the levels */
            int myIndex = pIndex;
            for (int i = 1; i < theHashes.size(); i++) {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\jca\JcaAgreement.java 382
io\github\tonywasher\joceanus\gordianknot\impl\jca\JcaAgreement.java 459
final DHUParameterSpec myParams = new DHUParameterSpec(myEphPublic.getPublicKey(),
                        myEphPrivate.getPrivateKey(), myClientEphPublic.getPublicKey(), getAdditional());
                theAgreement.init(myPrivate.getPrivateKey(), myParams, getRandom());
                theAgreement.doPhase(myClientPublic.getPublicKey(), true);
                storeSecret(theAgreement.generateSecret());

            } catch (InvalidKeyException
                     | InvalidAlgorithmParameterException e) {
                throw new GordianCryptoException(ERR_AGREEMENT, e);
            }
        }

        @Override
        public void processServerHello() throws GordianException {
            /* Protect against exceptions */
            try {
                /* Access keys */
                final JcaPublicKey myServerPublic = (JcaPublicKey) getPublicKey(getServerKeyPair());
                final JcaPublicKey myServerEphPublic = (JcaPublicKey) getPublicKey(getServerEphemeral());
                final JcaPrivateKey myPrivate = (JcaPrivateKey) getPrivateKey(getClientKeyPair());
                final JcaPublicKey myEphPublic = (JcaPublicKey) getPublicKey(getClientEphemeral());
                final JcaPrivateKey myEphPrivate = (JcaPrivateKey) getPrivateKey(getClientEphemeral());
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\macs\GordianZuc128Mac.java 111
io\github\tonywasher\joceanus\gordianknot\impl\ext\macs\GordianZuc256Mac.java 124
for (int i = 0; i < theKeyStream.length - 1; i++) {
            theKeyStream[i] = theEngine.makeKeyStreamWord();
        }
        theWordIndex = theKeyStream.length - 1;
        theByteIndex = Integer.BYTES - 1;
    }

    /**
     * Update the mac with a single byte.
     *
     * @param in the byte to update with
     */
    public void update(final byte in) {
        /* shift for next byte */
        shift4NextByte();

        /* Loop through the bits */
        final int bitBase = theByteIndex * Byte.SIZE;
        for (int bitMask = TOPBIT, bitNo = 0; bitMask > 0; bitMask >>= 1, bitNo++) {
            /* If the bit is set */
            if ((in & bitMask) != 0) {
                /* update theMac */
                updateMac(bitBase + bitNo);
            }
        }
    }

    /**
     * Shift for next byte.
     */
    private void shift4NextByte() {
        /* Adjust the byte index */
        theByteIndex = (theByteIndex + 1) % Integer.BYTES;

        /* Adjust keyStream if required */
        if (theByteIndex == 0) {
            theKeyStream[theWordIndex] = theEngine.makeKeyStreamWord();
            theWordIndex = (theWordIndex + 1) % theKeyStream.length;
        }
    }

    /**
     * Update the Mac.
     *
     * @param bitNo the bit number
     */
    private void updateMac(final int bitNo) {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyDSTUKeyPair.java 163
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyGOSTKeyPair.java 168
final BCDSTU4145PrivateKey privKey = new BCDSTU4145PrivateKey(ALGO, myParms, pubKey, theSpec);
            return new PKCS8EncodedKeySpec(privKey.getEncoded());
        }

        @Override
        public BouncyKeyPair deriveKeyPair(final X509EncodedKeySpec pPublicKey,
                                           final PKCS8EncodedKeySpec pPrivateKey) throws GordianException {
            /* Check the keySpecs */
            checkKeySpec(pPrivateKey);

            /* derive keyPair */
            final BouncyECPublicKey myPublic = derivePublicKey(pPublicKey);
            final PrivateKeyInfo myInfo = PrivateKeyInfo.getInstance(pPrivateKey.getEncoded());
            final ECPrivateKeyParameters myParms = deriveFromPrivKeyInfo(myInfo);
            final BouncyECPrivateKey myPrivate = new BouncyECPrivateKey(getKeySpec(), myParms);
            final BouncyKeyPair myPair = new BouncyKeyPair(myPublic, myPrivate);

            /* Check that we have a matching pair */
            GordianKeyPairValidity.checkValidity(getFactory(), myPair);

            /* Return the keyPair */
            return myPair;
        }

        @Override
        public X509EncodedKeySpec getX509Encoding(final GordianKeyPair pKeyPair) throws GordianException {
            /* Check the keyPair type and keySpecs */
            BouncyKeyPair.checkKeyPair(pKeyPair, getKeySpec());

            /* build and return the encoding */
            final BouncyECPublicKey myPublicKey = (BouncyECPublicKey) getPublicKey(pKeyPair);
            final ECPublicKeyParameters myParms = myPublicKey.getPublicKey();
            final BCDSTU4145PublicKey pubKey = new BCDSTU4145PublicKey(ALGO, myParms, theSpec);
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSimonEngine.java 96
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSpeckEngine.java 50
private static final int ROT3 = 3;

    /**
     * Rotate8.
     */
    private static final int ROT8 = 8;

    /**
     * The # of rounds.
     */
    private int theRounds;

    /**
     * The expanded key schedule.
     */
    private long[] theRoundKeys;

    /**
     * Are we encrypting?
     */
    private boolean forEncryption;

    @Override
    public void init(final boolean pEncrypt,
                     final CipherParameters pParams) {
        /* Reject invalid parameters */
        if (!(pParams instanceof KeyParameter)) {
            throw new IllegalArgumentException("Invalid parameter passed to Speck init - "
                    + pParams.getClass().getName());
        }

        /* Validate keyLength */
        final byte[] myKey = ((KeyParameter) pParams).getKey();
        final int myKeyLen = myKey.length;
        if ((((myKeyLen << 1) % BLOCKSIZE) != 0)
                || myKeyLen < BLOCKSIZE
                || myKeyLen > (BLOCKSIZE << 1)) {
            throw new IllegalArgumentException("KeyBitSize must be 128, 192 or 256");
        }

        /* Generate the round keys */
        forEncryption = pEncrypt;
        generateRoundKeys(myKey);
    }

    @Override
    public void reset() {
        /* NoOp */
    }

    @Override
    public String getAlgorithmName() {
        return "Simon";
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianCubeHashDigest.java 206
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianRabbitEngine.java 201
}

    /**
     * Decode a 32-bit value from a buffer (little-endian).
     *
     * @param buf the input buffer
     * @param off the input offset
     * @return the decoded value
     */
    private static int decode32le(final byte[] buf,
                                  final int off) {
        return (buf[off] & 0xFF)
                | ((buf[off + 1] & 0xFF) << 8)
                | ((buf[off + 2] & 0xFF) << 16)
                | ((buf[off + 3] & 0xFF) << 24);
    }

    /**
     * Encode a 32-bit value into a buffer (little-endian).
     *
     * @param val the value to encode
     * @param buf the output buffer
     * @param off the output offset
     */
    private static void encode32le(final int val,
                                   final byte[] buf,
                                   final int off) {
        buf[off] = (byte) val;
        buf[off + 1] = (byte) (val >> 8);
        buf[off + 2] = (byte) (val >> 16);
        buf[off + 3] = (byte) (val >> 24);
    }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianCubeHashDigest.java 215
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 255
private static int decode32le(final byte[] buf,
                                  final int off) {
        return (buf[off] & 0xFF)
                | ((buf[off + 1] & 0xFF) << 8)
                | ((buf[off + 2] & 0xFF) << 16)
                | ((buf[off + 3] & 0xFF) << 24);
    }

    /**
     * Encode a 32-bit value into a buffer (little-endian).
     *
     * @param val the value to encode
     * @param buf the output buffer
     * @param off the output offset
     */
    private static void encode32le(final int val,
                                   final byte[] buf,
                                   final int off) {
        buf[off] = (byte) val;
        buf[off + 1] = (byte) (val >> 8);
        buf[off + 2] = (byte) (val >> 16);
        buf[off + 3] = (byte) (val >> 24);
    }

    /**
     * Process a block.
     */
    private void processBlock() {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianRabbitEngine.java 210
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 255
private static int decode32le(final byte[] buf, final int off) {
        return (buf[off] & 0xFF)
                | ((buf[off + 1] & 0xFF) << 8)
                | ((buf[off + 2] & 0xFF) << 16)
                | ((buf[off + 3] & 0xFF) << 24);
    }

    /**
     * Encode a 32-bit value into a buffer (little-endian).
     *
     * @param val the value to encode
     * @param buf the output buffer
     * @param off the output offset
     */
    private static void encode32le(final int val, final byte[] buf, final int off) {
        buf[off] = (byte) val;
        buf[off + 1] = (byte) (val >> 8);
        buf[off + 2] = (byte) (val >> 16);
        buf[off + 3] = (byte) (val >> 24);
    }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyDSTUKeyPair.java 347
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncySM2KeyPair.java 115
theCoder = new BouncyDSTUCoder();
        }

        @Override
        public void initForSigning(final GordianSignParams pParams) throws GordianException {
            /* Initialise detail */
            super.initForSigning(pParams);
            final BouncyKeyPair myPair = getKeyPair();
            BouncyKeyPair.checkKeyPair(myPair);

            /* Initialise and set the signer */
            final BouncyECPrivateKey myPrivate = (BouncyECPrivateKey) myPair.getPrivateKey();
            final ParametersWithRandom myParms = new ParametersWithRandom(myPrivate.getPrivateKey(), getRandom());
            theSigner.init(true, myParms);
        }

        @Override
        public void initForVerify(final GordianSignParams pParams) throws GordianException {
            /* Initialise detail */
            super.initForVerify(pParams);
            final BouncyKeyPair myPair = getKeyPair();
            BouncyKeyPair.checkKeyPair(myPair);

            /* Initialise and set the signer */
            final BouncyECPublicKey myPublic = (BouncyECPublicKey) myPair.getPublicKey();
            theSigner.init(false, myPublic.getPublicKey());
        }

        @Override
        public byte[] sign() throws GordianException {
            /* Check that we are in signing mode */
            checkMode(GordianSignatureMode.SIGN);
File Line
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyGOSTKeyPair.java 391
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncySM2KeyPair.java 115
theCoder = new BouncyGOSTCoder(pSpec.getDigestSpec().getDigestLength().getByteLength() << 1);
        }

        @Override
        public void initForSigning(final GordianSignParams pParams) throws GordianException {
            /* Initialise detail */
            super.initForSigning(pParams);
            final BouncyKeyPair myPair = getKeyPair();
            BouncyKeyPair.checkKeyPair(myPair);

            /* Initialise and set the signer */
            final BouncyECPrivateKey myPrivate = (BouncyECPrivateKey) myPair.getPrivateKey();
            final ParametersWithRandom myParms = new ParametersWithRandom(myPrivate.getPrivateKey(), getRandom());
            theSigner.init(true, myParms);
        }

        @Override
        public void initForVerify(final GordianSignParams pParams) throws GordianException {
            /* Initialise detail */
            super.initForVerify(pParams);
            final BouncyKeyPair myPair = getKeyPair();
            BouncyKeyPair.checkKeyPair(myPair);

            /* Initialise and set the signer */
            final BouncyECPublicKey myPublic = (BouncyECPublicKey) myPair.getPublicKey();
            theSigner.init(false, myPublic.getPublicKey());
        }

        @Override
        public byte[] sign() throws GordianException {
            /* Check that we are in signing mode */
            checkMode(GordianSignatureMode.SIGN);
File Line
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyDSTUKeyPair.java 139
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyGOSTKeyPair.java 144
new ECDomainParameters(myCurve, myG, theSpec.getOrder(), BigInteger.valueOf(theSpec.getCofactor())), getRandom());
            theGenerator.init(myParams);
        }

        @Override
        public BouncyKeyPair generateKeyPair() {
            /* Generate and return the keyPair */
            final AsymmetricCipherKeyPair myPair = theGenerator.generateKeyPair();
            final BouncyECPublicKey myPublic = new BouncyECPublicKey(getKeySpec(), (ECPublicKeyParameters) myPair.getPublic());
            final BouncyECPrivateKey myPrivate = new BouncyECPrivateKey(getKeySpec(), (ECPrivateKeyParameters) myPair.getPrivate());
            return new BouncyKeyPair(myPublic, myPrivate);
        }

        @Override
        public PKCS8EncodedKeySpec getPKCS8Encoding(final GordianKeyPair pKeyPair) throws GordianException {
            /* Check the keyPair type and keySpecs */
            BouncyKeyPair.checkKeyPair(pKeyPair, getKeySpec());

            /* build and return the encoding */
            final BouncyECPrivateKey myPrivateKey = (BouncyECPrivateKey) getPrivateKey(pKeyPair);
            final ECPrivateKeyParameters myParms = myPrivateKey.getPrivateKey();
            final BouncyECPublicKey myPublicKey = (BouncyECPublicKey) getPublicKey(pKeyPair);
            final ECPublicKeyParameters myPubParms = myPublicKey.getPublicKey();
            final BCDSTU4145PublicKey pubKey = new BCDSTU4145PublicKey(ALGO, myPubParms, theSpec);
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSnow3GEngine.java 412
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSnow3GEngine.java 441
^ (f)
        );
        lfsrState[0] = lfsrState[1];
        lfsrState[1] = lfsrState[2];
        lfsrState[2] = lfsrState[3];
        lfsrState[3] = lfsrState[4];
        lfsrState[4] = lfsrState[5];
        lfsrState[5] = lfsrState[6];
        lfsrState[6] = lfsrState[7];
        lfsrState[7] = lfsrState[8];
        lfsrState[8] = lfsrState[9];
        lfsrState[9] = lfsrState[10];
        lfsrState[10] = lfsrState[11];
        lfsrState[11] = lfsrState[12];
        lfsrState[12] = lfsrState[13];
        lfsrState[13] = lfsrState[14];
        lfsrState[14] = lfsrState[15];
        lfsrState[15] = v;
    }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianJHDigest.java 689
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianJHDigest.java 717
buffer[63] = (byte) (databitlen & 0xff);
                buffer[62] = (byte) ((databitlen >> 8) & 0xff);
                buffer[61] = (byte) ((databitlen >> 16) & 0xff);
                buffer[60] = (byte) ((databitlen >> 24) & 0xff);
                buffer[59] = (byte) ((databitlen >> 32) & 0xff);
                buffer[58] = (byte) ((databitlen >> 40) & 0xff);
                buffer[57] = (byte) ((databitlen >> 48) & 0xff);
                buffer[56] = (byte) ((databitlen >> 56) & 0xff);
                f8();
            } else {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianBlake2XEngine.java 124
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianBlake3Engine.java 117
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSkeinXofEngine.java 125
return theBlake2X.getAlgorithmName();
    }

    @Override
    public int processBytes(final byte[] in,
                            final int inOff,
                            final int len,
                            final byte[] out,
                            final int outOff) {
        /* Check for errors */
        if (theResetState == null) {
            throw new IllegalStateException(getAlgorithmName() + " not initialised");
        }
        if ((inOff + len) > in.length) {
            throw new DataLengthException("input buffer too short");
        }
        if ((outOff + len) > out.length) {
            throw new OutputLengthException("output buffer too short");
        }

        /* Loop through the input bytes */
        for (int i = 0; i < len; i++) {
            out[i + outOff] = returnByte(in[i + inOff]);
        }
        return len;
    }

    @Override
    public void reset() {
        if (theResetState != null) {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSnow3GEngine.java 413
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianZuc128Engine.java 341
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianZuc128Engine.java 376
);
        lfsrState[0] = lfsrState[1];
        lfsrState[1] = lfsrState[2];
        lfsrState[2] = lfsrState[3];
        lfsrState[3] = lfsrState[4];
        lfsrState[4] = lfsrState[5];
        lfsrState[5] = lfsrState[6];
        lfsrState[6] = lfsrState[7];
        lfsrState[7] = lfsrState[8];
        lfsrState[8] = lfsrState[9];
        lfsrState[9] = lfsrState[10];
        lfsrState[10] = lfsrState[11];
        lfsrState[11] = lfsrState[12];
        lfsrState[12] = lfsrState[13];
        lfsrState[13] = lfsrState[14];
        lfsrState[14] = lfsrState[15];
        lfsrState[15] = v;
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSnow3GEngine.java 442
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianZuc128Engine.java 341
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianZuc128Engine.java 376
);
        lfsrState[0] = lfsrState[1];
        lfsrState[1] = lfsrState[2];
        lfsrState[2] = lfsrState[3];
        lfsrState[3] = lfsrState[4];
        lfsrState[4] = lfsrState[5];
        lfsrState[5] = lfsrState[6];
        lfsrState[6] = lfsrState[7];
        lfsrState[7] = lfsrState[8];
        lfsrState[8] = lfsrState[9];
        lfsrState[9] = lfsrState[10];
        lfsrState[10] = lfsrState[11];
        lfsrState[11] = lfsrState[12];
        lfsrState[12] = lfsrState[13];
        lfsrState[13] = lfsrState[14];
        lfsrState[14] = lfsrState[15];
        lfsrState[15] = v;
File Line
io\github\tonywasher\joceanus\gordianknot\impl\jca\JcaSignature.java 429
io\github\tonywasher\joceanus\gordianknot\impl\jca\JcaSignature.java 488
JcaSLHDSASignature(final GordianBaseFactory pFactory,
                           final GordianSignatureSpec pSignatureSpec) {
            /* Initialise class */
            super(pFactory, pSignatureSpec);
        }

        @Override
        public void initForSigning(final GordianSignParams pParams) throws GordianException {
            /* Determine the required signer */
            final GordianKeyPair myPair = pParams.getKeyPair();
            JcaKeyPair.checkKeyPair(myPair);
            final String mySignName = getAlgorithmForKeyPair(myPair);
            setSigner(getJavaSignature(mySignName, false));

            /* pass on call */
            super.initForSigning(pParams);
        }

        @Override
        public void initForVerify(final GordianSignParams pParams) throws GordianException {
            /* Determine the required signer */
            final GordianKeyPair myPair = pParams.getKeyPair();
            JcaKeyPair.checkKeyPair(myPair);
            final String mySignName = getAlgorithmForKeyPair(myPair);
            setSigner(getJavaSignature(mySignName, false));

            /* pass on call */
            super.initForVerify(pParams);
        }

        /**
         * Obtain algorithmName for keyPair.
         *
         * @param pKeyPair the keyPair
         * @return the name
         */
        private static String getAlgorithmForKeyPair(final GordianKeyPair pKeyPair) {
            /* Build the algorithm */
            final boolean isHash = pKeyPair.getKeyPairSpec().getSLHDSAKeySpec().isHash();
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianBlake2XEngine.java 125
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianRabbitEngine.java 159
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSkeinXofEngine.java 126
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSnow3GEngine.java 204
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 111
}

    @Override
    public int processBytes(final byte[] in,
                            final int inOff,
                            final int len,
                            final byte[] out,
                            final int outOff) {
        /* Check for errors */
        if (theResetState == null) {
            throw new IllegalStateException(getAlgorithmName() + " not initialised");
        }
        if ((inOff + len) > in.length) {
            throw new DataLengthException("input buffer too short");
        }
        if ((outOff + len) > out.length) {
            throw new OutputLengthException("output buffer too short");
        }

        /* Loop through the input bytes */
        for (int i = 0; i < len; i++) {
            out[i + outOff] = returnByte(in[i + inOff]);
        }
        return len;
    }

    @Override
    public void reset() {
        if (theResetState != null) {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianBlake3Engine.java 118
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianRabbitEngine.java 159
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSnow3GEngine.java 204
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 111
}

    @Override
    public int processBytes(final byte[] in,
                            final int inOff,
                            final int len,
                            final byte[] out,
                            final int outOff) {
        /* Check for errors */
        if (theResetState == null) {
            throw new IllegalStateException(getAlgorithmName() + " not initialised");
        }
        if ((inOff + len) > in.length) {
            throw new DataLengthException("input buffer too short");
        }
        if ((outOff + len) > out.length) {
            throw new OutputLengthException("output buffer too short");
        }

        /* Loop through the input bytes */
        for (int i = 0; i < len; i++) {
            out[i + outOff] = returnByte(in[i + inOff]);
        }
        return len;
    }

    @Override
    public void reset() {
        if (theResetState != null) {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\macs\GordianSkeinMac.java 89
io\github\tonywasher\joceanus\gordianknot\impl\ext\macs\GordianSkeinXMac.java 96
return "Skein-MAC-" + (theEngine.getBlockSize() * Byte.SIZE) + "-" + (theEngine.getOutputSize() * Byte.SIZE);
    }

    /**
     * Initialises the Skein digest with the provided parameters.<br>
     * See {@link GordianSkeinParameters} for details on the parameterisation of the Skein hash function.
     *
     * @param params an instance of {@link GordianSkeinParameters} or {@link KeyParameter}.
     */
    public void init(final CipherParameters params)
            throws IllegalArgumentException {
        final GordianSkeinParameters skeinParameters;
        if (params instanceof GordianSkeinParameters) {
            skeinParameters = (GordianSkeinParameters) params;
        } else if (params instanceof KeyParameter) {
            skeinParameters = new GordianSkeinParametersBuilder().setKey(((KeyParameter) params).getKey()).build();
        } else {
            throw new IllegalArgumentException("Invalid parameter passed to Skein MAC init - "
                    + params.getClass().getName());
        }
        if (skeinParameters.getKey() == null) {
            throw new IllegalArgumentException("Skein MAC requires a key parameter.");
        }
        theEngine.init(skeinParameters);
    }

    @Override
    public int getMacSize() {
        return theEngine.getOutputSize();
    }

    @Override
    public void reset() {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\jca\JcaSignature.java 429
io\github\tonywasher\joceanus\gordianknot\impl\jca\JcaSignature.java 739
JcaSLHDSASignature(final GordianBaseFactory pFactory,
                           final GordianSignatureSpec pSignatureSpec) {
            /* Initialise class */
            super(pFactory, pSignatureSpec);
        }

        @Override
        public void initForSigning(final GordianSignParams pParams) throws GordianException {
            /* Determine the required signer */
            final GordianKeyPair myPair = pParams.getKeyPair();
            JcaKeyPair.checkKeyPair(myPair);
            final String mySignName = getAlgorithmForKeyPair(myPair);
            setSigner(getJavaSignature(mySignName, false));

            /* pass on call */
            super.initForSigning(pParams);
        }

        @Override
        public void initForVerify(final GordianSignParams pParams) throws GordianException {
            /* Determine the required signer */
            final GordianKeyPair myPair = pParams.getKeyPair();
            JcaKeyPair.checkKeyPair(myPair);
            final String mySignName = getAlgorithmForKeyPair(myPair);
            setSigner(getJavaSignature(mySignName, false));

            /* pass on call */
            super.initForVerify(pParams);
        }

        /**
         * Obtain algorithmName for keyPair.
         *
         * @param pKeyPair the keyPair
         * @return the name
         */
        private static String getAlgorithmForKeyPair(final GordianKeyPair pKeyPair) {
            /* Build the algorithm */
            final boolean isHash = pKeyPair.getKeyPairSpec().getSLHDSAKeySpec().isHash();
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianBlake2Tree.java 243
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianSkeinTree.java 291
theStore.init(pParams);
    }

    /**
     * Update leaf.
     *
     * @param pIndex    the index of the leaf
     * @param pInput    the input buffer
     * @param pInOffSet the starting offset the the input buffer
     */
    public void updateLeaf(final int pIndex,
                           final byte[] pInput,
                           final int pInOffSet) {
        /* Full leafLen */
        updateLeaf(pIndex, pInput, pInOffSet, getLeafLen());
    }

    /**
     * Update leaf.
     *
     * @param pIndex    the index of the leaf
     * @param pInput    the input buffer
     * @param pInOffSet the starting offset the the input buffer
     * @param pLen      the length of data
     */
    public void updateLeaf(final int pIndex,
                           final byte[] pInput,
                           final int pInOffSet,
                           final int pLen) {
        /* Check index validity */
        final boolean bLast = theStore.checkLeafIndex(pIndex);

        /* Validate the leaf length */
        final int myLeafLen = getLeafLen();
        if (pLen < 0 || pLen > myLeafLen) {
            throw new DataLengthException("Invalid length");
        }

        /* Any leaf that is not the last must be leafLen in length */
        if (!bLast && pLen != myLeafLen) {
            throw new DataLengthException("All but the last leaf must have byteLength " + myLeafLen);
        }

        /* Make sure that the buffer is valid */
        if (pLen + pInOffSet > pInput.length) {
            throw new DataLengthException("Invalid input buffer");
        }

        /* Initialise the node and note if last node */
        theDigest.setNodePosition(pIndex, 0);
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 571
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 847
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 1123
tt = w7 ^ w2 ^ w4 ^ w6 ^ (0x9E3779B9 ^ (28 + 3));
        w7 = rotateLeft(tt, 11);
        r0 = w4;
        r1 = w5;
        r2 = w6;
        r3 = w7;
        r1 ^= r3;
        r3 = ~r3;
        r2 ^= r3;
        r3 ^= r0;
        r4 = r1;
        r1 &= r3;
        r1 ^= r2;
        r4 ^= r3;
        r0 ^= r4;
        r2 &= r4;
        r2 ^= r0;
        r0 &= r1;
        r3 ^= r0;
        r4 |= r1;
        r4 ^= r0;
        r0 |= r3;
        r0 ^= r2;
        r2 &= r3;
        r0 = ~r0;
        r4 ^= r2;
        serpent24SubKeys[i++] = r1;
        serpent24SubKeys[i++] = r4;
        serpent24SubKeys[i++] = r0;
        serpent24SubKeys[i++] = r3;
        tt = w0 ^ w3 ^ w5 ^ w7 ^ (0x9E3779B9 ^ (32));
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 466
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 742
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 1018
tt = w3 ^ w6 ^ w0 ^ w2 ^ (0x9E3779B9 ^ (16 + 3));
        w3 = rotateLeft(tt, 11);
        r0 = w0;
        r1 = w1;
        r2 = w2;
        r3 = w3;
        r4 = r1;
        r1 |= r2;
        r1 ^= r3;
        r4 ^= r2;
        r2 ^= r1;
        r3 |= r4;
        r3 &= r0;
        r4 ^= r2;
        r3 ^= r1;
        r1 |= r4;
        r1 ^= r0;
        r0 |= r4;
        r0 ^= r2;
        r1 ^= r4;
        r2 ^= r1;
        r1 &= r0;
        r1 ^= r4;
        r2 = ~r2;
        r2 |= r0;
        r4 ^= r2;
        serpent24SubKeys[i++] = r4;
        serpent24SubKeys[i++] = r3;
        serpent24SubKeys[i++] = r1;
        serpent24SubKeys[i++] = r0;
        tt = w4 ^ w7 ^ w1 ^ w3 ^ (0x9E3779B9 ^ (20));
File Line
SevenZip\Compression\LZ\BinTree.java 200
SevenZip\Compression\LZ\BinTree.java 296
int count = _cutValue;

		while (true)
		{
			if (curMatch <= matchMinPos || count-- == 0)
			{
				_son[ptr0] = _son[ptr1] = kEmptyHashValue;
				break;
			}
			int delta = _pos - curMatch;
			int cyclicPos = ((delta <= _cyclicBufferPos) ?
				(_cyclicBufferPos - delta) :
				(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;

			int pby1 = _bufferOffset + curMatch;
			int len = Math.min(len0, len1);
			if (_bufferBase[pby1 + len] == _bufferBase[cur + len])
			{
				while(++len != lenLimit)
					if (_bufferBase[pby1 + len] != _bufferBase[cur + len])
						break;
				if (maxLen < len)
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianBlake2Tree.java 367
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianSkeinTree.java 443
theHashes.clear();
            treeBuilt = false;
        }

        /**
         * Add intermediate node.
         *
         * @param pHash the intermediate hash
         */
        void addElement(final byte[] pHash) {
            /* Access the base level */
            if (theHashes.isEmpty()) {
                theHashes.addElement(new SimpleVector());
            }
            final SimpleVector myLevel = (SimpleVector) theHashes.firstElement();

            /* Add the element to the vector */
            myLevel.addElement(Arrays.clone(pHash));
        }

        /**
         * Obtain the tree result.
         *
         * @param pOut       the output buffer
         * @param pOutOffset the offset into the output buffer
         * @return the number of bytes returned
         */
        int obtainResult(final byte[] pOut,
                         final int pOutOffset) {
            /* Check parameters */
            if (pOut.length < pOutOffset + theResult.length) {
                throw new OutputLengthException("Insufficient output buffer");
            }
            if (!treeBuilt) {
                throw new IllegalStateException("tree has not been built");
            }

            /* Access the final level */
            final SimpleVector myLevel = (SimpleVector) theHashes.lastElement();
            final byte[] myResult = (byte[]) myLevel.firstElement();
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 536
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 812
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 1088
tt = w3 ^ w6 ^ w0 ^ w2 ^ (0x9E3779B9 ^ (24 + 3));
        w3 = rotateLeft(tt, 11);
        r0 = w0;
        r1 = w1;
        r2 = w2;
        r3 = w3;
        r0 ^= r1;
        r1 ^= r3;
        r3 = ~r3;
        r4 = r1;
        r1 &= r0;
        r2 ^= r3;
        r1 ^= r2;
        r2 |= r4;
        r4 ^= r3;
        r3 &= r1;
        r3 ^= r0;
        r4 ^= r1;
        r4 ^= r2;
        r2 ^= r0;
        r0 &= r3;
        r2 = ~r2;
        r0 ^= r4;
        r4 |= r3;
        r2 ^= r4;
        serpent24SubKeys[i++] = r1;
        serpent24SubKeys[i++] = r3;
        serpent24SubKeys[i++] = r0;
        serpent24SubKeys[i++] = r2;
        tt = w4 ^ w7 ^ w1 ^ w3 ^ (0x9E3779B9 ^ (28));
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 607
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 883
tt = w3 ^ w6 ^ w0 ^ w2 ^ (0x9E3779B9 ^ (32 + 3));
        w3 = rotateLeft(tt, 11);
        r0 = w0;
        r1 = w1;
        r2 = w2;
        r3 = w3;
        r4 = r0;
        r0 |= r3;
        r3 ^= r1;
        r1 &= r4;
        r4 ^= r2;
        r2 ^= r3;
        r3 &= r0;
        r4 |= r1;
        r3 ^= r4;
        r0 ^= r1;
        r4 &= r0;
        r1 ^= r3;
        r4 ^= r2;
        r1 |= r0;
        r1 ^= r2;
        r0 ^= r3;
        r2 = r1;
        r1 |= r3;
        r1 ^= r0;
        serpent24SubKeys[i++] = r1;
        serpent24SubKeys[i++] = r2;
        serpent24SubKeys[i++] = r3;
        serpent24SubKeys[i++] = r4;
        tt = w4 ^ w7 ^ w1 ^ w3 ^ (0x9E3779B9 ^ (36));
File Line
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyDSAKeyPair.java 344
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyGOSTKeyPair.java 415
final BouncyDSAPublicKey myPublic = (BouncyDSAPublicKey) myPair.getPublicKey();
            theSigner.init(false, myPublic.getPublicKey());
        }

        @Override
        public byte[] sign() throws GordianException {
            /* Check that we are in signing mode */
            checkMode(GordianSignatureMode.SIGN);

            /* Sign the message */
            final BigInteger[] myValues = theSigner.generateSignature(getDigest());
            return theCoder.dsaEncode(myValues[0], myValues[1]);
        }

        @Override
        public boolean verify(final byte[] pSignature) throws GordianException {
            /* Check that we are in verify mode */
            checkMode(GordianSignatureMode.VERIFY);

            /* Verify the message */
            final BigInteger[] myValues = theCoder.dsaDecode(pSignature);
            return theSigner.verifySignature(getDigest(), myValues[0], myValues[1]);
        }
    }
}
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 398
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 674
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 950
tt = w3 ^ w6 ^ w0 ^ w2 ^ (0x9E3779B9 ^ (8 + 3));
        w3 = rotateLeft(tt, 11);
        r0 = w0;
        r1 = w1;
        r2 = w2;
        r3 = w3;
        r0 = ~r0;
        r2 = ~r2;
        r4 = r0;
        r0 &= r1;
        r2 ^= r0;
        r0 |= r3;
        r3 ^= r2;
        r1 ^= r0;
        r0 ^= r4;
        r4 |= r1;
        r1 ^= r3;
        r2 |= r0;
        r2 &= r4;
        r0 ^= r1;
        r1 &= r2;
        r1 ^= r0;
        r0 &= r2;
        r0 ^= r4;
        serpent24SubKeys[i++] = r2;
        serpent24SubKeys[i++] = r0;
        serpent24SubKeys[i++] = r3;
        serpent24SubKeys[i++] = r1;
        tt = w4 ^ w7 ^ w1 ^ w3 ^ (0x9E3779B9 ^ (12));
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 502
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 778
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 1054
tt = w7 ^ w2 ^ w4 ^ w6 ^ (0x9E3779B9 ^ (20 + 3));
        w7 = rotateLeft(tt, 11);
        r0 = w4;
        r1 = w5;
        r2 = w6;
        r3 = w7;
        r2 = ~r2;
        r4 = r3;
        r3 &= r0;
        r0 ^= r4;
        r3 ^= r2;
        r2 |= r4;
        r1 ^= r3;
        r2 ^= r0;
        r0 |= r1;
        r2 ^= r1;
        r4 ^= r0;
        r0 |= r3;
        r0 ^= r2;
        r4 ^= r3;
        r4 ^= r0;
        r3 = ~r3;
        r2 &= r4;
        r2 ^= r3;
        serpent24SubKeys[i++] = r0;
        serpent24SubKeys[i++] = r1;
        serpent24SubKeys[i++] = r4;
        serpent24SubKeys[i++] = r2;
        tt = w0 ^ w3 ^ w5 ^ w7 ^ (0x9E3779B9 ^ (24));
File Line
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyDSAKeyPair.java 344
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyEllipticKeyPair.java 384
final BouncyDSAPublicKey myPublic = (BouncyDSAPublicKey) myPair.getPublicKey();
            theSigner.init(false, myPublic.getPublicKey());
        }

        @Override
        public byte[] sign() throws GordianException {
            /* Check that we are in signing mode */
            checkMode(GordianSignatureMode.SIGN);

            /* Sign the message */
            final BigInteger[] myValues = theSigner.generateSignature(getDigest());
            return theCoder.dsaEncode(myValues[0], myValues[1]);
        }

        @Override
        public boolean verify(final byte[] pSignature) throws GordianException {
            /* Check that we are in verify mode */
            checkMode(GordianSignatureMode.VERIFY);

            /* Verify the message */
            final BigInteger[] myValues = theCoder.dsaDecode(pSignature);
            return theSigner.verifySignature(getDigest(), myValues[0], myValues[1]);
        }
    }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 432
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 708
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 984
tt = w7 ^ w2 ^ w4 ^ w6 ^ (0x9E3779B9 ^ (12 + 3));
        w7 = rotateLeft(tt, 11);
        r0 = w4;
        r1 = w5;
        r2 = w6;
        r3 = w7;
        r3 ^= r0;
        r4 = r1;
        r1 &= r3;
        r4 ^= r2;
        r1 ^= r0;
        r0 |= r3;
        r0 ^= r4;
        r4 ^= r3;
        r3 ^= r2;
        r2 |= r1;
        r2 ^= r4;
        r4 = ~r4;
        r4 |= r1;
        r1 ^= r3;
        r1 ^= r4;
        r3 |= r0;
        r1 ^= r3;
        r4 ^= r3;
        serpent24SubKeys[i++] = r1;
        serpent24SubKeys[i++] = r4;
        serpent24SubKeys[i++] = r2;
        serpent24SubKeys[i++] = r0;
        tt = w0 ^ w3 ^ w5 ^ w7 ^ (0x9E3779B9 ^ (16));
File Line
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyDSAKeyPair.java 344
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyDSTUKeyPair.java 371
final BouncyDSAPublicKey myPublic = (BouncyDSAPublicKey) myPair.getPublicKey();
            theSigner.init(false, myPublic.getPublicKey());
        }

        @Override
        public byte[] sign() throws GordianException {
            /* Check that we are in signing mode */
            checkMode(GordianSignatureMode.SIGN);

            /* Sign the message */
            final BigInteger[] myValues = theSigner.generateSignature(getDigest());
            return theCoder.dsaEncode(myValues[0], myValues[1]);
        }

        @Override
        public boolean verify(final byte[] pSignature) throws GordianException {
            /* Check that we are in verify mode */
            checkMode(GordianSignatureMode.VERIFY);

            /* Verify the message */
            final BigInteger[] myValues = theCoder.dsaDecode(pSignature);
            return theSigner.verifySignature(getDigest(), myValues[0], myValues[1]);
        }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianBlake2XEngine.java 128
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianZuc128Engine.java 233
public int processBytes(final byte[] in,
                            final int inOff,
                            final int len,
                            final byte[] out,
                            final int outOff) {
        /* Check for errors */
        if (theResetState == null) {
            throw new IllegalStateException(getAlgorithmName() + " not initialised");
        }
        if ((inOff + len) > in.length) {
            throw new DataLengthException("input buffer too short");
        }
        if ((outOff + len) > out.length) {
            throw new OutputLengthException("output buffer too short");
        }

        /* Loop through the input bytes */
        for (int i = 0; i < len; i++) {
            out[i + outOff] = returnByte(in[i + inOff]);
        }
        return len;
    }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianBlake3Engine.java 121
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianZuc128Engine.java 233
public int processBytes(final byte[] in,
                            final int inOff,
                            final int len,
                            final byte[] out,
                            final int outOff) {
        /* Check for errors */
        if (theResetState == null) {
            throw new IllegalStateException(getAlgorithmName() + " not initialised");
        }
        if ((inOff + len) > in.length) {
            throw new DataLengthException("input buffer too short");
        }
        if ((outOff + len) > out.length) {
            throw new OutputLengthException("output buffer too short");
        }

        /* Loop through the input bytes */
        for (int i = 0; i < len; i++) {
            out[i + outOff] = returnByte(in[i + inOff]);
        }
        return len;
    }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianRabbitEngine.java 162
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianZuc128Engine.java 233
public int processBytes(final byte[] in,
                            final int inOff,
                            final int len,
                            final byte[] out,
                            final int outOff) {
        /* Check for errors */
        if (theResetState == null) {
            throw new IllegalStateException(getAlgorithmName() + " not initialised");
        }
        if ((inOff + len) > in.length) {
            throw new DataLengthException("input buffer too short");
        }
        if ((outOff + len) > out.length) {
            throw new OutputLengthException("output buffer too short");
        }

        /* Loop through the input bytes */
        for (int i = 0; i < len; i++) {
            out[i + outOff] = returnByte(in[i + inOff]);
        }
        return len;
    }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSkeinXofEngine.java 129
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianZuc128Engine.java 233
public int processBytes(final byte[] in,
                            final int inOff,
                            final int len,
                            final byte[] out,
                            final int outOff) {
        /* Check for errors */
        if (theResetState == null) {
            throw new IllegalStateException(getAlgorithmName() + " not initialised");
        }
        if ((inOff + len) > in.length) {
            throw new DataLengthException("input buffer too short");
        }
        if ((outOff + len) > out.length) {
            throw new OutputLengthException("output buffer too short");
        }

        /* Loop through the input bytes */
        for (int i = 0; i < len; i++) {
            out[i + outOff] = returnByte(in[i + inOff]);
        }
        return len;
    }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSnow3GEngine.java 207
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianZuc128Engine.java 233
public int processBytes(final byte[] in,
                            final int inOff,
                            final int len,
                            final byte[] out,
                            final int outOff) {
        /* Check for errors */
        if (theResetState == null) {
            throw new IllegalStateException(getAlgorithmName() + " not initialised");
        }
        if ((inOff + len) > in.length) {
            throw new DataLengthException("input buffer too short");
        }
        if ((outOff + len) > out.length) {
            throw new OutputLengthException("output buffer too short");
        }

        /* Loop through the input bytes */
        for (int i = 0; i < len; i++) {
            out[i + outOff] = returnByte(in[i + inOff]);
        }
        return len;
    }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 114
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianZuc128Engine.java 233
public int processBytes(final byte[] in,
                            final int inOff,
                            final int len,
                            final byte[] out,
                            final int outOff) {
        /* Check for errors */
        if (theResetState == null) {
            throw new IllegalStateException(getAlgorithmName() + " not initialised");
        }
        if ((inOff + len) > in.length) {
            throw new DataLengthException("input buffer too short");
        }
        if ((outOff + len) > out.length) {
            throw new OutputLengthException("output buffer too short");
        }

        /* Loop through the input bytes */
        for (int i = 0; i < len; i++) {
            out[i + outOff] = returnByte(in[i + inOff]);
        }
        return len;
    }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianGroestlDigest.java 74
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianJHDigest.java 74
}

    @Override
    public int getDigestSize() {
        return theDigestLen;
    }

    @Override
    public void reset() {
        theDigest.reset();
    }

    @Override
    public void update(final byte arg0) {
        final byte[] myByte = new byte[]{arg0};
        update(myByte, 0, 1);
    }

    @Override
    public void update(final byte[] pData, final int pOffset, final int pLength) {
        theDigest.update(pData, pOffset, ((long) pLength) * Byte.SIZE);
    }

    @Override
    public int getByteLength() {
        return theDigest.getBufferSize();
    }

    @Override
    public GordianGroestlDigest copy() {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSnow3GEngine.java 151
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianZuc128Engine.java 164
private GordianSnow3GEngine(final GordianSnow3GEngine pSource) {
        reset(pSource);
    }

    /**
     * initialise a Snow3G cipher.
     *
     * @param forEncryption whether or not we are for encryption.
     * @param params        the parameters required to set up the cipher.
     * @throws IllegalArgumentException if the params argument is inappropriate.
     */
    public void init(final boolean forEncryption,
                     final CipherParameters params) {
        /*
         * encryption and decryption is completely symmetrical, so the 'forEncryption' is
         * irrelevant. (Like 90% of stream ciphers)
         */

        /* Determine parameters */
        CipherParameters myParams = params;
        byte[] newKey = null;
        byte[] newIV = null;
        if ((myParams instanceof ParametersWithIV)) {
            final ParametersWithIV ivParams = (ParametersWithIV) myParams;
            newIV = ivParams.getIV();
            myParams = ivParams.getParameters();
        }
        if (myParams instanceof KeyParameter) {
            final KeyParameter keyParam = (KeyParameter) myParams;
            newKey = keyParam.getKey();
        }

        /* Initialise engine and mark as initialised */
        theIndex = 0;
        theIterations = 0;
        setKeyAndIV(newKey, newIV);

        /* Save reset state */
        theResetState = copy();
    }

    /**
     * Obtain Max iterations.
     *
     * @return the maximum iterations
     */
    protected int getMaxIterations() {
        return 625;
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 366
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 642
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 918
tt = w7 ^ w2 ^ w4 ^ w6 ^ (0x9E3779B9 ^ (4 + 3));
        w7 = rotateLeft(tt, 11);
        r0 = w4;
        r1 = w5;
        r2 = w6;
        r3 = w7;
        r4 = r0;
        r0 &= r2;
        r0 ^= r3;
        r2 ^= r1;
        r2 ^= r0;
        r3 |= r4;
        r3 ^= r1;
        r4 ^= r2;
        r1 = r3;
        r3 |= r4;
        r3 ^= r0;
        r0 &= r1;
        r4 ^= r0;
        r1 ^= r3;
        r1 ^= r4;
        r4 = ~r4;
        serpent24SubKeys[i++] = r2;
        serpent24SubKeys[i++] = r3;
        serpent24SubKeys[i++] = r1;
        serpent24SubKeys[i++] = r4;
        tt = w0 ^ w3 ^ w5 ^ w7 ^ (0x9E3779B9 ^ (8));
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\macs\GordianBlake2Mac.java 64
io\github\tonywasher\joceanus\gordianknot\impl\ext\macs\GordianBlake3Mac.java 63
throw new IllegalArgumentException("Blake2Mac requires a key parameter.");
        }

        /* Configure the digest */
        theDigest.init(myBlakeParams);
    }

    @Override
    public int getMacSize() {
        return theDigest.getDigestSize();
    }

    @Override
    public void update(final byte in) {
        theDigest.update(in);
    }

    @Override
    public void update(final byte[] in, final int inOff, final int len) {
        theDigest.update(in, inOff, len);
    }

    @Override
    public int doFinal(final byte[] out, final int outOff) {
        return theDigest.doFinal(out, outOff);
    }

    @Override
    public void reset() {
        theDigest.reset();
    }
File Line
io\github\tonywasher\joceanus\gordianknot\impl\core\agree\GordianCoreAgreementFactory.java 429
io\github\tonywasher\joceanus\gordianknot\impl\core\agree\GordianCoreAgreementFactory.java 442
case GOST2012:
                myAgreements.addAll(listAllKDFs(pKeyPairSpec, GordianAgreementType.ANON));
                myAgreements.addAll(listAllKDFs(pKeyPairSpec, GordianAgreementType.KEM));
                myAgreements.addAll(listAllKDFs(pKeyPairSpec, GordianAgreementType.BASIC));
                myAgreements.addAll(listAllKDFs(pKeyPairSpec, GordianAgreementType.SIGNED));
                myAgreements.addAll(listAllKDFs(pKeyPairSpec, GordianAgreementType.UNIFIED));
                myAgreements.addAll(listAllKDFs(pKeyPairSpec, GordianAgreementType.UNIFIED, Boolean.TRUE));
                myAgreements.addAll(listAllKDFs(pKeyPairSpec, GordianAgreementType.MQV));
                myAgreements.addAll(listAllKDFs(pKeyPairSpec, GordianAgreementType.MQV, Boolean.TRUE));
File Line
io\github\tonywasher\joceanus\gordianknot\impl\core\digest\GordianCoreDigest.java 50
io\github\tonywasher\joceanus\gordianknot\impl\core\mac\GordianCoreMac.java 97
return theDigestSpec.getDigestLength().getByteLength();
    }

    @Override
    public void update(final byte[] pBytes,
                       final int pOffset,
                       final int pLength) {
        /* Check that the buffers are sufficient */
        final int myInBufLen = pBytes == null ? 0 : pBytes.length;
        if (myInBufLen < (pLength + pOffset)) {
            throw new IllegalArgumentException("Input buffer too short.");
        }

        /* Process the bytes */
        if (pLength != 0) {
            doUpdate(pBytes, pOffset, pLength);
        }
    }

    /**
     * Update the digest with a portion of a byte array.
     *
     * @param pBytes  the bytes to update with.
     * @param pOffset the offset of the data within the byte array
     * @param pLength the length of the data to use
     */
    public abstract void doUpdate(byte[] pBytes,
                                  int pOffset,
                                  int pLength);

    @Override
    public int finish(final byte[] pBuffer,
                      final int pOffset) throws GordianException {
        /* Check that the buffers are sufficient */
        if (pBuffer.length < (getDigestSize() + pOffset)) {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianBlake2Tree.java 165
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianSkeinTree.java 184
}

    /**
     * Process data.
     *
     * @param pIn       the input buffer
     * @param pInOffSet the starting offset in the input buffer
     * @param pLen      the length of data to process
     */
    private void processData(final byte[] pIn,
                             final int pInOffSet,
                             final int pLen) {
        /* Cannot process further data once tree is built */
        if (theStore.treeBuilt()) {
            throw new IllegalStateException("Tree has been built");
        }

        /* Determine space in current block */
        final int blkSize = getLeafLen();
        final int mySpace = blkSize - theProcessed;

        /* If all data can be processed by the current leaf */
        if (mySpace >= pLen) {
            /* Update and return */
            theDigest.update(pIn, pInOffSet, pLen);
            theProcessed += pLen;
            return;
        }

        /* Process as much as possible into current leaf */
        if (mySpace > 0) {
            theDigest.update(pIn, pInOffSet, mySpace);
            theProcessed += mySpace;
        }

        /* Loop while we have data remaining */
        int myProcessed = mySpace;
        while (myProcessed < pLen) {
            /* If the current leaf is full */
            if (theProcessed == blkSize) {
                /* Finalise the leaf and process the result */
                theDigest.doFinal(theHash, 0);
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianBlake2Tree.java 410
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianSkeinTree.java 489
return myResult.length;
        }

        /**
         * Calculate tree result.
         *
         * @param pOut       the output buffer
         * @param pOutOffset the offset into the output buffer
         * @return the number of bytes returned
         */
        int calculateTree(final byte[] pOut,
                          final int pOutOffset) {
            /* Check parameters */
            if (pOut.length < pOutOffset + theResult.length) {
                throw new OutputLengthException("Insufficient output buffer");
            }
            if (treeBuilt) {
                throw new IllegalStateException("tree already built");
            }

            /* Access the only level */
            SimpleVector myLevel = (SimpleVector) theHashes.lastElement();

            /* While we have elements that must be reduced */
            while (myLevel.size() > 1) {
                /* Calculate the next set of hashes */
                myLevel = calculateNextLevel(myLevel);
                theHashes.addElement(myLevel);
            }

            /* Note that the tree has been built */
            treeBuilt = true;

            /* Return the final hash */
            return obtainResult(pOut, pOutOffset);
        }

        /**
         * Calculate next level.
         *
         * @param pInput the current set of hashes
         * @return the next level
         */
        private SimpleVector calculateNextLevel(final SimpleVector pInput) {
            /* Set the depth of the tree */
            final int myCurDepth = theHashes.size();
File Line
io\github\tonywasher\joceanus\gordianknot\impl\jca\JcaAEADCipher.java 71
io\github\tonywasher\joceanus\gordianknot\impl\jca\JcaCipher.java 72
JcaAEADCipher(final GordianBaseFactory pFactory,
                  final GordianCipherSpec<T> pCipherSpec,
                  final Cipher pCipher) {
        super(pFactory, pCipherSpec);
        theCipher = pCipher;
    }

    @Override
    public JcaKey<T> getKey() {
        return (JcaKey<T>) super.getKey();
    }


    @Override
    public void init(final boolean pEncrypt,
                     final GordianCipherParameters pParams) throws GordianException {
        /* Process the parameters and access the key */
        processParameters(pParams);
        final JcaKey<T> myJcaKey = JcaKey.accessKey(getKey());

        /* Access details */
        final int myMode = pEncrypt
                ? Cipher.ENCRYPT_MODE
                : Cipher.DECRYPT_MODE;
        final SecretKey myKey = myJcaKey.getKey();
        final byte[] myAEAD = getInitialAEAD();
File Line
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyEdDSAKeyPair.java 477
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncySM2KeyPair.java 89
}

        @Override
        public void update(final byte[] pBytes,
                           final int pOffset,
                           final int pLength) {
            theSigner.update(pBytes, pOffset, pLength);
        }

        @Override
        public void update(final byte pByte) {
            theSigner.update(pByte);
        }

        @Override
        public void update(final byte[] pBytes) {
            theSigner.update(pBytes, 0, pBytes.length);
        }

        @Override
        public void reset() {
            theSigner.reset();
        }

        @Override
        protected BouncyKeyPair getKeyPair() {
            return (BouncyKeyPair) super.getKeyPair();
        }

        @Override
        public GordianBaseFactory getFactory() {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyMLDSAKeyPair.java 348
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncySM2KeyPair.java 89
}

        @Override
        public void update(final byte[] pBytes,
                           final int pOffset,
                           final int pLength) {
            theSigner.update(pBytes, pOffset, pLength);
        }

        @Override
        public void update(final byte pByte) {
            theSigner.update(pByte);
        }

        @Override
        public void update(final byte[] pBytes) {
            theSigner.update(pBytes, 0, pBytes.length);
        }

        @Override
        public void reset() {
            theSigner.reset();
        }

        @Override
        protected BouncyKeyPair getKeyPair() {
            return (BouncyKeyPair) super.getKeyPair();
        }

        @Override
        public GordianBaseFactory getFactory() {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianBlake2XEngine.java 72
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSkeinXofEngine.java 73
theKeyStream = new byte[theBlake2X.getByteLength() >> 1];
        reset(pSource);
    }

    /**
     * initialise a Blake2X cipher.
     *
     * @param forEncryption whether or not we are for encryption.
     * @param params        the parameters required to set up the cipher.
     * @throws IllegalArgumentException if the params argument is inappropriate.
     */
    public void init(final boolean forEncryption,
                     final CipherParameters params) {
        /*
         * Blake2X encryption and decryption is completely symmetrical, so the 'forEncryption' is
         * irrelevant. (Like 90% of stream ciphers)
         */

        /* Determine parameters */
        CipherParameters myParams = params;
        byte[] newKey = null;
        byte[] newIV = null;
        if ((myParams instanceof ParametersWithIV)) {
            final ParametersWithIV ivParams = (ParametersWithIV) myParams;
            newIV = ivParams.getIV();
            myParams = ivParams.getParameters();
        }
        if (myParams instanceof KeyParameter) {
            final KeyParameter keyParam = (KeyParameter) myParams;
            newKey = keyParam.getKey();
        }
        if (newKey == null || newIV == null) {
            throw new IllegalArgumentException("A key and IV must be provided");
        }

        /* Initialise engine and mark as initialised */
        final GordianBlake2ParametersBuilder myBuilder = new GordianBlake2ParametersBuilder()
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 607
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 1159
tt = w3 ^ w6 ^ w0 ^ w2 ^ (0x9E3779B9 ^ (32 + 3));
        w3 = rotateLeft(tt, 11);
        r0 = w0;
        r1 = w1;
        r2 = w2;
        r3 = w3;
        r4 = r0;
        r0 |= r3;
        r3 ^= r1;
        r1 &= r4;
        r4 ^= r2;
        r2 ^= r3;
        r3 &= r0;
        r4 |= r1;
        r3 ^= r4;
        r0 ^= r1;
        r4 &= r0;
        r1 ^= r3;
        r4 ^= r2;
        r1 |= r0;
        r1 ^= r2;
        r0 ^= r3;
        r2 = r1;
        r1 |= r3;
        r1 ^= r0;
        serpent24SubKeys[i++] = r1;
        serpent24SubKeys[i++] = r2;
        serpent24SubKeys[i++] = r3;
        serpent24SubKeys[i++] = r4;
File Line
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyDSTUKeyPair.java 195
io\github\tonywasher\joceanus\gordianknot\impl\bc\BouncyGOSTKeyPair.java 200
final BCDSTU4145PublicKey pubKey = new BCDSTU4145PublicKey(ALGO, myParms, theSpec);
            return new X509EncodedKeySpec(pubKey.getEncoded());
        }

        @Override
        public BouncyKeyPair derivePublicOnlyKeyPair(final X509EncodedKeySpec pEncodedKey) throws GordianException {
            final BouncyECPublicKey myPublic = derivePublicKey(pEncodedKey);
            return new BouncyKeyPair(myPublic);
        }

        /**
         * Derive public key from encoded.
         *
         * @param pEncodedKey the encoded key
         * @return the public key
         * @throws GordianException on error
         */
        private BouncyECPublicKey derivePublicKey(final X509EncodedKeySpec pEncodedKey) throws GordianException {
            /* Check the keySpecs */
            checkKeySpec(pEncodedKey);

            /* derive publicKey */
            final SubjectPublicKeyInfo myInfo = SubjectPublicKeyInfo.getInstance(pEncodedKey.getEncoded());
            final ECPublicKeyParameters myParms = deriveFromPubKeyInfo(myInfo);
            return new BouncyECPublicKey(getKeySpec(), myParms);
        }

        /**
         * Derive Public Key parameters from SubjectPublicKeyInfo. (extracted from BouncyCastle initialiser)
         *
         * @param pKeyInfo the keyInfo
         * @return the PrivateKeyParameters
         * @throws GordianException on error
         */
        private ECPublicKeyParameters deriveFromPubKeyInfo(final SubjectPublicKeyInfo pKeyInfo) throws GordianException {
            final ASN1BitString bits = pKeyInfo.getPublicKeyData();
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianZuc128Engine.java 329
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianZuc128Engine.java 365
private void lfsrWithInitialisationMode(final int u) {
        int f = lfsrState[0];
        int v = mulByPow2(lfsrState[0], 8);
        f = addM(f, v);
        v = mulByPow2(lfsrState[4], 20);
        f = addM(f, v);
        v = mulByPow2(lfsrState[10], 21);
        f = addM(f, v);
        v = mulByPow2(lfsrState[13], 17);
        f = addM(f, v);
        v = mulByPow2(lfsrState[15], 15);
        f = addM(f, v);
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianBlake2XEngine.java 73
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianBlake3Engine.java 69
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSkeinXofEngine.java 74
reset(pSource);
    }

    /**
     * initialise a Blake2X cipher.
     *
     * @param forEncryption whether or not we are for encryption.
     * @param params        the parameters required to set up the cipher.
     * @throws IllegalArgumentException if the params argument is inappropriate.
     */
    public void init(final boolean forEncryption,
                     final CipherParameters params) {
        /*
         * Blake2X encryption and decryption is completely symmetrical, so the 'forEncryption' is
         * irrelevant. (Like 90% of stream ciphers)
         */

        /* Determine parameters */
        CipherParameters myParams = params;
        byte[] newKey = null;
        byte[] newIV = null;
        if ((myParams instanceof ParametersWithIV)) {
            final ParametersWithIV ivParams = (ParametersWithIV) myParams;
            newIV = ivParams.getIV();
            myParams = ivParams.getParameters();
        }
        if (myParams instanceof KeyParameter) {
            final KeyParameter keyParam = (KeyParameter) myParams;
            newKey = keyParam.getKey();
        }
        if (newKey == null || newIV == null) {
            throw new IllegalArgumentException("A key and IV must be provided");
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianRabbitEngine.java 114
io\github\tonywasher\joceanus\gordianknot\impl\ext\engines\GordianSosemanukEngine.java 66
private GordianRabbitEngine(final GordianRabbitEngine pSource) {
        reset(pSource);
    }

    /**
     * initialise a Rabbit cipher.
     *
     * @param forEncryption whether or not we are for encryption.
     * @param params        the parameters required to set up the cipher.
     * @throws IllegalArgumentException if the params argument is inappropriate.
     */
    public void init(final boolean forEncryption,
                     final CipherParameters params) {
        /*
         * encryption and decryption is completely symmetrical, so the 'forEncryption' is
         * irrelevant. (Like 90% of stream ciphers)
         */

        /* Determine parameters */
        CipherParameters myParams = params;
        byte[] newKey = null;
        byte[] newIV = null;
        if ((myParams instanceof ParametersWithIV)) {
            final ParametersWithIV ivParams = (ParametersWithIV) myParams;
            newIV = ivParams.getIV();
            myParams = ivParams.getParameters();
        }
        if (myParams instanceof KeyParameter) {
            final KeyParameter keyParam = (KeyParameter) myParams;
            newKey = keyParam.getKey();
        }

        /* Initialise engine and mark as initialised */
        theIndex = 0;
        setKey(newKey);
        setIV(newIV);
File Line
io\github\tonywasher\joceanus\gordianknot\impl\jca\JcaAgreement.java 359
io\github\tonywasher\joceanus\gordianknot\impl\jca\JcaAgreement.java 437
JcaUnifiedEngine(final GordianCoreAgreementFactory pFactory,
                         final GordianAgreementSpec pSpec,
                         final KeyAgreement pAgreement) throws GordianException {
            /* Initialize underlying class */
            super(pFactory, pSpec);

            /* Store the agreement */
            theAgreement = pAgreement;
        }

        @Override
        public void processClientHello() throws GordianException {
            /* Protect against exceptions */
            try {
                /* Access keys */
                final JcaPublicKey myClientPublic = (JcaPublicKey) getPublicKey(getClientKeyPair());
                final JcaPublicKey myClientEphPublic = (JcaPublicKey) getPublicKey(getClientEphemeral());
                final JcaPrivateKey myPrivate = (JcaPrivateKey) getPrivateKey(getServerKeyPair());
                final JcaPublicKey myEphPublic = (JcaPublicKey) getPublicKey(getServerEphemeral());
                final JcaPrivateKey myEphPrivate = (JcaPrivateKey) getPrivateKey(getServerEphemeral());
File Line
io\github\tonywasher\joceanus\gordianknot\impl\core\cipher\GordianCoreCipherParameters.java 341
io\github\tonywasher\joceanus\gordianknot\impl\core\cipher\GordianCoreCipherParameters.java 373
myPassword = PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(pPassword);
            myGenerator.init(myPassword, thePBESalt, mySpec.getIterationCount());

            /* Generate the parameters */
            final int myKeyLen = theSpec.getKeyType().getKeyLength().getLength();
            final int myIVLen = theSpec.needsIV() ? Byte.SIZE * theSpec.getIVLength() : 0;
            return myIVLen == 0
                    ? myGenerator.generateDerivedParameters(myKeyLen)
                    : myGenerator.generateDerivedParameters(myKeyLen, myIVLen);
        } finally {
            if (myPassword != null) {
                Arrays.fill(myPassword, (byte) 0);
            }
        }
    }

    /**
     * derive PKCS12 key and IV.
     *
     * @param pPassword the password
     * @return the parameters
     */
    private CipherParameters derivePKCS12Parameters(final char[] pPassword) {
File Line
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianBlake2bDigest.java 151
io\github\tonywasher\joceanus\gordianknot\impl\ext\digests\GordianBlake2sDigest.java 151
return new GordianBlake2bDigest(this);
    }

    @Override
    void adjustCounter(final int pCount) {
        t0 += pCount;
        if (t0 == 0) {
            t1++;
        }
    }

    @Override
    void completeCounter(final int pCount) {
        t0 += pCount;
        if (pCount > 0 && t0 == 0) {
            t1++;
        }
    }

    @Override
    void outputDigest(final byte[] pOut,
                      final int pOutOffset) {
        /* Loop to provide the output */
        final int myDigestLen = getDigestSize();
        for (int i = 0, j = 0; i < NUMWORDS && j < myDigestLen; i++, j += Long.BYTES) {