org.bouncycastle.math.ec.rfc8032.Codec Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-lts8on Show documentation
Show all versions of bcprov-lts8on Show documentation
The Long Term Stable (LTS) Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains the JCA/JCE provider and low-level API for the BC LTS version 2.73.7 for Java 8 and later.
package org.bouncycastle.math.ec.rfc8032;
abstract class Codec
{
static int decode16(byte[] bs, int off)
{
int n = bs[off] & 0xFF;
n |= (bs[++off] & 0xFF) << 8;
return n;
}
static int decode24(byte[] bs, int off)
{
int n = bs[ off] & 0xFF;
n |= (bs[++off] & 0xFF) << 8;
n |= (bs[++off] & 0xFF) << 16;
return n;
}
static int decode32(byte[] bs, int off)
{
int n = bs[off] & 0xFF;
n |= (bs[++off] & 0xFF) << 8;
n |= (bs[++off] & 0xFF) << 16;
n |= bs[++off] << 24;
return n;
}
static void decode32(byte[] bs, int bsOff, int[] n, int nOff, int nLen)
{
for (int i = 0; i < nLen; ++i)
{
n[nOff + i] = decode32(bs, bsOff + i * 4);
}
}
static void encode24(int n, byte[] bs, int off)
{
bs[ off] = (byte)(n );
bs[++off] = (byte)(n >>> 8);
bs[++off] = (byte)(n >>> 16);
}
static void encode32(int n, byte[] bs, int off)
{
bs[ off] = (byte)(n );
bs[++off] = (byte)(n >>> 8);
bs[++off] = (byte)(n >>> 16);
bs[++off] = (byte)(n >>> 24);
}
static void encode32(int[] n, int nOff, int nLen, byte[] bs, int bsOff)
{
for (int i = 0; i < nLen; ++i)
{
encode32(n[nOff + i], bs, bsOff + i * 4);
}
}
static void encode56(long n, byte[] bs, int off)
{
encode32((int)n, bs, off);
encode24((int)(n >>> 32), bs, off + 4);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy