Add support for Dual EC DRBG from SP800-90. Include updates to algorithm
[openssl.git] / fips / rand / fips_rand_lcl.h
index eeed0eca2385254b52e9bf3121c6c3cb22479055..32809d41ac111343deac92b29245f5e248eed2a8 100644 (file)
@@ -52,7 +52,9 @@
  */
 
 typedef struct drbg_hash_ctx_st DRBG_HASH_CTX;
+typedef struct drbg_hmac_ctx_st DRBG_HMAC_CTX;
 typedef struct drbg_ctr_ctx_st DRBG_CTR_CTX;
+typedef struct drbg_ec_ctx_st DRBG_EC_CTX;
 
 /* 888 bits from 10.1 table 2 */
 #define HASH_PRNG_MAX_SEEDLEN  111
@@ -67,6 +69,14 @@ struct drbg_hash_ctx_st
        unsigned char vtmp[HASH_PRNG_MAX_SEEDLEN];
        };
 
+struct drbg_hmac_ctx_st
+       {
+       const EVP_MD *md;
+       HMAC_CTX hctx;
+       unsigned char K[EVP_MAX_MD_SIZE];
+       unsigned char V[EVP_MAX_MD_SIZE];
+       };
+
 struct drbg_ctr_ctx_st
        {
        AES_KEY ks;
@@ -82,10 +92,42 @@ struct drbg_ctr_ctx_st
        unsigned char KX[48];
        };
 
+/* Maximum seed length */
+#define EC_PRNG_MAX_SEEDLEN    66
+
+struct drbg_ec_ctx_st
+       {
+       /* Message digest to use */
+       const EVP_MD *md;
+       /* Curve to use: generator is point P */
+       EC_GROUP *curve;
+       /* Point Q */
+       EC_POINT *Q;
+       /* Temporary point */
+       EC_POINT *ptmp;
+       size_t exbits;
+       /* Secret s value */
+       BIGNUM *s;
+       /* Buffer to store byte version of s value */
+       unsigned char sbuf[EC_PRNG_MAX_SEEDLEN];
+       /* Buffer to store byte version of t value */
+       unsigned char tbuf[EC_PRNG_MAX_SEEDLEN];
+       /* Digest context */
+       EVP_MD_CTX mctx;
+       /* Temporary value storage: should always exceed max digest length */
+       unsigned char vtmp[EC_PRNG_MAX_SEEDLEN];
+       /* Flag to indicate s = s * P has been deferred */
+       int sp_defer;
+       /* Temp BN context */
+       BN_CTX *bctx;
+       };
+
 /* DRBG flags */
 
 /* Functions shouldn't call err library */
 #define        DRBG_FLAG_NOERR                 0x4
+/* Custom reseed checking */
+#define        DRBG_CUSTOM_RESEED              0x8
 
 /* DRBG status values */
 /* not initialised */
@@ -137,7 +179,9 @@ struct drbg_ctx_st
        union 
                {
                DRBG_HASH_CTX hash;
+               DRBG_HMAC_CTX hmac;
                DRBG_CTR_CTX  ctr;
+               DRBG_EC_CTX  ec;
                } d;
        /* Initialiase PRNG and setup callbacks below */
        int (*init)(DRBG_CTX *ctx, int nid, int security, unsigned int flags);
@@ -157,6 +201,9 @@ struct drbg_ctx_st
        /* uninstantiate */
        int (*uninstantiate)(DRBG_CTX *ctx);
 
+       /* Entropy source block length */
+       size_t entropy_blocklen;
+
        /* entropy gathering function */
        size_t (*get_entropy)(DRBG_CTX *ctx, unsigned char **pout,
                                int entropy, size_t min_len, size_t max_len);
@@ -188,5 +235,7 @@ struct drbg_ctx_st
 
 int fips_drbg_ctr_init(DRBG_CTX *dctx);
 int fips_drbg_hash_init(DRBG_CTX *dctx);
+int fips_drbg_hmac_init(DRBG_CTX *dctx);
+int fips_drbg_ec_init(DRBG_CTX *dctx);
 int fips_drbg_kat(DRBG_CTX *dctx, int nid, unsigned int flags);
 int fips_drbg_cprng_test(DRBG_CTX *dctx, const unsigned char *out);