public static byte[] routingKeyFromFullKey(byte[] keyBuf) { if(keyBuf.length != FULL_KEY_LENGTH) { Logger.error(NodeSSK.class, "routingKeyFromFullKey() on buffer length "+keyBuf.length); } byte[] encryptedHashedDocname = Arrays.copyOfRange(keyBuf, 2, 2+E_H_DOCNAME_SIZE); byte[] pubKeyHash = Arrays.copyOfRange(keyBuf, 2+E_H_DOCNAME_SIZE, 2+E_H_DOCNAME_SIZE+PUBKEY_HASH_SIZE); return makeRoutingKey(pubKeyHash, encryptedHashedDocname); }
public NodeSSK(byte[] pkHash, byte[] ehDocname, byte cryptoAlgorithm) { super(makeRoutingKey(pkHash, ehDocname)); this.encryptedHashedDocname = ehDocname; this.pubKeyHash = pkHash; this.cryptoAlgorithm = cryptoAlgorithm; this.pubKey = null; 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 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); }