public byte[] asBytesHash() { byte[] hash = SHA256.digest(asBytes()); return hash; }
public static byte[] digest(byte[] data) { MessageDigest md = null; try { md = getMessageDigest(); return md.digest(data); } finally { returnMessageDigest(md); } }
try { fis = new FileInputStream(filename); MessageDigest md = SHA256.getMessageDigest(); SHA256.hash(fis, md); byte[] hash = md.digest(); SHA256.returnMessageDigest(md); fis.close(); fis = null;
throw new FSParseException("ecdsa.P256.pub is invalid!"); this.peerECDSAPubKey = key; peerECDSAPubKeyHash = SHA256.digest(peerECDSAPubKey.getEncoded()); identity = SHA256.digest(DSAPublicKey.create(sfs, Global.DSAgroupBigA).asBytes()); throw new FSParseException("No identity"); identityAsBase64String = Base64.encode(identity); identityHash = SHA256.digest(identity); identityHashHash = SHA256.digest(identityHash); swapIdentifier = Fields.bytesToLong(identityHashHash); hashCode = Fields.hashCode(peerECDSAPubKeyHash); byte[] nodeKeyHash = crypto.identityHashHash; int digestLength = SHA256.getDigestLength(); incomingSetupKey = new byte[digestLength]; for(int i = 0; i < incomingSetupKey.length; i++)
public void recycle(MessageDigest md) { if(this.equals(SHA256)) { freenet.crypt.SHA256.returnMessageDigest(md); } // Else no pooling. } }
public MessageDigest get() throws NoSuchAlgorithmException { if(javaName == null) { if(this.name().equals("ED2K")) return new Ed2MessageDigest(); if(this.name().equals("TTH")) return new TigerTree(); } if(name().equals("SHA256")) { // User the pool return freenet.crypt.SHA256.getMessageDigest(); } else { return MessageDigest.getInstance(javaName, Util.mdProviders.get(javaName)); } }
byte[] finalHash = md256.digest(cdata); SHA256.returnMessageDigest(md256);
/** * Encode a splitfile block. * @param data The data to encode. Must be exactly DATA_LENGTH bytes. * @param cryptoKey The encryption key. Can be null in which case this is equivalent to a normal block * encode. */ static public ClientCHKBlock encodeSplitfileBlock(byte[] data, byte[] cryptoKey, byte cryptoAlgorithm) throws CHKEncodeException { if(data.length != CHKBlock.DATA_LENGTH) throw new IllegalArgumentException(); if(cryptoKey != null && cryptoKey.length != 32) throw new IllegalArgumentException(); MessageDigest md256 = SHA256.getMessageDigest(); // No need to pad if(cryptoKey == null) { cryptoKey = md256.digest(data); } if(cryptoAlgorithm == Key.ALGO_AES_PCFB_256_SHA256) return innerEncode(data, CHKBlock.DATA_LENGTH, md256, cryptoKey, false, (short)-1, cryptoAlgorithm); else if(cryptoAlgorithm != Key.ALGO_AES_CTR_256_SHA256) throw new IllegalArgumentException("Unknown crypto algorithm: "+cryptoAlgorithm); if(Rijndael.AesCtrProvider == null) { return encodeNewNoJCA(data, CHKBlock.DATA_LENGTH, md256, cryptoKey, false, (short)-1, cryptoAlgorithm, KeyBlock.HASH_SHA256); } else { return encodeNew(data, CHKBlock.DATA_LENGTH, md256, cryptoKey, false, (short)-1, cryptoAlgorithm, KeyBlock.HASH_SHA256); } }
public static byte[] getCryptoKey(byte[] hash) { // This is exactly the same algorithm used by e.g. JFK for generating multiple session keys from a single generated value. // The only difference is we use a constant of more than one byte's length here, to avoid having to keep a registry. MessageDigest md = SHA256.getMessageDigest(); md.update(hash); md.update(SPLITKEY); byte[] buf = md.digest(); SHA256.returnMessageDigest(md); return buf; }
private static String getForceValue(FreenetURI key, long time) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try{ bos.write(random); bos.write(key.toString().getBytes("UTF-8")); bos.write(Long.toString(time / FORCE_GRAIN_INTERVAL).getBytes("UTF-8")); } catch (IOException e) { throw new Error(e); } String f = HexUtil.bytesToHex(SHA256.digest(bos.toByteArray())); return f; }
MessageDigest md = SHA256.getMessageDigest(); byte[] foundHash; try { try { is = data.getInputStream(); SHA256.hash(is, md); } catch (IOException e) { SHA256.returnMessageDigest(md); Logger.error(this, "Got IOE: " + e.getMessage(), e); throw new MessageInvalidException(ProtocolErrorMessage.COULD_NOT_READ_FILE, SHA256.returnMessageDigest(md);
byte[] finalHash = md256.digest(cdata); SHA256.returnMessageDigest(md256);
MessageDigest md256 = SHA256.getMessageDigest();
private static byte[] makeRoutingKey(byte[] pkHash, byte[] ehDocname) { MessageDigest md256 = SHA256.getMessageDigest(); md256.update(ehDocname); md256.update(pkHash); byte[] key = md256.digest(); SHA256.returnMessageDigest(md256); return key; }
/** * Create the cryptographic keys etc from scratch */ public void initCrypto() { ecdsaP256 = new ECDSA(ECDSA.Curves.P256); ecdsaPubKeyHash = SHA256.digest(ecdsaP256.getPublicKey().getEncoded()); myARK = InsertableClientSSK.createRandom(random, "ark"); myARKNumber = 0; clientNonce = new byte[32]; node.random.nextBytes(clientNonce); myIdentity = new byte[IDENTITY_LENGTH]; node.random.nextBytes(myIdentity); identityHash = SHA256.digest(myIdentity); identityHashHash = SHA256.digest(identityHash); anonSetupCipher.initialize(identityHash); }
byte[] finalHash = md256.digest(data); SHA256.returnMessageDigest(md256);
public static byte[] getCrossSegmentSeed(byte[] hash) { // This is exactly the same algorithm used by e.g. JFK for generating multiple session keys from a single generated value. // The only difference is we use a constant of more than one byte's length here, to avoid having to keep a registry. MessageDigest md = SHA256.getMessageDigest(); md.update(hash); md.update(CROSS_SEGMENT_SEED); byte[] buf = md.digest(); SHA256.returnMessageDigest(md); return buf; }
public NodeSSK(byte[] pkHash, byte[] ehDocname, DSAPublicKey pubKey, byte cryptoAlgorithm) throws SSKVerifyException { super(makeRoutingKey(pkHash, ehDocname)); this.encryptedHashedDocname = ehDocname; this.pubKeyHash = pkHash; this.cryptoAlgorithm = cryptoAlgorithm; this.pubKey = pubKey; if(pubKey != null) { byte[] hash = SHA256.digest(pubKey.asBytes()); if(!Arrays.equals(hash, pkHash)) throw new SSKVerifyException("Invalid pubKey: wrong hash"); } if(ehDocname.length != E_H_DOCNAME_SIZE) throw new IllegalArgumentException("ehDocname must be "+E_H_DOCNAME_SIZE+" bytes"); if(pkHash.length != PUBKEY_HASH_SIZE) throw new IllegalArgumentException("pubKeyHash must be "+PUBKEY_HASH_SIZE+" bytes"); hashCode = Fields.hashCode(pkHash) ^ Fields.hashCode(ehDocname); }
public byte[] saltKey(Key key) { MessageDigest md = SHA256.getMessageDigest(); md.update(key.getRoutingKey()); md.update(globalSalt); byte[] ret = md.digest(); SHA256.returnMessageDigest(md); return ret; }
public static InsertableClientSSK createRandom(RandomSource r, String docName) { byte[] ckey = new byte[CRYPTO_KEY_LENGTH]; r.nextBytes(ckey); DSAGroup g = Global.DSAgroupBigA; DSAPrivateKey privKey = new DSAPrivateKey(g, r); DSAPublicKey pubKey = new DSAPublicKey(g, privKey); try { byte[] pkHash = SHA256.digest(pubKey.asBytes()); return new InsertableClientSSK(docName, pkHash, pubKey, privKey, ckey, Key.ALGO_AES_PCFB_256_SHA256); } catch (MalformedURLException e) { throw new Error(e); } }