javacryptographydigital-signaturebouncycastlentrusign

bouncycastle fails NTRU generation


There are three types of default security levels of NTRU, implemented in bouncy-castle:

 1. NTRUSigningKeyGenerationParameters.TEST157
 2. NTRUSigningKeyGenerationParameters.APR2011_439
 3. NTRUSigningKeyGenerationParameters.APR2011_743

First two are generated normally, but when I try to generate the tird one, I get the next Exception:

SEVERE: Servlet.service() for servlet [mvc-dispatcher] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Signing failed: too many retries (max=100)] with root cause java.lang.IllegalStateException: Signing failed: too many retries (max=100)

Here is piece of my code:

NTRUSigningPrivateKeyParameters ntruSigningPrivateKeyParameters1 = null;

    NTRUSigner ntruSigner = new NTRUSigner(ntruSigningKeyGenerationParameters.getSigningParameters());

    try {
        ntruSigningPrivateKeyParameters1 = new NTRUSigningPrivateKeyParameters(ntruSigningPrivateKeyParameters.getEncoded(), ntruSigningKeyGenerationParameters);
    } catch (IOException e) {

        e.printStackTrace();
    }

    ntruSigner.init(true, ntruSigningPrivateKeyParameters);
    byte [] res = ntruSigner.generateSignature();

Calling ntruSigner.generateSignature() with the third set of parameters leads to a such Exception.

Does anyone knows how to solve it?


Solution

  • Currently, it's a bug, so there are two solutions:

    1. use another library - tbuktu's github project (bouncy-castle is using it with some modifications, as I see)
    2. download sources, catch the bug of this generation parameter, solve it and pack into library for a project