org.bouncycastle.crypto.modes.GOST3413CipherUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-jdk15on Show documentation
Show all versions of bcprov-jdk15on Show documentation
The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 and up.
The newest version!
package org.bouncycastle.crypto.modes;
import org.bouncycastle.util.Arrays;
/**
* Some methods for GOST 3412 cipher algorithm
*/
class GOST3413CipherUtil
{
/**
* copy first size elements from from
*
* @param from source array
* @param size size of new array
* @return
*/
public static byte[] MSB(byte[] from, int size)
{
return Arrays.copyOf(from, size);
}
/**
* copy last size elements from from
*
* @param from source array
* @param size size of new array
* @return
*/
public static byte[] LSB(byte[] from, int size)
{
byte[] result = new byte[size];
System.arraycopy(from, from.length - size, result, 0, size);
return result;
}
/**
* componentwise addition modulo 2 (XOR)
*
* @param in clear text
* @param gamma gamma parameter
* @return
*/
public static byte[] sum(byte[] in, byte[] gamma)
{
byte[] out = new byte[in.length];
for (int i = 0; i < in.length; i++)
{
out[i] = (byte)(in[i] ^ gamma[i]);
}
return out;
}
/**
* copy from input array size bytes with offset
*
* @param input input byte array
* @param size count bytes to copy
* @param offset inputs offset
* @return
*/
public static byte[] copyFromInput(byte[] input, int size, int offset)
{
if (input.length < (size + offset))
{
size = input.length - offset;
}
byte[] newIn = new byte[size];
System.arraycopy(input, offset, newIn, 0, size);
return newIn;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy