/** * Calculate the initial (pre message block) chaining state. */ private void createInitialState() { long[] precalc = (long[])INITIAL_STATES.get(variantIdentifier(getBlockSize(), getOutputSize())); if ((key == null) && (precalc != null)) { // Precalculated UBI(CFG) chain = Arrays.clone(precalc); } else { // Blank initial state chain = new long[getBlockSize() / 8]; // Process key block if (key != null) { ubiComplete(SkeinParameters.PARAM_TYPE_KEY, key); } // Process configuration block ubiComplete(PARAM_TYPE_CONFIG, new Configuration(outputSizeBytes * 8).getBytes()); } // Process additional pre-message parameters if (preMessageParameters != null) { for (int i = 0; i < preMessageParameters.length; i++) { Parameter param = preMessageParameters[i]; ubiComplete(param.getType(), param.getValue()); } } initialState = Arrays.clone(chain); }
private void testParameters() throws Exception { Mac mac = Mac.getInstance("Skein-Mac-512-160", provider); // test six, init using SkeinParameters mac.init(new SecretKeySpec(shortMacKey, "Skein-Mac-512-160"), new SkeinParameters.Builder().setKeyIdentifier(keyIdentifier).build()); byte[] result = mac.doFinal(shortMacMessage); if (!MessageDigest.isEqual(result, keyIdentifierVector)) { fail("Mac with key identifier failed.", new String(Hex.encode(keyIdentifierVector)), new String(Hex.encode(result))); } }
protected void engineInit( Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException { CipherParameters param; if (key == null) { throw new InvalidKeyException("key is null"); } if (key instanceof BCPBEKey) { BCPBEKey k = (BCPBEKey)key; if (k.getParam() != null) { param = k.getParam(); } else if (params instanceof PBEParameterSpec) { param = PBE.Util.makePBEMacParameters(k, params); } else { throw new InvalidAlgorithmParameterException("PBE requires PBE parameters to be set."); } } else if (params instanceof IvParameterSpec) { param = new ParametersWithIV(new KeyParameter(key.getEncoded()), ((IvParameterSpec)params).getIV()); } else if (params instanceof SkeinParameterSpec) { param = new SkeinParameters.Builder(copyMap(((SkeinParameterSpec)params).getParameters())).setKey(key.getEncoded()).build(); } else if (params == null) { param = new KeyParameter(key.getEncoded()); } else { throw new InvalidAlgorithmParameterException("unknown parameter type."); } macEngine.init(param); }
protected void engineInit( Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException { CipherParameters param; if (key == null) { throw new InvalidKeyException("key is null"); } if (key instanceof BCPBEKey) { BCPBEKey k = (BCPBEKey)key; if (k.getParam() != null) { param = k.getParam(); } else if (params instanceof PBEParameterSpec) { param = PBE.Util.makePBEMacParameters(k, params); } else { throw new InvalidAlgorithmParameterException("PBE requires PBE parameters to be set."); } } else if (params instanceof IvParameterSpec) { param = new ParametersWithIV(new KeyParameter(key.getEncoded()), ((IvParameterSpec)params).getIV()); } else if (params instanceof SkeinParameters) { param = new SkeinParameters.Builder((SkeinParameters) params).setKey(key.getEncoded()).build(); } else if (params == null) { param = new KeyParameter(key.getEncoded()); } else { throw new InvalidAlgorithmParameterException("unknown parameter type."); } macEngine.init(param); }
/** * Optionally initialises the Skein digest with the provided parameters.<br> * See {@link SkeinParameters} for details on the parameterisation of the Skein hash function. * * @param params the parameters to apply to this engine, or <code>null</code> to use no parameters. */ public void init(SkeinParameters params) { engine.init(params); }