Esempio n. 1
0
void crc32_update(crc32_state *ctx, const unsigned char *input, unsigned long length)
{
   LTC_ARGCHKVD(ctx != NULL);
   LTC_ARGCHKVD(input != NULL);
   ulong32 crc = ctx->crc;

   while (length--)
      crc = crc32_m_tab[CRC32_INDEX(crc) ^ *input++] ^ CRC32_SHIFTED(crc);

   ctx->crc = crc;
}
Esempio n. 2
0
void crc32_finish(crc32_state *ctx, void *hash, unsigned long size)
{
   LTC_ARGCHKVD(ctx != NULL);
   LTC_ARGCHKVD(hash != NULL);

   unsigned char* h = hash;
   unsigned long i;

   ulong32 crc = ctx->crc;
   crc ^= _CRC32_NEGL;
   for (i = 0; i < size; i++) {
      h[i] = ((unsigned char*)&(crc))[i];
   }
}
Esempio n. 3
0
void zeromem(void *out, size_t outlen)
{
   unsigned char *mem = out;
   LTC_ARGCHKVD(out != NULL);
   while (outlen-- > 0) {
      *mem++ = 0;
   }
}
Esempio n. 4
0
void ecc_sizes(int *low, int *high)
{
    int i;
    LTC_ARGCHKVD(low  != NULL);
    LTC_ARGCHKVD(high != NULL);

    *low = INT_MAX;
    *high = 0;
    for (i = 0; ltc_ecc_sets[i].size != 0; i++) {
        if (ltc_ecc_sets[i].size < *low)  {
            *low  = ltc_ecc_sets[i].size;
        }
        if (ltc_ecc_sets[i].size > *high) {
            *high = ltc_ecc_sets[i].size;
        }
    }
}
Esempio n. 5
0
/**
   Zero a block of memory
   @param out    The destination of the area to zero
   @param outlen The length of the area to zero (octets)
*/
void zeromem(volatile void *out, size_t outlen)
{
   volatile char *mem = out;
   LTC_ARGCHKVD(out != NULL);
   while (outlen-- > 0) {
      *mem++ = '\0';
   }
}
Esempio n. 6
0
/* adds 16 bytes to the checksum */
static void md2_update_chksum(ltc_md2_ctx *ctx)
{
    int j;
    unsigned char L;

    LTC_ARGCHKVD(ctx != NULL);
    
    L = ctx->chksum[15];
    for (j = 0; j < 16; j++) {
        
        /* caution, the RFC says its "C[j] = S[M[i*16+j] xor L]" but the
	 * reference source code [and test vectors] say otherwise.
         */
        L = (ctx->chksum[j] ^= PI_SUBST[(int)(ctx->buf[j] ^ L)] & 255);
    }
}
Esempio n. 7
0
static void md2_compress(ltc_md2_ctx *ctx)
{
    int j, k;
    unsigned char t;

    LTC_ARGCHKVD(ctx != NULL);

    /* copy block */
    for (j = 0; j < 16; j++) {
        ctx->X[16+j] = ctx->buf[j];
        ctx->X[32+j] = ctx->X[j] ^ ctx->X[16+j];
    }
    
    t = (unsigned char)0;
    
    /* do 18 rounds */
    for (j = 0; j < 18; j++) {
        for (k = 0; k < 48; k++) {
            t = (ctx->X[k] ^= PI_SUBST[(int)(t & 255)]);
        }
        t = (t + (unsigned char)j) & 255;
    }
}
Esempio n. 8
0
static void deinit(void *a)
{
   LTC_ARGCHKVD(a != NULL);
   mpz_clear(a);
   XFREE(a);
}
Esempio n. 9
0
/**
   Free a DSA key
   @param key   The key to free from memory
*/
void dsa_free(dsa_key *key)
{
   LTC_ARGCHKVD(key != NULL);
   mp_clear_multi(key->g, key->q, key->p, key->x, key->y, NULL);
}
Esempio n. 10
0
/**
  Free the allocated ram for a DH key
  @param key   The key which you wish to free
*/
void dh_free(dh_key *key)
{
   LTC_ARGCHKVD(key != NULL);
   mp_cleanup_multi(&key->prime, &key->base, &key->y, &key->x, NULL);
}
Esempio n. 11
0
void crc32_init(crc32_state *ctx)
{
   LTC_ARGCHKVD(ctx != NULL);
   ctx->crc = _CRC32_NEGL;
}
Esempio n. 12
0
static void deinit(void *a)
{
	LTC_ARGCHKVD(a != NULL);

	mpa_free_static_temp_var((mpanum *) &a, external_mem_pool);
}
Esempio n. 13
0
/**
  Free an ECC key from memory
  @param key   The key you wish to free
*/
void ecc_free(ecc_key *key)
{
   LTC_ARGCHKVD(key != NULL);
   mp_clear_multi(key->pubkey.x, key->pubkey.y, key->pubkey.z, key->k, NULL);
}
Esempio n. 14
0
/** Terminate XTS state
   @param xts    The state to terminate
*/
void xts_done(symmetric_xts *xts)
{
   LTC_ARGCHKVD(xts != NULL);
   cipher_descriptor[xts->cipher].done(&xts->key1);
   cipher_descriptor[xts->cipher].done(&xts->key2);
}
Esempio n. 15
0
/**
   Free a DSA key
   @param key   The key to free from memory
*/
void dsa_free(dsa_key *key)
{
   LTC_ARGCHKVD(key != NULL);
   mp_cleanup_multi(&key->y, &key->x, &key->q, &key->g, &key->p, NULL);
   key->type = key->qord = 0;
}
Esempio n. 16
0
/**
  Free an RSA key from memory
  @param key   The RSA key to free
*/
void rsa_free(rsa_key *key)
{
   LTC_ARGCHKVD(key != NULL);
   mp_clear_multi(key->e, key->d, key->N, key->dQ, key->dP, key->qP, key->p, key->q, NULL);
}
Esempio n. 17
0
static void deinit(void *a)
{
	LTC_ARGCHKVD(a != NULL);

	mpa_free_static_temp_var((mpanum *) &a, NULL);
}