public byte[] asBytesHash() { byte[] hash = SHA256.digest(asBytes()); return hash; }
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; }
/** * 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); }
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 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); } }
SSKInsertSender(SSKBlock block, long uid, InsertTag tag, short htl, PeerNode source, Node node, boolean fromStore, boolean canWriteClientCache, boolean forkOnCacheable, boolean preferInsert, boolean ignoreLowBackoff, boolean realTimeFlag) { super(block.getKey(), realTimeFlag, source, node, htl, uid); this.fromStore = fromStore; this.origUID = uid; this.origTag = tag; myKey = block.getKey(); data = block.getRawData(); headers = block.getRawHeaders(); pubKey = myKey.getPubKey(); if(pubKey == null) throw new IllegalArgumentException("Must have pubkey to insert data!!"); // pubKey.fingerprint() is not the same as hash(pubKey.asBytes())). FIXME it should be! byte[] pubKeyAsBytes = pubKey.asBytes(); pubKeyHash = SHA256.digest(pubKeyAsBytes); this.block = block; startTime = System.currentTimeMillis(); this.forkOnCacheable = forkOnCacheable; this.preferInsert = preferInsert; this.ignoreLowBackoff = ignoreLowBackoff; this.realTimeFlag = realTimeFlag; }
public void setPubKey(DSAPublicKey pubKey2) throws SSKVerifyException { if(pubKey == pubKey2) return; if(pubKey2 == null) return; if((pubKey == null) || !pubKey2.equals(pubKey)) { if(pubKey2 != null) { byte[] newPubKeyHash = SHA256.digest(pubKey2.asBytes()); if(Arrays.equals(pubKeyHash, newPubKeyHash)) { if(pubKey != null) { // same hash, yet different keys! Logger.error(this, "Found SHA-256 collision or something... WTF?"); throw new SSKVerifyException("Invalid new pubkey: "+pubKey2+" old pubkey: "+pubKey); } // Valid key, assign. } else { throw new SSKVerifyException("New pubkey has invalid hash"); } } pubKey = pubKey2; } }
byte[] message1 = new byte[nonceSizeHashed+modulusLength+(unknownInitiator ? NodeCrypto.IDENTITY_LENGTH : 0)]; System.arraycopy(SHA256.digest(nonce), 0, message1, offset, nonceSizeHashed); offset += nonceSizeHashed; System.arraycopy(myExponential, 0, message1, offset, modulusLength);
byte[] hash = SHA256.digest(output); if(logDEBUG) Logger.debug(this, "Data hash: "+HexUtil.bytesToHex(hash)); int prePaddingLength = iv.length + hash.length + 2 /* length */ + output.length;
int nonceSize = getNonceSize(negType); byte[] nonceInitiatorHashed = SHA256.digest(nonceInitiator);
pcfb.blockDecipher(payload, 0, payload.length); byte[] realHash = SHA256.digest(payload);
synchronized (pn.jfkNoncesSent) { for(byte[] buf : pn.jfkNoncesSent) { if(MessageDigest.isEqual(nonceInitiator, SHA256.digest(buf))) myNi = buf;
pcfb.blockDecipher(payload, 0, payload.length); byte[] realHash = SHA256.digest(payload);
pcfb.blockDecipher(payload, 0, payload.length); byte[] realHash = SHA256.digest(payload);
DSAPrivateKey privKey = new DSAPrivateKey(g, random); DSAPublicKey pubKey = new DSAPublicKey(g, privKey); byte[] pkHash = SHA256.digest(pubKey.asBytes()); String docName = "myDOC"; InsertableClientSSK ik = new InsertableClientSSK(docName, pkHash, pubKey, privKey, ckey, Key.ALGO_AES_PCFB_256_SHA256);
DSAPrivateKey privKey = new DSAPrivateKey(g, random); DSAPublicKey pubKey = new DSAPublicKey(g, privKey); byte[] pkHash = SHA256.digest(pubKey.asBytes()); String docName = "myDOC"; InsertableClientSSK ik = new InsertableClientSSK(docName, pkHash, pubKey, privKey, ckey, Key.ALGO_AES_PCFB_256_SHA256);
DSAPrivateKey privKey = new DSAPrivateKey(g, random); DSAPublicKey pubKey = new DSAPublicKey(g, privKey); byte[] pkHash = SHA256.digest(pubKey.asBytes()); String docName = "myDOC"; InsertableClientSSK ik = new InsertableClientSSK(docName, pkHash, pubKey, privKey, ckey, Key.ALGO_AES_PCFB_256_SHA256);
DSAPrivateKey privKey = new DSAPrivateKey(g, random); DSAPublicKey pubKey = new DSAPublicKey(g, privKey); byte[] pkHash = SHA256.digest(pubKey.asBytes()); String docName = "myDOC"; InsertableClientSSK ik = new InsertableClientSSK(docName, pkHash, pubKey, privKey, ckey, Key.ALGO_AES_PCFB_256_SHA256); byte[] pkHash2 = SHA256.digest(pubKey2.asBytes()); InsertableClientSSK ik2 = new InsertableClientSSK(docName, pkHash2, pubKey2, privKey2, ckey, Key.ALGO_AES_PCFB_256_SHA256); block = ik2.encode(bucket, false, false, (short)-1, bucket.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false);
DSAPrivateKey privKey = new DSAPrivateKey(g, random); DSAPublicKey pubKey = new DSAPublicKey(g, privKey); byte[] pkHash = SHA256.digest(pubKey.asBytes()); String docName = "myDOC"; InsertableClientSSK ik = new InsertableClientSSK(docName, pkHash, pubKey, privKey, ckey, Key.ALGO_AES_PCFB_256_SHA256);