crypto/ringlwe/ringlwe_key.c
/* Make a copy of public key / private key pair data structure */
Make a copy of public key / private key pair data structure
Make a copy of public key / private key pair data structure
RLWE_PAIR *RLWE_PAIR_dup(const RLWE_PAIR *src) {
  RLWE_PAIR *dest;
  if (src == NULL) {
    RINGLWEerr(RINGLWE_F_RLWE_PAIR_DUP, ERR_R_PASSED_NULL_PARAMETER);
    return (NULL);
  }
  dest = (RLWE_PAIR *)OPENSSL_malloc(sizeof(RLWE_PAIR));
  if (dest == NULL) {
    RINGLWEerr(RINGLWE_F_RLWE_PAIR_DUP, ERR_R_MALLOC_FAILURE);
    return (NULL);
  }
  dest->param_data = src->param_data;
  memcpy(dest->descriptor, src->descriptor, _RLWE_DESCRIPTOR_LEN);
  dest->pub = (RLWE_PUB *)RLWE_PUB_dup(src->pub);
  if (dest->pub == NULL) {
    RLWE_PAIR_free(dest);
    return (NULL);
  }
  if (src->s && src->param_data) {
    dest->s = (RINGELT *) OPENSSL_malloc(2 * dest->param_data->m * sizeof (RINGELT));
    if (dest->s == NULL) {
      RINGLWEerr(RINGLWE_F_RLWE_PAIR_DUP, ERR_R_MALLOC_FAILURE);
      RLWE_PAIR_free(dest);
      return (NULL);
    }
    memcpy(dest->s, src->s, 2 * src->param_data->m * sizeof(RINGELT));
  }
  dest->keys_set = src->keys_set;
  return dest;
}
RLWE_PAIR * RLWE_PAIR_dup ( const RLWE_PAIR * src ) { RLWE_PAIR * dest ; if ( src == NULL ) { RINGLWEerr ( RINGLWE_F_RLWE_PAIR_DUP , ERR_R_PASSED_NULL_PARAMETER ) ; return ( NULL ) ; } dest = ( RLWE_PAIR * ) OPENSSL_malloc ( sizeof ( RLWE_PAIR ) ) ; if ( dest == NULL ) { RINGLWEerr ( RINGLWE_F_RLWE_PAIR_DUP , ERR_R_MALLOC_FAILURE ) ; return ( NULL ) ; } dest -> param_data = src -> param_data ; memcpy ( dest -> descriptor , src -> descriptor , _RLWE_DESCRIPTOR_LEN ) ; dest -> pub = ( RLWE_PUB * ) RLWE_PUB_dup ( src -> pub ) ; if ( dest -> pub == NULL ) { RLWE_PAIR_free ( dest ) ; return ( NULL ) ; } if ( src -> s && src -> param_data ) { dest -> s = ( RINGELT * ) OPENSSL_malloc ( 2 * dest -> param_data -> m * sizeof ( RINGELT ) ) ; if ( dest -> s == NULL ) { RINGLWEerr ( RINGLWE_F_RLWE_PAIR_DUP , ERR_R_MALLOC_FAILURE ) ; RLWE_PAIR_free ( dest ) ; return ( NULL ) ; } memcpy ( dest -> s , src -> s , 2 * src -> param_data -> m * sizeof ( RINGELT ) ) ; } dest -> keys_set = src -> keys_set ; return dest ; }
Make a copy of public key / private key pair data structure
Make a copy of public key / private key pair data structure
/* copy the parameters */ /* copy the public key */ /* copy the secret key */