crypto/ringlwe/ringlwe_key.c
/* Convert reconciliation data structure into binary */
Convert reconciliation data structure into binary
Convert reconciliation data structure into binary
size_t i2o_RLWE_REC(RLWE_REC *rec, unsigned char **out) {
  size_t buf_len = 0;
  int new_buffer = 0, i;
  if (rec == NULL) {
    RINGLWEerr(RINGLWE_F_I2O_RLWE_REC, ERR_R_PASSED_NULL_PARAMETER);
    return 0;
  }
  uint32_t muwords = rec->muwords;
  buf_len = 4 + muwords * 8;
  if (out == NULL || buf_len == 0)
    return buf_len;
  if (*out == NULL) {
    if ((*out = OPENSSL_malloc(buf_len)) == NULL) {
      RINGLWEerr(RINGLWE_F_I2O_RLWE_REC, ERR_R_MALLOC_FAILURE);
      return 0;
    }
    new_buffer = 1;
  }
  (*out)[0] = (muwords >> 24) & 0xff;
  (*out)[1] = (muwords >> 16) & 0xff;
  (*out)[2] = (muwords >> 8) & 0xff;
  (*out)[3] = (muwords) & 0xff;
  for (i = 0; i < muwords; i++) {
    int k = 0;
    for (k = 0; k < 8; k++) {
      (*out)[4 + 8*i + k] = (rec->c[i] >> (8*k)) & 0xff;
    }
  }
  if (!new_buffer)
    *out += buf_len;
  return buf_len;
}
size_t i2o_RLWE_REC ( RLWE_REC * rec , unsigned char * * out ) { size_t buf_len = 0 ; int new_buffer = 0 , i ; if ( rec == NULL ) { RINGLWEerr ( RINGLWE_F_I2O_RLWE_REC , ERR_R_PASSED_NULL_PARAMETER ) ; return 0 ; } uint32_t muwords = rec -> muwords ; buf_len = 4 + muwords * 8 ; if ( out == NULL || buf_len == 0 ) return buf_len ; if ( * out == NULL ) { if ( ( * out = OPENSSL_malloc ( buf_len ) ) == NULL ) { RINGLWEerr ( RINGLWE_F_I2O_RLWE_REC , ERR_R_MALLOC_FAILURE ) ; return 0 ; } new_buffer = 1 ; } ( * out ) [ 0 ] = ( muwords >> 24 ) & 0xff ; ( * out ) [ 1 ] = ( muwords >> 16 ) & 0xff ; ( * out ) [ 2 ] = ( muwords >> 8 ) & 0xff ; ( * out ) [ 3 ] = ( muwords ) & 0xff ; for ( i = 0 ; i < muwords ; i ++ ) { int k = 0 ; for ( k = 0 ; k < 8 ; k ++ ) { ( * out ) [ 4 + 8 * i + k ] = ( rec -> c [ i ] >> ( 8 * k ) ) & 0xff ; } } if ( ! new_buffer ) * out += buf_len ; return buf_len ; }
Convert reconciliation data structure into binary
Convert reconciliation data structure into binary
/* out == NULL => just return the length of the octet string */