public class NTRUEngine extends java.lang.Object implements AsymmetricBlockCipher
Modifier and Type | Field and Description |
---|---|
private boolean |
forEncryption |
private NTRUEncryptionParameters |
params |
private NTRUEncryptionPrivateKeyParameters |
privKey |
private NTRUEncryptionPublicKeyParameters |
pubKey |
private java.security.SecureRandom |
random |
Constructor and Description |
---|
NTRUEngine()
Constructs a new instance with a set of encryption parameters.
|
Modifier and Type | Method and Description |
---|---|
private byte[] |
buildSData(byte[] oid,
byte[] m,
int l,
byte[] b,
byte[] hTrunc) |
private byte[] |
calcHash(Digest hashAlg) |
private byte[] |
calcHash(Digest hashAlg,
byte[] input) |
private byte[] |
copyOf(byte[] src,
int len) |
private byte[] |
decrypt(byte[] data,
NTRUEncryptionPrivateKeyParameters privKey)
Decrypts a message.
See P1363.1 section 9.2.3. |
protected IntegerPolynomial |
decrypt(IntegerPolynomial e,
Polynomial priv_t,
IntegerPolynomial priv_fp) |
private byte[] |
encrypt(byte[] m,
NTRUEncryptionPublicKeyParameters pubKey)
Encrypts a message.
See P1363.1 section 9.2.2. |
protected IntegerPolynomial |
encrypt(IntegerPolynomial m,
TernaryPolynomial r,
IntegerPolynomial pubKey) |
private int[] |
generateBlindingCoeffs(IndexGenerator ig,
int dr)
Generates an
int array containing dr elements equal to 1
and dr elements equal to -1 using an index generator. |
private Polynomial |
generateBlindingPoly(byte[] seed,
byte[] M)
Deterministically generates a blinding polynomial from a seed and a message representative.
|
int |
getInputBlockSize()
returns the largest size an input block can be.
|
int |
getOutputBlockSize()
returns the maximum size of the block produced by this cipher.
|
void |
init(boolean forEncryption,
CipherParameters parameters)
initialise the cipher.
|
private int |
log2(int value) |
private IntegerPolynomial |
MGF(byte[] seed,
int N,
int minCallsR,
boolean hashSeed)
An implementation of MGF-TP-1 from P1363.1 section 8.4.1.1.
|
byte[] |
processBlock(byte[] in,
int inOff,
int len)
process the block of len bytes stored in in from offset inOff.
|
private void |
putInt(Digest hashAlg,
int counter) |
private boolean forEncryption
private NTRUEncryptionParameters params
private NTRUEncryptionPublicKeyParameters pubKey
private NTRUEncryptionPrivateKeyParameters privKey
private java.security.SecureRandom random
public NTRUEngine()
public void init(boolean forEncryption, CipherParameters parameters)
AsymmetricBlockCipher
init
in interface AsymmetricBlockCipher
forEncryption
- if true the cipher is initialised for
encryption, if false for decryption.parameters
- the key and other data required by the cipher.public int getInputBlockSize()
AsymmetricBlockCipher
getInputBlockSize
in interface AsymmetricBlockCipher
public int getOutputBlockSize()
AsymmetricBlockCipher
getOutputBlockSize
in interface AsymmetricBlockCipher
public byte[] processBlock(byte[] in, int inOff, int len) throws InvalidCipherTextException
AsymmetricBlockCipher
processBlock
in interface AsymmetricBlockCipher
in
- the input datainOff
- offset into the in array where the data startslen
- the length of the block to be processed.InvalidCipherTextException
- data decrypts improperly.private byte[] encrypt(byte[] m, NTRUEncryptionPublicKeyParameters pubKey)
m
- The message to encryptpubKey
- the public key to encrypt the message withprivate byte[] buildSData(byte[] oid, byte[] m, int l, byte[] b, byte[] hTrunc)
protected IntegerPolynomial encrypt(IntegerPolynomial m, TernaryPolynomial r, IntegerPolynomial pubKey)
private Polynomial generateBlindingPoly(byte[] seed, byte[] M)
seed
- M
- message representativeprivate int[] generateBlindingCoeffs(IndexGenerator ig, int dr)
int
array containing dr
elements equal to 1
and dr
elements equal to -1
using an index generator.ig
- an index generatordr
- number of ones / negative ones-1
and 1
private IntegerPolynomial MGF(byte[] seed, int N, int minCallsR, boolean hashSeed)
seed
- N
- minCallsR
- hashSeed
- whether to hash the seedprivate void putInt(Digest hashAlg, int counter)
private byte[] calcHash(Digest hashAlg)
private byte[] calcHash(Digest hashAlg, byte[] input)
private byte[] decrypt(byte[] data, NTRUEncryptionPrivateKeyParameters privKey) throws InvalidCipherTextException
data
- The message to decryptprivKey
- the corresponding private keyInvalidCipherTextException
- if the encrypted data is invalid, or maxLenBytes
is greater than 255protected IntegerPolynomial decrypt(IntegerPolynomial e, Polynomial priv_t, IntegerPolynomial priv_fp)
e
- priv_t
- a polynomial such that if fastFp=true
, f=1+3*priv_t
; otherwise, f=priv_t
priv_fp
- private byte[] copyOf(byte[] src, int len)
private int log2(int value)