@Override public byte[] getPubkeyBytes() { return pubKey.asBytes(); }
public byte[] asPaddedBytes() { byte[] asBytes = asBytes(); if(asBytes.length == PADDED_SIZE) return asBytes; if(asBytes.length > PADDED_SIZE) throw new Error("Cannot fit key in " + PADDED_SIZE + " - real size is " + asBytes.length); return Arrays.copyOf(asBytes, PADDED_SIZE); }
public byte[] asBytesHash() { byte[] hash = SHA256.digest(asBytes()); return hash; }
public static ClientKSK create(String keyword) { MessageDigest md256 = SHA256.getMessageDigest(); try { byte[] keywordHash; try { keywordHash = md256.digest(keyword.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new Error("Impossible: JVM doesn't support UTF-8: " + e, e); } MersenneTwister mt = new MersenneTwister(keywordHash); DSAPrivateKey privKey = new DSAPrivateKey(Global.DSAgroupBigA, mt); DSAPublicKey pubKey = new DSAPublicKey(Global.DSAgroupBigA, privKey); byte[] pubKeyHash = md256.digest(pubKey.asBytes()); try { return new ClientKSK(keyword, pubKeyHash, pubKey, privKey, keywordHash); } catch (MalformedURLException e) { throw new Error(e); } } finally { SHA256.returnMessageDigest(md256); } }
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); }
try { if (pubKey != null) { byte[] pubKeyAsBytes = pubKey.asBytes(); md.update(pubKeyAsBytes); byte[] otherPubKeyHash = md.digest();
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; } }
identity = SHA256.digest(DSAPublicKey.create(sfs, Global.DSAgroupBigA).asBytes());
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);