private static byte[] addPadding(byte[] plaintextraw, int keysize) { byte padlen = (byte) (0xFF & (keysize - (plaintextraw.length % keysize))); byte[] padding = new byte[padlen]; for (int i = 0; i < padlen; i++) { padding[i] = padlen; } byte[] padded = ArrayConverter.concatenate(plaintextraw, padding); return padded; }
public byte[] getCompleteEncryptedCipherText() { if (explicitIv) { return ArrayConverter.concatenate(initialisationVector, encryptedCipherText); } else { return encryptedCipherText; } } }
/** * Computes the HKDF-Label as defined in TLS 1.3 */ private static byte[] labelEncoder(byte[] hashValue, String labelIn, int outLen) { String label = "tls13 " + labelIn; int labelLength = label.getBytes().length; int hashValueLength = hashValue.length; byte[] result = ArrayConverter.concatenate(ArrayConverter.intToBytes(outLen, 2), ArrayConverter.intToBytes(labelLength, 1), label.getBytes(), ArrayConverter.intToBytes(hashValueLength, 1), hashValue); return result; }
public BigInteger calculateX(byte[] salt, byte[] identity, byte[] password) { byte[] hashInput1 = ArrayConverter.concatenate(identity, ArrayConverter.hexStringToByteArray("3A"), password); LOGGER.debug("HashInput for hashInput1: " + ArrayConverter.bytesToHexString(hashInput1)); byte[] hashOutput1 = SHAsum(hashInput1); LOGGER.debug("Hashvalue for hashInput1: " + ArrayConverter.bytesToHexString(hashOutput1)); byte[] hashInput2 = ArrayConverter.concatenate(salt, hashOutput1); LOGGER.debug("HashInput for hashInput2: " + ArrayConverter.bytesToHexString(hashInput2)); byte[] hashOutput2 = SHAsum(hashInput2); LOGGER.debug("Hashvalue for hashInput2: " + ArrayConverter.bytesToHexString(hashOutput2)); return new BigInteger(1, hashOutput2); }
private BigInteger calculateSRP6Multiplier(BigInteger modulus, BigInteger generator) { BigInteger srp6Multiplier; byte[] paddedGenerator = calculatePadding(modulus, generator); byte[] hashInput = ArrayConverter.concatenate(ArrayConverter.bigIntegerToByteArray(modulus), paddedGenerator); LOGGER.debug("HashInput SRP6Multi: " + ArrayConverter.bytesToHexString(hashInput)); byte[] hashOutput = SHAsum(hashInput); return new BigInteger(1, hashOutput); }
private BigInteger calculateSRP6Multiplier(BigInteger modulus, BigInteger generator) { BigInteger srp6Multiplier; byte[] paddedGenerator = calculatePadding(modulus, generator); byte[] hashInput = ArrayConverter.concatenate(ArrayConverter.bigIntegerToByteArray(modulus), paddedGenerator); LOGGER.debug("HashInput SRP6Multi: " + ArrayConverter.bytesToHexString(hashInput)); byte[] hashOutput = SHAsum(hashInput); return new BigInteger(1, hashOutput); }
protected ECDomainParameters generateEcParameters(NamedGroup group) { InputStream is = new ByteArrayInputStream(ArrayConverter.concatenate( new byte[] { EllipticCurveType.NAMED_CURVE.getValue() }, group.getValue())); try { return ECCUtilsBCWrapper.readECParameters(group, ECPointFormat.UNCOMPRESSED, is); } catch (IOException ex) { throw new PreparationException("Failed to generate EC domain parameters", ex); } }
protected ECDomainParameters getDomainParameters(EllipticCurveType curveType, NamedGroup namedGroup) { InputStream stream = new ByteArrayInputStream(ArrayConverter.concatenate(new byte[] { curveType.getValue() }, namedGroup.getValue())); try { return ECCUtilsBCWrapper.readECParameters(new NamedGroup[] { namedGroup }, new ECPointFormat[] { ECPointFormat.UNCOMPRESSED }, stream); } catch (IOException ex) { throw new PreparationException("Failed to generate EC domain parameters", ex); } }
protected ECDomainParameters getDomainParameters(EllipticCurveType curveType, NamedGroup namedGroup) { InputStream stream = new ByteArrayInputStream(ArrayConverter.concatenate(new byte[] { curveType.getValue() }, namedGroup.getValue())); try { return ECCUtilsBCWrapper.readECParameters(new NamedGroup[] { tlsContext.getChooser() .getSelectedNamedGroup() }, new ECPointFormat[] { ECPointFormat.UNCOMPRESSED }, stream); } catch (IOException ex) { throw new PreparationException("Failed to generate EC domain parameters", ex); } } }
private EncryptionResult encryptTLS12(EncryptionRequest request) throws CryptoException { byte[] nonce = ArrayConverter.longToBytes(context.getWriteSequenceNumber(), RecordByteLength.SEQUENCE_NUMBER); byte[] iv = ArrayConverter.concatenate( getKeySet().getWriteIv(context.getConnection().getLocalConnectionEndType()), nonce); LOGGER.debug("Encrypting GCM with the following IV: {}", ArrayConverter.bytesToHexString(iv)); LOGGER.debug("Encrypting GCM with the following AAD: {}", ArrayConverter.bytesToHexString(request.getAdditionalAuthenticatedData())); byte[] ciphertext = encryptCipher.encrypt(iv, GCM_TAG_LENGTH * 8, request.getAdditionalAuthenticatedData(), request.getPlainText()); return new EncryptionResult(iv, ArrayConverter.concatenate(nonce, ciphertext), false); }
protected void prepareSerializedPublicKey(T msg) { msg.setPublicKey(ArrayConverter.concatenate(new byte[] { msg.getEcPointFormat().getValue() }, msg .getEcPointEncoded().getValue())); LOGGER.debug("SerializedPublicKey: " + ArrayConverter.bytesToHexString(msg.getPublicKey().getValue())); }
private void prepareClientServerRandom(PskClientKeyExchangeMessage msg) { clientRandom = ArrayConverter.concatenate(chooser.getClientRandom(), chooser.getServerRandom()); msg.getComputations().setClientServerRandom(clientRandom); LOGGER.debug("ClientServerRandom: " + ArrayConverter.bytesToHexString(msg.getComputations().getClientServerRandom().getValue())); }
private void prepareClientServerRandom(SrpServerKeyExchangeMessage msg) { msg.getComputations().setClientServerRandom( ArrayConverter.concatenate(chooser.getClientRandom(), chooser.getServerRandom())); LOGGER.debug("ClientServerRandom: " + ArrayConverter.bytesToHexString(msg.getComputations().getClientServerRandom().getValue())); }
protected void prepareClientServerRandom(T msg) { clientServerRandom = ArrayConverter.concatenate(chooser.getClientRandom(), chooser.getServerRandom()); msg.getComputations().setClientServerRandom(clientServerRandom); LOGGER.debug("ClientRandom: " + ArrayConverter.bytesToHexString(msg.getComputations().getClientServerRandom().getValue())); }
protected void prepareClientServerRandom(T msg) { msg.getComputations().setClientServerRandom( ArrayConverter.concatenate(chooser.getClientRandom(), chooser.getServerRandom())); LOGGER.debug("ClientServerRandom: " + ArrayConverter.bytesToHexString(msg.getComputations().getClientServerRandom().getValue())); }
private void prepareClientServerRandom() { byte[] random = ArrayConverter.concatenate(chooser.getClientRandom(), chooser.getServerRandom()); msg.getComputations().setClientServerRandom(random); LOGGER.debug("ClientServerRandom: " + ArrayConverter.bytesToHexString(msg.getComputations().getClientServerRandom().getValue())); }
protected void prepareClientServerRandom(T msg) { msg.getComputations().setClientServerRandom( ArrayConverter.concatenate(chooser.getClientRandom(), chooser.getServerRandom())); LOGGER.debug("ClientServerRandom: " + ArrayConverter.bytesToHexString(msg.getComputations().getClientServerRandom().getValue())); }
protected void preparePlainPaddedPremasterSecret(SSL2ClientMasterKeyMessage msg) { msg.getComputations().setPlainPaddedPremasterSecret( ArrayConverter.concatenate(new byte[] { 0x00, 0x02 }, padding, new byte[] { 0x00 }, msg .getComputations().getPremasterSecret().getValue())); LOGGER.debug("PlainPaddedPremasterSecret: " + ArrayConverter.bytesToHexString(msg.getComputations().getPlainPaddedPremasterSecret().getValue())); }
protected void preparePlainPaddedPremasterSecret(T msg) { msg.getComputations().setPlainPaddedPremasterSecret( ArrayConverter.concatenate(new byte[] { 0x00, 0x02 }, padding, new byte[] { 0x00 }, msg .getComputations().getPremasterSecret().getValue())); LOGGER.debug("PlainPaddedPremasterSecret: " + ArrayConverter.bytesToHexString(msg.getComputations().getPlainPaddedPremasterSecret().getValue())); }
public static byte[] calculateEKM(Chooser chooser, int length) throws CryptoException { byte[] masterSecret = chooser.getMasterSecret(); String label = TokenBindingLabel.TOKEN_LABEL; byte[] clientServerRandom = ArrayConverter.concatenate(chooser.getClientRandom(), chooser.getServerRandom()); PRFAlgorithm algorithm = AlgorithmResolver.getPRFAlgorithm(chooser.getSelectedProtocolVersion(), chooser.getSelectedCipherSuite()); return PseudoRandomFunction.compute(algorithm, masterSecret, label, clientServerRandom, length); }