crypto/ringlwe/ringlwe_key.c
/* Allocate auxiliary variables (context) data structure */
Allocate auxiliary variables (context) data structure
Allocate auxiliary variables ( context ) data structure
RLWE_CTX *RLWE_CTX_new(const int nid) {
  RLWE_CTX *ctx;
  ctx = (RLWE_CTX *)OPENSSL_malloc(sizeof(RLWE_CTX));
  if (ctx == NULL) {
    RINGLWEerr(RINGLWE_F_RLWE_CTX_NEW, ERR_R_MALLOC_FAILURE);
    return (NULL);
  }
  ctx->nid = nid;
  ctx->param_data = RINGLWE_PARAM_DATA_set(nid);
  if (ctx->param_data == NULL) {
    RINGLWEerr(RINGLWE_F_RLWE_CTX_NEW, RINGLWE_R_PARAM_UNKNOWN);
    goto err;
  }
  memcpy(ctx->descriptor, (const unsigned char *)"RLWE", 4);
  ctx->descriptor[4] = (ctx->param_data->m>>24) & 0xff;
  ctx->descriptor[5] = (ctx->param_data->m>>16) & 0xff;
  ctx->descriptor[6] = (ctx->param_data->m>>8) & 0xff;
  ctx->descriptor[7] = (ctx->param_data->m) & 0xff;
  ctx->descriptor[8] = (ctx->param_data->q>>24) & 0xff;
  ctx->descriptor[9] = (ctx->param_data->q>>16) & 0xff;
  ctx->descriptor[10]= (ctx->param_data->q>>8) & 0xff;
  ctx->descriptor[11]= (ctx->param_data->q) & 0xff;
#ifndef OPENSSL_NO_SHA
  unsigned char sha_outbuf[SHA_DIGEST_LENGTH];
  SHA1((void *)ctx->param_data->a, ctx->param_data->m * sizeof(RINGELT), sha_outbuf);
  memcpy(ctx->descriptor+12, sha_outbuf, _RLWE_DESCRIPTOR_LEN - 12);
#else
  memset(ctx->descriptor+12, 0, 20);
#endif
  return (ctx);
 err:
  OPENSSL_free(ctx);
  return (NULL);
}
RLWE_CTX * RLWE_CTX_new ( const int nid ) { RLWE_CTX * ctx ; ctx = ( RLWE_CTX * ) OPENSSL_malloc ( sizeof ( RLWE_CTX ) ) ; if ( ctx == NULL ) { RINGLWEerr ( RINGLWE_F_RLWE_CTX_NEW , ERR_R_MALLOC_FAILURE ) ; return ( NULL ) ; } ctx -> nid = nid ; ctx -> param_data = RINGLWE_PARAM_DATA_set ( nid ) ; if ( ctx -> param_data == NULL ) { RINGLWEerr ( RINGLWE_F_RLWE_CTX_NEW , RINGLWE_R_PARAM_UNKNOWN ) ; goto err ; } memcpy ( ctx -> descriptor , ( const unsigned char * ) " " , 4 ) ; ctx -> descriptor [ 4 ] = ( ctx -> param_data -> m >> 24 ) & 0xff ; ctx -> descriptor [ 5 ] = ( ctx -> param_data -> m >> 16 ) & 0xff ; ctx -> descriptor [ 6 ] = ( ctx -> param_data -> m >> 8 ) & 0xff ; ctx -> descriptor [ 7 ] = ( ctx -> param_data -> m ) & 0xff ; ctx -> descriptor [ 8 ] = ( ctx -> param_data -> q >> 24 ) & 0xff ; ctx -> descriptor [ 9 ] = ( ctx -> param_data -> q >> 16 ) & 0xff ; ctx -> descriptor [ 10 ] = ( ctx -> param_data -> q >> 8 ) & 0xff ; ctx -> descriptor [ 11 ] = ( ctx -> param_data -> q ) & 0xff ; #ifndef OPENSSL_NO_SHA unsigned char sha_outbuf [ SHA_DIGEST_LENGTH ] ; SHA1 ( ( void * ) ctx -> param_data -> a , ctx -> param_data -> m * sizeof ( RINGELT ) , sha_outbuf ) ; memcpy ( ctx -> descriptor + 12 , sha_outbuf , _RLWE_DESCRIPTOR_LEN - 12 ) ; #else memset ( ctx -> descriptor + 12 , 0 , 20 ) ; #endif return ( ctx ) ; err : OPENSSL_free ( ctx ) ; return ( NULL ) ; }
Allocate auxiliary variables (context) data structure
Allocate auxiliary variables ( context ) data structure
/* Make 32-byte descriptor for parameter set
     0-3:   "RLWE"
     4-7:   m
     8-11:  q
     12-31: truncated hash of a */