bool decode(const std::string& enc, std::string& data)
    {
      if (enc.empty())
      {
        data.clear();
        return true;
      }

      size_t full_block_count = enc.size() / full_encoded_block_size;
      size_t last_block_size = enc.size() % full_encoded_block_size;
      int last_block_decoded_size = decoded_block_sizes::instance(last_block_size);
      if (last_block_decoded_size < 0)
        return false; // Invalid enc length
      size_t data_size = full_block_count * full_block_size + last_block_decoded_size;

      data.resize(data_size, 0);
      for (size_t i = 0; i < full_block_count; ++i)
      {
        if (!decode_block(enc.data() + i * full_encoded_block_size, full_encoded_block_size, &data[i * full_block_size]))
          return false;
      }

      if (0 < last_block_size)
      {
        if (!decode_block(enc.data() + full_block_count * full_encoded_block_size, last_block_size,
          &data[full_block_count * full_block_size]))
          return false;
      }

      return true;
    }
Beispiel #2
0
void AES::test(){
    BYTE src[] = {0x01, 0x02, 0x03, 0x04, 
                  0x05, 0x06, 0x07, 0x08,
                  0x09, 0x10, 0x11, 0x12,
                  0x13, 0x14, 0x15, 0x16};
    BYTE key[] = {0x05, 0x06, 0x07, 0x08,
                  0x01, 0x02, 0x03, 0x04,
                  0x09, 0x10, 0x11, 0x12,
                  0x13, 0x14, 0x15, 0x16};
    BYTE rk[11][16];
    AES::expand_key(key, rk);
    
    BYTE dst[16];
    
    sub_bytes_inv(src,dst);
    //AES::print_state(dst);

    decode_block(src, dst, rk);
    /*AES::print_state(rk[0]);
    AES::print_state(rk[1]);
    AES::print_state(rk[2]);
    AES::print_state(rk[3]);
    AES::print_state(rk[4]);
    AES::print_state(rk[5]);
    AES::print_state(rk[6]);
    AES::print_state(rk[7]);
    AES::print_state(rk[8]);
    AES::print_state(rk[9]);*/
    AES::print_state(dst);
}
Beispiel #3
0
static void decode_block(BigInt *b, char *bitmap, int w, int h, int level)
{
    switch (pop_integer(b, &ff_xface_probranges_per_level[level][0])) {
    case XFACE_COLOR_WHITE:
        return;
    case XFACE_COLOR_BLACK:
        pop_greys(b, bitmap, w, h);
        return;
    default:
        w /= 2;
        h /= 2;
        level++;
        decode_block(b, bitmap,                       w, h, level);
        decode_block(b, bitmap + w,                   w, h, level);
        decode_block(b, bitmap + h * XFACE_WIDTH,     w, h, level);
        decode_block(b, bitmap + w + h * XFACE_WIDTH, w, h, level);
        return;
    }
}
Beispiel #4
0
void AES::srtp_decode(BYTE* src, BYTE* dst, BYTE* key, BYTE* iv, int length){
    LOG_MSG("AES::srtp_decode(%s, %s, %s, %s, %d)",src,dst,key,iv,length);
    BYTE counter[BLOCK_SIZE] = {0};
    memcpy(counter, iv, BLOCK_SIZE);

    unsigned char round_key[ROUND_KEY_SIZE][BLOCK_SIZE];
    expand_key(key,round_key);
    
    int i = 0, j = 0;

    for( ; i < length; i+=BLOCK_SIZE){
        decode_block(counter, dst+i, round_key);
        xor_key(dst+i,dst+i,src+i);
        update_counter(counter);
    }

    BYTE last_block[BLOCK_SIZE];
    decode_block(counter, last_block, round_key);
    for(i=i-BLOCK_SIZE; i < length; i++, j++){
        dst[i] = last_block[j] ^ src[i];
    }
}
Beispiel #5
0
static int decode_frame(AVCodecContext *avctx, void *data,
                        int *got_frame_ptr, AVPacket *avpkt)
{
    BinkAudioContext *s = avctx->priv_data;
    AVFrame *frame      = data;
    BitstreamContext *bc = &s->bc;
    int ret, consumed = 0;

    if (!bitstream_bits_left(bc)) {
        uint8_t *buf;
        /* handle end-of-stream */
        if (!avpkt->size) {
            *got_frame_ptr = 0;
            return 0;
        }
        if (avpkt->size < 4) {
            av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
            return AVERROR_INVALIDDATA;
        }
        buf = av_realloc(s->packet_buffer, avpkt->size + AV_INPUT_BUFFER_PADDING_SIZE);
        if (!buf)
            return AVERROR(ENOMEM);
        s->packet_buffer = buf;
        memcpy(s->packet_buffer, avpkt->data, avpkt->size);
        bitstream_init(bc, s->packet_buffer, avpkt->size * 8);
        consumed = avpkt->size;

        /* skip reported size */
        bitstream_skip(bc, 32);
    }

    /* get output buffer */
    frame->nb_samples = s->frame_len;
    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
        return ret;
    }

    if (decode_block(s, (float **)frame->extended_data,
                     avctx->codec->id == AV_CODEC_ID_BINKAUDIO_DCT)) {
        av_log(avctx, AV_LOG_ERROR, "Incomplete packet\n");
        return AVERROR_INVALIDDATA;
    }
    get_bits_align32(bc);

    frame->nb_samples = s->block_size / avctx->channels;
    *got_frame_ptr    = 1;

    return consumed;
}
Beispiel #6
0
bool xmr_base58_decode(const char *b58, size_t b58sz, void *data, size_t *binsz)
{
	if (b58sz == 0) {
		*binsz = 0;
		return true;
	}

	size_t full_block_count = b58sz / full_encoded_block_size;
	size_t last_block_size = b58sz % full_encoded_block_size;
	int last_block_decoded_size = decoded_block_sizes[last_block_size];
	if (last_block_decoded_size < 0) {
		*binsz = 0;
		return false; // Invalid enc length
	}

	size_t data_size = full_block_count * full_block_size + last_block_decoded_size;
	if (*binsz < data_size){
		*binsz = 0;
		return false;
	}

	char * data_bin = data;
	for (size_t i = 0; i < full_block_count; ++i)
	{
		if (!decode_block(b58 + i * full_encoded_block_size, full_encoded_block_size, data_bin + i * full_block_size))
			return false;
	}

	if (0 < last_block_size)
	{
		if (!decode_block(b58 + full_block_count * full_encoded_block_size, last_block_size,
											data_bin + full_block_count * full_block_size))
			return false;
	}

	return true;
}
Beispiel #7
0
void IMA4Decoder::decode(const void *buffer, t_size bytes, audio_chunk &chunk,
                         abort_callback &abort)
{
    unsigned nchannels = m_channel_state.size();
    unsigned nblocks   = bytes / nchannels / 34;
    auto bp = static_cast<const uint8_t*>(buffer);
    unsigned nsamples  = nblocks * nchannels * 64;

    m_sample_buffer.resize(nsamples);
    for (unsigned i = 0; i < nblocks; ++i) {
        for (unsigned ch = 0; ch < nchannels; ++ch) {
            decode_block(&m_channel_state[ch], &bp[(i * nchannels + ch) * 34],
                         &m_sample_buffer[i * nchannels * 64 + ch], nchannels);
        }
    }
    m_lpcm_decoder->decode(m_sample_buffer.data(), nsamples * 2, chunk, abort);
}
Beispiel #8
0
int xcs(FILE * src, FILE * dst, unsigned int len)
{
	unsigned char data[BLOCKSIZ];

	if (len % BLOCKSIZ)
		return -1;

	int blocks = len / BLOCKSIZ;

	for (int i = 0; i < blocks; i++) {
		if (fread(data, BLOCKSIZ, 1, src) != 1)
			return -1;

		decode_block(data, dst);
	}

	return 0;
}
Beispiel #9
0
static void decode(struct ptxed_decoder *decoder,
		   struct pt_image_section_cache *iscache,
		   const struct ptxed_options *options,
		   struct ptxed_stats *stats)
{
	if (!decoder) {
		printf("[internal error]\n");
		return;
	}

	switch (decoder->type) {
	case pdt_insn_decoder:
		decode_insn(decoder->variant.insn, options, stats);
		break;

	case pdt_block_decoder:
		decode_block(decoder->variant.block, iscache, options, stats);
		break;
	}
}
static void decode_block_intra(int plane, int block, BLOCK_SIZE_TYPE bsize,
                               int ss_txfrm_size, void *arg) {
  MACROBLOCKD* const xd = arg;
  struct macroblockd_plane *pd = &xd->plane[plane];

  const int raster_block = txfrm_block_to_raster_block(xd, bsize, plane,
                                                       block, ss_txfrm_size);
  uint8_t* const dst = raster_block_offset_uint8(xd, bsize, plane,
                                                 raster_block,
                                                 pd->dst.buf, pd->dst.stride);
  const TX_SIZE tx_size = (TX_SIZE)(ss_txfrm_size / 2);
  int b_mode;
  int plane_b_size;
  const int tx_ib = raster_block >> tx_size;
  const int mode = plane == 0 ? xd->mode_info_context->mbmi.mode
                              : xd->mode_info_context->mbmi.uv_mode;


  if (plane == 0 && xd->mode_info_context->mbmi.sb_type < BLOCK_SIZE_SB8X8) {
    assert(bsize == BLOCK_SIZE_SB8X8);
    b_mode = xd->mode_info_context->bmi[raster_block].as_mode.first;
  } else {
    b_mode = mode;
  }

  if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0)
    extend_for_intra(xd, plane, block, bsize, ss_txfrm_size);

  plane_b_size = b_width_log2(bsize) - pd->subsampling_x;
  vp9_predict_intra_block(xd, tx_ib, plane_b_size, tx_size, b_mode,
                          dst, pd->dst.stride);

  // Early exit if there are no coefficients
  if (xd->mode_info_context->mbmi.mb_skip_coeff)
    return;

  decode_block(plane, block, bsize, ss_txfrm_size, arg);
}
Beispiel #11
0
/*
 * decode_stdin: Decode from stdin (base64) to stdout (binary). Returns 0 for
 * success, and 1 if input (excluding CRs/LFs) was not a multiple of 4 bytes.
 */
int decode_stdin() {
    int err_code = 0;
    bool done = false;
    int octets;
    int i;

    while (! done)
        switch (get_base64_block()) {
        case 1:  /* got a full block */
            octets = decode_block();
            for (i = 0; i < octets; ++i)
                putchar(binary_block[i]);
            break;
        case 0:  /* got no block */
            done = true;
            break;
        default: /* input was not a multiple of 4 bytes */
            err_code = 1;
            break;
        }

    return err_code;
}
Beispiel #12
0
int
validate (const char *dst, const void *src, int srclen)
{
    int n;
    char buf[9];

    if (encode_block (buf, &n, src, srclen) < 0)
        return (-1);
    if (n != strlen (dst))
        return (-1);
    if (strncmp (dst, buf, n))
        return (-1);

    if (decode_block (buf, &n, dst, strlen (dst)) < 0)
        return (-1);
    if (n != srclen)
        return (-1);
    if (strncmp (src, buf, n))
        return (-1);

    if (encode_context (buf, &n, src, srclen) < 0)
        return (-1);
    if (n != strlen (dst))
        return (-1);
    if (strncmp (dst, buf, n))
        return (-1);

    if (decode_context (buf, &n, dst, strlen (dst)) < 0)
        return (-1);
    if (n != srclen)
        return (-1);
    if (strncmp (src, buf, n))
        return (-1);

    return (0);
}
Beispiel #13
0
int
validate (const unsigned char *src, const unsigned char *dst)
{
    int n;
    unsigned char buf[9];

    if (encode_block (buf, &n, src, strlen (src)) < 0)
        return (-1);
    if (n != strlen (dst))
        return (-1);
    if (strncmp (dst, buf, n))
        return (-1);

    if (decode_block (buf, &n, dst, strlen (dst)) < 0)
        return (-1);
    if (n != strlen (src))
        return (-1);
    if (strncmp (src, buf, n))
        return (-1);

    if (encode_context (buf, &n, src, strlen (src)) < 0)
        return (-1);
    if (n != strlen (dst))
        return (-1);
    if (strncmp (dst, buf, n))
        return (-1);

    if (decode_context (buf, &n, dst, strlen (dst)) < 0)
        return (-1);
    if (n != strlen (src))
        return (-1);
    if (strncmp (src, buf, n))
        return (-1);

    return (0);
}
Beispiel #14
0
int
read_priv_key (FILE * privring, PRIVATE_KEY * privkey,
	       unsigned char *newID)
{
  unsigned char line[1024];
  int i, err, len, length;
  unsigned char iv[20];
  unsigned char *temp, *temp2;
  byte digest[16], *byteptr;
  byte des3key[24];
  BUFFER *buff;
#ifdef USE_RSAREF
  R_DIGEST_CTX digest_context;
  DES3_CBC_CTX context;
#else
  B_ALGORITHM_OBJ digest_obj;
  B_ALGORITHM_OBJ des_obj;
  B_KEY_OBJ key_obj;
  A_PKCS_RSA_PRIVATE_KEY keyinfo;
#endif

  buff = new_buffer ();
  /* read in the length */
  if ((temp = getline (line, sizeof (line), privring)) == NULL)
    return -1;
  sscanf (line, "%d", &length);

  /* Read in iv */
  if (((temp = getline (line, sizeof (line), privring)) == NULL)
      || (decode_block (iv, &len, line, strlen (line))))
    return -1;

  if ((temp = getline (line, sizeof (line), privring)) == NULL)
    return -1;
  while (temp != NULL && !streq (line, end_key))
    {
      add_to_buffer (buff, line, strlen (line));
      temp = getline (line, sizeof (line), privring);
    }
  temp = malloc (buff->length);
  temp2 = malloc (buff->length);
  if (decode_block (temp, &len, buff->message, buff->length) != 0)
    return -1;

  if (len < length)
    {
      fprintf (errlog, "Error: recovered key is too small!\n");
      return (-2);
    }
  /* decrypt key */
#ifdef USE_RSAREF
  R_DigestInit (&digest_context, DA_MD5);
  R_DigestUpdate (&digest_context, PASSPHRASE, strlen (PASSPHRASE));
  R_DigestFinal (&digest_context, digest, &i);
  memcpy (des3key, digest, 16);	/* set first 2 keys */
  memcpy (des3key + 16, digest, 8);	/* third key = first key */
  DES3_CBCInit (&context, des3key, iv, 0);
  while (len % 8 != 0)
    len++;			/* align on block boundry */
  err = DES3_CBCUpdate (&context, temp2, temp, len);
#else
  B_CreateAlgorithmObject (&digest_obj);
  B_SetAlgorithmInfo (digest_obj, AI_MD5, NULL);

  B_DigestInit (digest_obj, NULL, CHOOSER, NULL);
  B_DigestUpdate (digest_obj, PASSPHRASE, strlen (PASSPHRASE), NULL);
  B_DigestFinal (digest_obj, digest, &i, 16, NULL);
  B_DestroyAlgorithmObject (&digest_obj);

  memcpy (des3key, digest, 16);	/* set first 2 keys */
  memcpy (des3key + 16, digest, 8);	/* third key = first key */
  B_CreateAlgorithmObject (&des_obj);
  B_SetAlgorithmInfo (des_obj, AI_DES_EDE3_CBC_IV8, iv);
  B_CreateKeyObject (&key_obj);
  err = B_SetKeyInfo (key_obj, KI_DES24Strong, des3key);
  B_DecryptInit (des_obj, key_obj, CHOOSER, NULL);
  err = B_DecryptUpdate (des_obj, temp2, &i, len, temp, len, random_obj,
			 NULL);
  B_DecryptFinal (des_obj, temp2 + i, &i, len - i, random_obj, NULL);
  B_DestroyKeyObject (&key_obj);
  B_DestroyAlgorithmObject (&des_obj);
#endif

  if (err)
    {
      printf ("Error: Problem decrypting key %x\n", err);
      return (-1);
    }
  memset ((void *) digest, 0, 16);	/* zero password */
  free (temp);

  /* Rebuild privkey */
  byteptr = temp2;
  i = *byteptr++;
  i += (*byteptr++ * 256);

#ifdef USE_RSAREF
  (*privkey).bits = i;

  for (i = 0; i < MAX_RSA_MODULUS_LEN; i++)
    (*privkey).modulus[i] = *byteptr++;
  for (i = 0; i < MAX_RSA_MODULUS_LEN; i++)
    (*privkey).publicExponent[i] = *byteptr++;
  for (i = 0; i < MAX_RSA_MODULUS_LEN; i++)
    (*privkey).exponent[i] = *byteptr++;
  for (i = 0; i < MAX_RSA_PRIME_LEN; i++)
    (*privkey).prime[0][i] = *byteptr++;
  for (i = 0; i < MAX_RSA_PRIME_LEN; i++)
    (*privkey).prime[1][i] = *byteptr++;
  for (i = 0; i < MAX_RSA_PRIME_LEN; i++)
    (*privkey).primeExponent[0][i] = *byteptr++;
  for (i = 0; i < MAX_RSA_PRIME_LEN; i++)
    (*privkey).primeExponent[1][i] = *byteptr++;
  for (i = 0; i < MAX_RSA_PRIME_LEN; i++)
    (*privkey).coefficient[i] = *byteptr++;
  free (temp2);

  /* Make Key ID */
  R_DigestInit (&digest_context, DA_MD5);
  R_DigestUpdate (&digest_context, privkey->modulus, MAX_RSA_MODULUS_LEN);
  R_DigestUpdate (&digest_context, privkey->publicExponent, MAX_RSA_MODULUS_LEN);
  R_DigestFinal (&digest_context, newID, &i);
#else
  i = (i + 7) / 8;
  if (i < MAX_RSA_MODULUS_LEN)
    i = MAX_RSA_MODULUS_LEN;

  keyinfo.modulus.len = i;
  keyinfo.publicExponent.len = i;
  keyinfo.privateExponent.len = i;
  keyinfo.prime[0].len = (i + 1) / 2;
  keyinfo.prime[1].len = (i + 1) / 2;
  keyinfo.primeExponent[0].len = (i + 1) / 2;
  keyinfo.primeExponent[1].len = (i + 1) / 2;
  keyinfo.coefficient.len = (i + 1) / 2;

  keyinfo.modulus.data = malloc (keyinfo.modulus.len);
  memcpy (keyinfo.modulus.data, byteptr, keyinfo.modulus.len);
  byteptr += keyinfo.modulus.len;

  keyinfo.publicExponent.data = malloc (keyinfo.publicExponent.len);
  memcpy (keyinfo.publicExponent.data, byteptr, keyinfo.publicExponent.len);
  byteptr += keyinfo.publicExponent.len;

  keyinfo.privateExponent.data = malloc (keyinfo.privateExponent.len);
  memcpy (keyinfo.privateExponent.data, byteptr, keyinfo.privateExponent.len);
  byteptr += keyinfo.privateExponent.len;

  keyinfo.prime[0].data = malloc (keyinfo.prime[0].len);
  memcpy (keyinfo.prime[0].data, byteptr, keyinfo.prime[0].len);
  byteptr += keyinfo.prime[0].len;

  keyinfo.prime[1].data = malloc (keyinfo.prime[1].len);
  memcpy (keyinfo.prime[1].data, byteptr, keyinfo.prime[1].len);
  byteptr += keyinfo.prime[1].len;

  keyinfo.primeExponent[0].data = malloc (keyinfo.primeExponent[0].len);
  memcpy (keyinfo.primeExponent[0].data, byteptr,
	  keyinfo.primeExponent[0].len);
  byteptr += keyinfo.primeExponent[0].len;

  keyinfo.primeExponent[1].data = malloc (keyinfo.primeExponent[1].len);
  memcpy (keyinfo.primeExponent[1].data, byteptr,
	  keyinfo.primeExponent[1].len);
  byteptr += keyinfo.primeExponent[1].len;

  keyinfo.coefficient.data = malloc (keyinfo.coefficient.len);
  memcpy (keyinfo.coefficient.data, byteptr, keyinfo.coefficient.len);

  B_CreateKeyObject (privkey);
  B_SetKeyInfo (*privkey, KI_PKCS_RSAPrivate, (POINTER) & keyinfo);

  /* Make Key ID */
  B_CreateAlgorithmObject (&digest_obj);
  B_SetAlgorithmInfo (digest_obj, AI_MD5, NULL);

  B_DigestInit (digest_obj, NULL, CHOOSER, NULL);
  B_DigestUpdate (digest_obj, keyinfo.modulus.data, keyinfo.modulus.len, NULL);
  B_DigestUpdate (digest_obj, keyinfo.publicExponent.data,
		  keyinfo.publicExponent.len, NULL);
  B_DigestFinal (digest_obj, newID, &i, 16, NULL);
  B_DestroyAlgorithmObject (&digest_obj);
  free (keyinfo.modulus.data);
  free (keyinfo.publicExponent.data);
  free (keyinfo.privateExponent.data);
  free (keyinfo.prime[0].data);
  free (keyinfo.prime[1].data);
  free (keyinfo.primeExponent[0].data);
  free (keyinfo.primeExponent[1].data);
  free (keyinfo.coefficient.data);
  free (temp2);
#endif
  return 0;
}
Beispiel #15
0
int
get_DH (DH_PARAMS * DH_parms)
{
#ifdef USE_RSAREF
  unsigned char line[1024], IDstr[80], line2[1024];
  unsigned char ID[16];
  unsigned int i, len, length, found = 0;
  unsigned char *temp;
  FILE *dhfile;
  FILE *dhlock;
  R_DIGEST_CTX digest_context;
  byte *byteptr;
  BUFFER *buff;

  mix_lock ("DH", &dhlock);
  if ((dhfile = open_mix_file ("DH.mix", "r")) == NULL)
    {
      mix_unlock ("DH", dhlock);
      return (-1);
    }
  while (!found)
    {
      getline (line, sizeof (line), dhfile);
      while (!streq (line, begin_key))
	{
	  if (getline (line, sizeof (line), dhfile) == NULL)
	    {
	      fprintf (errlog, "End of file DH.mix\n");
	      fclose (dhfile);
	      mix_unlock ("DH", dhlock);
	      return (-1);
	    }
	}
      getline (line2, sizeof (line2), dhfile);
      buff = new_buffer ();
      /* read in the length */
      if ((temp = getline (line, 1024, dhfile)) == NULL)
	break;
      sscanf (line, "%d", &length);

      if ((temp = getline (line, sizeof (line), dhfile)) == NULL)
	break;
      while (temp != NULL && !streq (line, end_key))
	{
	  add_to_buffer (buff, line, strlen (line));
	  temp = getline (line, sizeof (line), dhfile);
	}
      temp = malloc (buff->length);	/* Longer than we need */
      if (decode_block (temp, &len, buff->message, buff->length) != 0)
	{
	  fprintf (errlog, "Bad DH.mix format!\n");
	  return (-1);
	}
      free_buffer (buff);
      if (len < length)
	{
	  fprintf (errlog, "Error: recovered DH parameters file is too small!\n");
	  fclose (dhfile);
	  mix_unlock ("DH", dhlock);
	  return (-2);
	}
      /* Rebuild the DH_parms struct */
      byteptr = temp;
      (*DH_parms).primeLen = *byteptr++;
      if ((*DH_parms).primeLen > length)
	{
	  fprintf (errlog, "Error: DH.mix is inconsistent!\n");
	  fclose (dhfile);
	  mix_unlock ("DH", dhlock);
	  return (-2);
	}
      (*DH_parms).prime = malloc ((*DH_parms).primeLen);
      for (i = 0; i < (*DH_parms).primeLen; i++)
	(*DH_parms).prime[i] = *byteptr++;
      (*DH_parms).generatorLen = *byteptr++;
      if ((*DH_parms).primeLen + (*DH_parms).generatorLen > length)
	{
	  fprintf (errlog, "Error: DH.mix is inconsistent!\n");
	  fclose (dhfile);
	  mix_unlock ("DH", dhlock);
	  return (-2);
	}
      (*DH_parms).generator = malloc ((*DH_parms).generatorLen);
      for (i = 0; i < (*DH_parms).generatorLen; i++)
	(*DH_parms).generator[i] = *byteptr++;
      free (temp);

      /* Make Key ID */
      R_DigestInit (&digest_context, DA_MD5);
      R_DigestUpdate (&digest_context, (*DH_parms).prime,
		      (*DH_parms).primeLen);
      R_DigestUpdate (&digest_context, (*DH_parms).generator,
		      (*DH_parms).generatorLen);
      R_DigestFinal (&digest_context, ID, &i);

      encode_ID (IDstr, ID);

      /* compare new ID with saved ID */
      if (memcmp (IDstr, line2, 32) != 0)
	{
	  fprintf (errlog, "Error: DH Parameter IDs do not match!\n");
	  fclose (dhfile);
	  mix_unlock ("DH", dhlock);
	  return (-3);
	}
      found = 1;		/* this will end the loop */
    }
  fclose (dhfile);
  mix_unlock ("DH", dhlock);
  if (found)
    return (0);
  return (1);
#else
  /* not implemented */
  return (1);
#endif
}
Beispiel #16
0
int
read_pub_key (FILE * pubring, PUBLIC_KEY * pubkey,
	      unsigned char *newID)
{
  unsigned char line[1024];
  int i, len, length;
  unsigned char *temp;
  byte *byteptr;
  BUFFER *buff;
#ifdef USE_RSAREF
  R_DIGEST_CTX digest_context;
#else
  B_ALGORITHM_OBJ digest_obj;
  A_RSA_KEY keyinfo;
#endif

  buff = new_buffer ();
  /* read in the length */
  if ((temp = getline (line, sizeof (line), pubring)) == NULL)
    return -1;
  sscanf (line, "%d", &length);

  if ((temp = getline (line, sizeof (line), pubring)) == NULL)
    return -1;
  while (temp != NULL && !streq (line, end_key))
    {
      add_to_buffer (buff, line, strlen (line));
      temp = getline (line, sizeof (line), pubring);
    }
  temp = malloc (buff->length);	/* Longer than we need */
  if (decode_block (temp, &len, buff->message, buff->length) != 0)
    {
      fprintf (errlog, "Error: Malformatted key!\n");
      return (-2);
    }
  free_buffer (buff);
  if (len < length)
    {
      fprintf (errlog, "Error: recovered key is too small!\n");
      return (-2);
    }
  byteptr = temp;
  i = *byteptr++;
  i += (*byteptr++ * 256);
#ifdef USE_RSAREF
  if ((i + 7) / 8 > MAX_RSA_MODULUS_LEN)
    {
      fprintf (errlog, "Keysize not supported by RSAREF.\n");
      return (-1);
    }
  (*pubkey).bits = i;
  for (i = 0; i < MAX_RSA_MODULUS_LEN; i++)
    (*pubkey).modulus[i] = *byteptr++;
  for (i = 0; i < MAX_RSA_MODULUS_LEN; i++)
    (*pubkey).exponent[i] = *byteptr++;
#else
  keyinfo.modulus.len = (i + 7) / 8;
  if (keyinfo.modulus.len < MAX_RSA_MODULUS_LEN)
    keyinfo.modulus.len = MAX_RSA_MODULUS_LEN;
  keyinfo.exponent.len = keyinfo.modulus.len;

  keyinfo.modulus.data = malloc (keyinfo.modulus.len);
  memcpy (keyinfo.modulus.data, byteptr, keyinfo.modulus.len);
  byteptr += keyinfo.modulus.len;

  keyinfo.exponent.data = malloc (keyinfo.exponent.len);
  memcpy (keyinfo.exponent.data, byteptr, keyinfo.exponent.len);

  B_CreateKeyObject (pubkey);
  B_SetKeyInfo (*pubkey, KI_RSAPublic, (POINTER) & keyinfo);
#endif
  free (temp);

  /* Make Key ID */
#ifdef USE_RSAREF
  R_DigestInit (&digest_context, DA_MD5);
  R_DigestUpdate (&digest_context, (*pubkey).modulus,
		  MAX_RSA_MODULUS_LEN);
  R_DigestUpdate (&digest_context, (*pubkey).exponent,
		  MAX_RSA_MODULUS_LEN);
  R_DigestFinal (&digest_context, newID, &i);
#else
  B_CreateAlgorithmObject (&digest_obj);
  B_SetAlgorithmInfo (digest_obj, AI_MD5, NULL);

  B_DigestInit (digest_obj, NULL, CHOOSER, NULL);
  B_DigestUpdate (digest_obj, keyinfo.modulus.data, keyinfo.modulus.len, NULL);
  B_DigestUpdate (digest_obj, keyinfo.exponent.data, keyinfo.exponent.len,
		  NULL);
  B_DigestFinal (digest_obj, newID, &i, 16, NULL);
  B_DestroyAlgorithmObject (&digest_obj);
  free (keyinfo.modulus.data);
  free (keyinfo.exponent.data);
#endif
  return 0;
}
Beispiel #17
0
static int xface_decode_frame(AVCodecContext *avctx,
                              void *data, int *got_frame,
                              AVPacket *avpkt)
{
    XFaceContext *xface = avctx->priv_data;
    int ret, i, j, k;
    uint8_t byte;
    BigInt b = {0};
    char *buf;
    int64_t c;
    AVFrame *frame = data;

    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
        return ret;

    for (i = 0, k = 0; avpkt->data[i] && i < avpkt->size; i++) {
        c = avpkt->data[i];

        /* ignore invalid digits */
        if (c < XFACE_FIRST_PRINT || c > XFACE_LAST_PRINT)
            continue;

        if (++k > XFACE_MAX_DIGITS) {
            av_log(avctx, AV_LOG_WARNING,
                   "Buffer is longer than expected, truncating at byte %d\n", i);
            break;
        }
        ff_big_mul(&b, XFACE_PRINTS);
        ff_big_add(&b, c - XFACE_FIRST_PRINT);
    }

    /* decode image and put it in bitmap */
    memset(xface->bitmap, 0, XFACE_PIXELS);
    buf = xface->bitmap;
    decode_block(&b, buf,                         16, 16, 0);
    decode_block(&b, buf + 16,                    16, 16, 0);
    decode_block(&b, buf + 32,                    16, 16, 0);
    decode_block(&b, buf + XFACE_WIDTH * 16,      16, 16, 0);
    decode_block(&b, buf + XFACE_WIDTH * 16 + 16, 16, 16, 0);
    decode_block(&b, buf + XFACE_WIDTH * 16 + 32, 16, 16, 0);
    decode_block(&b, buf + XFACE_WIDTH * 32     , 16, 16, 0);
    decode_block(&b, buf + XFACE_WIDTH * 32 + 16, 16, 16, 0);
    decode_block(&b, buf + XFACE_WIDTH * 32 + 32, 16, 16, 0);

    ff_xface_generate_face(xface->bitmap, xface->bitmap);

    /* convert image from 1=black 0=white bitmap to MONOWHITE */
    buf = frame->data[0];
    for (i = 0, j = 0, k = 0, byte = 0; i < XFACE_PIXELS; i++) {
        byte += xface->bitmap[i];
        if (k == 7) {
            buf[j++] = byte;
            byte = k = 0;
        } else {
            k++;
            byte <<= 1;
        }
        if (j == XFACE_WIDTH/8) {
            j = 0;
            buf += frame->linesize[0];
        }
    }

    *got_frame = 1;

    return avpkt->size;
}
Beispiel #18
0
void
decode_start(int* out_data_image_width, int* out_data_image_height, int* out_data_comp_vpos, int* out_data_comp_hpos)
{
    int i;
    int CurrentMCU = 0;
    int HuffBuff[NUM_COMPONENT][DCTSIZE2];
    int IDCTBuff[6][DCTSIZE2];
    
    /* Read buffer */
    CurHuffReadBuf = p_jinfo_jpeg_data; 
    
    /*
     * Initial value of DC element is 0
     */
    for(i = 0; i < NUM_COMPONENT; i++){
        HuffBuff[i][0] = 0;
    }
    
    /*
     * Set the size of image to output buffer
     */
    *out_data_image_width = p_jinfo_image_width;
    *out_data_image_height = p_jinfo_image_height;

    /*
     * Initialize output buffer
     */
    for(i = 0; i < RGB_NUM; i++){
        out_data_comp_vpos[i] =  0;
        out_data_comp_hpos[i] =  0;
    }
    
    
    if(p_jinfo_smp_fact == SF1_1_1){
        // printf("Decode 1:1:1 NumMCU = %d\n",p_jinfo_NumMCU);
        
        /*
         * 1_1_1
         */
        while(CurrentMCU < p_jinfo_NumMCU){
            
            for(i = 0; i < NUM_COMPONENT; i++){
                decode_block(i, IDCTBuff[i], HuffBuff[i]);
            }

            
            YuvToRgb(0,IDCTBuff[0],IDCTBuff[1],IDCTBuff[2]);
            /*
             * Write
             */
            for(i = 0; i < RGB_NUM; i++){
                WriteBlock(&rgb_buf[0][i][0],
                           &out_data_comp_vpos[i],
                           &out_data_comp_hpos[i],
                           &OutData_comp_buf[i][0]);
            }
            CurrentMCU++;
        }
        
    }else{
        // printf("Decode 4:1:1 NumMCU = %d\n",p_jinfo_NumMCU);
        /*
         * 4_1_1
         */
        while(CurrentMCU < p_jinfo_NumMCU){
            /*
             * Decode Y element
	         * Decoding Y, U and V elements should be sequentially conducted for the use of Huffman table
             */

            for(i = 0; i < 4; i++){
                decode_block(0, IDCTBuff[i], HuffBuff[0]);
            }
            
            /* Decode U */
            decode_block(1, IDCTBuff[4], HuffBuff[1]);
            
            /* Decode V */
            decode_block(2, IDCTBuff[5], HuffBuff[2]);

            
            /* Transform from Yuv into RGB */

            for(i = 0; i < 4; i++){
                YuvToRgb(i,IDCTBuff[i],IDCTBuff[4],IDCTBuff[5]);
            }


            for(i = 0; i < RGB_NUM; i++){
                Write4Blocks(&rgb_buf[0][i][0],
                            &rgb_buf[1][i][0],
                            &rgb_buf[2][i][0],
                            &rgb_buf[3][i][0],
                            &out_data_comp_vpos[i],
                            &out_data_comp_hpos[i],
                            &OutData_comp_buf[i][0]);
            }
            
            
            CurrentMCU += 4;
        }
    }
}
Beispiel #19
0
int
decode_start (int x[4000],int m, int y[4000],int n)
{

  data_in(x,m);
  //data1();
  int i;
  int CurrentMCU = 0;
  int HuffBuff[NUM_COMPONENT][DCTSIZE2];
  int IDCTBuff[6][DCTSIZE2];

  /* Read buffer */
  CurHuffReadBuf = p_jinfo_jpeg_data_;

  /*
   * Initial value of DC element is 0
   */
  for (i = 0; i < NUM_COMPONENT; i++)
    {
      HuffBuff[i][0] = 0;
    }

  /*
   * Set the size of image to output buffer
   */
  OutData_image_width_ = p_jinfo_image_width_;
  OutData_image_height_ = p_jinfo_image_height_;

  /*
   * Initialize output buffer
   */
  for (i = 0; i < RGB_NUM; i++)
    {
	  OutData_comp_vpos_[i] = 0;
	  OutData_comp_hpos_[i] = 0;
    }


  if (p_jinfo_smp_fact_ == SF1_1_1)
    {
      printf ("Decode 1:1:1 NumMCU = %d\n", p_jinfo_NumMCU_);

      /*
       * 1_1_1
       */
      while (CurrentMCU < p_jinfo_NumMCU_)
	{

	  for (i = 0; i < NUM_COMPONENT; i++)
	    {
	      decode_block (i, IDCTBuff[i], HuffBuff[i]);
	    }


	  YuvToRgb (0, IDCTBuff[0], IDCTBuff[1], IDCTBuff[2]);
	  /*
	   * Write
	   */
	  for (i = 0; i < RGB_NUM; i++)
	    {
	      WriteBlock (&rgb_buf[0][i][0],
			  &OutData_comp_vpos_[i],
			  &OutData_comp_hpos_[i], &OutData_comp_buf_[i][0]);
	    }
	  CurrentMCU++;
	}

    }
  else
    {
      printf ("Decode 4:1:1 NumMCU = %d\n", p_jinfo_NumMCU_);
      /*
       * 4_1_1
       */
      while (CurrentMCU < p_jinfo_NumMCU_)
	{
	  /*
	   * Decode Y element
	   * Decoding Y, U and V elements should be sequentially conducted for the use of Huffman table
	   */

	  for (i = 0; i < 4; i++)
	    {
	      decode_block (0, IDCTBuff[i], HuffBuff[0]);
	    }

	  /* Decode U */
	  decode_block (1, IDCTBuff[4], HuffBuff[1]);

	  /* Decode V */
	  decode_block (2, IDCTBuff[5], HuffBuff[2]);


	  /* Transform from Yuv into RGB */

	  for (i = 0; i < 4; i++)
	    {
	      YuvToRgb (i, IDCTBuff[i], IDCTBuff[4], IDCTBuff[5]);
	    }


	  for (i = 0; i < RGB_NUM; i++)
	    {
	      Write4Blocks (&rgb_buf[0][i][0],
			    &rgb_buf[1][i][0],
			    &rgb_buf[2][i][0],
			    &rgb_buf[3][i][0],
			    &OutData_comp_vpos_[i],
			    &OutData_comp_hpos_[i], &OutData_comp_buf_[i][0]);
	    }


	  CurrentMCU += 4;
	}
    }

    //data2();
    data_out(x,n);
    return m+n+*y;
}
Beispiel #20
0
void main (int argc, char *argv[])
 {
   cout << "Squirrel 1.16/release, Adaptive answer Service for USR Voice modems" << endl;
   cout << "Copyright (c)2000 Eugeniy Gryaznov, Compiled on 02.05.00 at 21:09" << endl;
   if(argc<2) {
      cout << " Use <squirrel.exe> <action> [<action param>] [switches]" << endl;
      cout << "  action:   PLAY,REC,MAILER,MAIN" << endl;
      cout << "      PLAY f.gsm     Play file to speaker(modem)" << endl;
      cout << "      REC f.gsm      Record from microphone(modem) to file" << endl;
      cout << "      MAILER         Mailer compatible mode" << endl;
      cout << "      MAIN           Run in master mode" << endl;
      cout << "      CONV f.gsm     Convert GSM ->WAV" << endl;
      cout << "  switches: [/L] [/D] [/P]" << endl;
      cout << "      /L             switch Playing/Recording device" << endl;
      cout << "      /D             switch Show debug info" << endl;
      cout << "      /P             switch close/real_close port" << endl;
      cout << "      /B             switch 8/16 bit wave output" << endl;
      cout << " Ex: squirrel play allo.gsm /L /D" << endl;
      cout << "     squirrel main" << endl;
      ErrorExit(0,"Help screen");
   }

   // Get default CTL name
   char ctl[128];
   char *ext = "CTL";
   strcpy(ctl,argv[0]);
   strcpy(ctl+strlen(ctl)-3,ext);
   SetDefault();

   // Check ARGV
   int Task = 0, swch = 0; // 1 - PLAY, 2 - REC, 3 - MAILER, 4 - MAIN
   char TParam[128],fname[128],*outw;
   int postdo = 0;

   // Get task type
   if (strcmp(strupr(argv[1]),"PLAY")==0) { strcpy(TParam,argv[2]);Task=1; }
   else if (strcmp(strupr(argv[1]),"REC")==0) { strcpy(TParam,argv[2]);Task=2; }
   else if (strcmp(strupr(argv[1]),"MAILER")==0) { strcpy(TParam,argv[2]);Task=3; }
   else if (strcmp(strupr(argv[1]),"MAIN")==0) { strcpy(TParam,argv[2]);Task=4; }
   else if (strcmp(strupr(argv[1]),"CONV")==0) { strcpy(TParam,argv[2]);Task=5; }
   else ErrorExit(1,"Unknown action");
   if ((Task==1||Task==2||Task==5)&&argc==2) ErrorExit(1,"not enough params");

   // Process switches
   for (int argnum=2;argnum<argc;argnum++){
      if ((Task!=1&&Task!=2&&Task!=5)||argnum!=2){
        if (strcmp(strupr(argv[argnum]),"/D")==0) swch|=1;
        else if (strcmp(strupr(argv[argnum]),"/L")==0) swch|=2;
        else if (strcmp(strupr(argv[argnum]),"/P")==0) swch|=4;
        else if (strcmp(strupr(argv[argnum]),"/B")==0) swch|=8;
        else ErrorExit(1,"Unknown switch");
      }
   }

   cout << "TASK: ";
   switch(Task){
     case 1: cout << "playing file (device <- " << TParam << ")" << endl;break;
     case 2: cout << "recording file (device -> " << TParam << ")" << endl;break;
     case 3: cout << "mailer mode" << endl;break;
     case 4: cout << "master mode" << endl;break;
   }

   if (Task<5){

     // Read config + FIX switches
     ReadConfig(ctl);
     if (swch&1) cfg.debuginfo=(cfg.debuginfo+1)%2;
     if (swch&2) cfg.pln=(cfg.pln+1)%2;
     if (swch&4) cfg.realcl=(cfg.realcl+1)%2;
     if (swch&8) cfg.wav8bit=(cfg.wav8bit+1)%2;

     // Open COMPort
     OpenComm(cfg.baud,cfg.ioport,cfg.irq);
     if(prtst!=-1) ErrorExit(3,"Communication port not found");

     // Init screen
     StartupScr();

     // Init modem
     SendModemStr(&cfg.init,"Initializing modem");
     SendModemStr(&cfg.voice,"Voice mode");
   }

   // Start Log
   if (Task==3||Task==4){
      struct time _t;
      struct date _d;
      gettime(&_t);getdate(&_d);

      write_log("\n -- executed on ");
      write_log_num(_d.da_day);write_log(".");
      write_log_num(_d.da_mon);write_log(".");
      write_log_num(_d.da_year);write_log(" at ");
      write_log_num(_t.ti_hour);write_log(":");
      write_log_num(_t.ti_min);write_log(" --\n");
   }

   // Main work
   switch(Task){

     case 1:
       PlayFile(TParam);
       break;

     case 2:
       cfg.wavout=0;
       RecFile(TParam,0);
       break;

     case 3:

       if (!cfg.gsmframe) ErrorExit(78,"mailer mode require USE_GSM=1");
       cfg.up=0;cfg.pln=0;
       if (cfg.useaon&1){
         AON();
       } else {
         if (cfg.hook){
           SendModemStr(&cfg.offhook,"Offhook");
           delay(cfg.wallo);
         }
       }
       PlayFile(cfg.sallo);
       if (cfg.loglev&2) write_log("detecting\n");
       switch (Detect()){

         case 1: // Modem
            CreateFlag(cfg.ata);
            SendModemStr(&cfg.data,"Data mode");
            SendModemStr(&cfg.mailinit,"Initializing modem to connect");
            write_log("Detected: MODEM\n");
            ErrorExit(0,"modem detected");
            break;

         case 2: // Voice
            write_log("Detected: VOICE\n");
            PlayFile(cfg.swait);
            for (int curring=0;curring<cfg.RTL;curring++){
               if (!kbhit()){
                if (strlen(cfg.soundfl))
                   CreateFlag(cfg.soundfl);
                else sound(cfg.khz);
                SendModemStr(&cfg.beep,"Beep");
                nosound();
               }
               if (kbhit()) break;
               if (curring+1!=cfg.RTL) delay(cfg.delayring);
            }
            ch=0;while (kbhit()) ch=getch();
            if (cfg.auto_detect&&ch!=27&&ch!=32){
              // check if voice present

              cout << " ! auto : speach in line" << endl;FixLine();
              if (cfg.loglev&2) write_log("detecting\n");
              ch=0;cfg.limit=cfg.auto_detect;
              if ((ch=Detect())==2) ch=32;
              if (ch==3||ch==4) break;
            }
            if (ch!=27) if (ch==32){
              cout << " ! autoanswer skipped" << endl;FixLine();
              write_log("autoanswer skipped\n");
              postdo=1;
            } else {
              PlayFile(cfg.sauto);
              SendModemStr(&cfg.abeep,"aBeep");
              generate_name(fname);
              write_log("Recording: ");write_log(fname);write_log("\n");
              RecFile(fname,cfg.rec_time);
            }
            break;
         case 3:
            write_log("Detected: BUSY\n");break;
         case 4:
            write_log("Detected: DIAL TONE\n");break;
       }
       SendModemStr(&cfg.onhook,"Onhook");
       break;

     case 4:
       int wring;
       char rng[100];cfg.up=0;cfg.pln=0;
       while(kbhit()) getch();

       if (cfg.gsmframe==0&&cfg.useaon!=0) ErrorExit(73,"AON require USE_GSM=1");
       while(!kbhit()){
         cout << "  Waiting for RING ...";rng[0]=0;
         while(!kbhit()&&strstr(rng,"RING")==NULL){
           while(ReadComm(ch)){
             rng[strlen(rng)+1]=0;
             rng[strlen(rng)]=ch;
             if (strlen(rng)==95) rng[0]=0;
           }
         }

         if (!kbhit()){
           cout << endl;FixLine();
           cout << " ! RING .";
           for(wring=0;wring<(cfg.ring-1);wring++){
             if (!WaitFor("RING",7,cfg.debuginfo))
               { cout << " <no more rings>" << endl;FixLine();wring=0;break;}
             else
               cout << ".";
           }

         }
         if (!kbhit()&&wring){

           // Wait cfg.ring

           cout << endl;FixLine();

           if (cfg.useaon&2){
             AON();
           } else {
             SendModemStr(&cfg.offhook,"Offhook");
             delay(cfg.wallo);
           }
           cfg.up=0;
           PlayFile(cfg.sauto);
           SendModemStr(&cfg.abeep,"aBeep");
           generate_name(fname);
           RecFile(fname,cfg.rec_time);
           SendModemStr(&cfg.onhook,"Onhook");
           SendModemStr(&cfg.init,"Initializing modem");
           SendModemStr(&cfg.voice,"Voice mode");
           while(kbhit()) getch();
         }
       }
       cout << endl;FixLine();
       while(kbhit()) getch();
       break;

     case 5:

       // Open files
       if (swch&8) cfg.wav8bit=(cfg.wav8bit+1)%2;
       fp=fopen(TParam,"rb");
       if (fp==NULL) ErrorExit(93,"error: .gsm input");
       outw=TParam;
       cout << "GSM->WAV converting: " << TParam << " -> ";
       while (strchr(outw,'\\')!=NULL) outw=strchr(outw,'\\');
       while (strchr(outw,'/')!=NULL) outw=strchr(outw,'/');
       if (strlen(outw)==0) ErrorExit(153,"out name error");
       if (strchr(outw,'.')!=NULL) *strchr(outw,'.')=0;
       strcat(strlwr(TParam),".wav");
       cout << TParam;if(cfg.wav8bit) cout << " (8bit)";cout << endl;
       if (!Start_GSM_WAV(TParam,cfg.wav8bit)){ cout << "output file error";exit(1);}

       while (fread(gsmb,1,33,fp)==33){
          decode_block(gsmb,cfg.wav8bit);
       }

       // close file
       fclose(fp);
       Close_GSM_WAV();
       ErrorExit(0,"OK");

   }

   // Deinit
   SendModemStr(&cfg.data,"Data mode");
   SendModemStr(&cfg.deinit,"Deinitializing modem");

   if (postdo&&cfg.postspace){
     cout << " ! Press any key to return to Mailer";
     getch();sound(440);delay(5);nosound();
     cout << endl;FixLine();
   }

   // Close COMPort & Exit
   ErrorExit(0,"All ok");

 }
void rm_test_0(ull r, ull m, int k, int max_iter, FILE *fout) {
	ull wordsize = 0, dim = 0, gen_size = 0;
	unsigned char *G = NULL, *D = NULL, *DD = NULL, *C = NULL, *NC = NULL;
	unsigned short *masks = NULL, width = 0;
	ull accumulator = 0, n = 0;

	ull data_block_size_bytes = 0;
	ull code_block_size_bytes = 0;

	dim = rm_dim(r, m);
	wordsize = rm_wordsize(r, m);
	width = rm_codeword_size_in_bytes(r, m);

	gen_size = gen_matrix_mem_size(m, m);
	G = (unsigned char *) malloc(gen_size);
	generate_matrix(m, m, G);
	
	//print(dim, 8 * width, G);printf("\n");

	masks = (unsigned short *) malloc(wordsize * sizeof(unsigned short));
	generate_masks(m, masks);

	data_block_size_bytes = rm_dataword_size_in_bytes(r, m);
	code_block_size_bytes = rm_codeword_size_in_bytes(r, m);

	D =	(unsigned char *) malloc(data_block_size_bytes);
	DD = (unsigned char *) malloc(data_block_size_bytes);

	for (int i = 0; i < data_block_size_bytes; ++i)
		D[i] = (unsigned char) rand();

	C = (unsigned char *) malloc(code_block_size_bytes);
	NC = (unsigned char *) malloc(code_block_size_bytes);

	encode_block(r, m, dim, wordsize, C, D, masks, G);
	//printf("Data:\n");print(1, dim, D);printf("\n");
	
	memcpy(NC, C, width);
	// print(1, wordsize, C);printf("\n");
	// decode_block(r, m, dim, wordsize, NC, DD, masks, G, width);
	// print(1, dim, DD);
	srand (time(NULL));
	
	n = 2 * k / 3 + 1;
	fprintf(fout, "%lld\n", n);
	for (ull i = 0; i < n; i++) {
		accumulator = 0;
		fprintf(fout, "%1.9lf ", (double) i / (double) k);

		for (ull j = 0; j < max_iter; ++j) {
			memcpy(NC, C, code_block_size_bytes);
	
			add_noise(NC, code_block_size_bytes, (double) i / (double) k);				
			decode_block(r, m, dim, wordsize, NC, DD, masks, G, width);
			accumulator += match(data_block_size_bytes, 0, dim, D, DD);
		}

		fprintf(fout, "%1.9lf\n", (double) accumulator / (double) max_iter);
	}
	FREE_IF_ALLOCATED(C);
	FREE_IF_ALLOCATED(NC);
	FREE_IF_ALLOCATED(D);
	FREE_IF_ALLOCATED(DD);
	FREE_IF_ALLOCATED(masks);
	FREE_IF_ALLOCATED(G);
}