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; }
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]; } }
void zeromem(void *out, size_t outlen) { unsigned char *mem = out; LTC_ARGCHKVD(out != NULL); while (outlen-- > 0) { *mem++ = 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; } } }
/** 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'; } }
/* 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); } }
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; } }
static void deinit(void *a) { LTC_ARGCHKVD(a != NULL); mpz_clear(a); XFREE(a); }
/** 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); }
/** 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); }
void crc32_init(crc32_state *ctx) { LTC_ARGCHKVD(ctx != NULL); ctx->crc = _CRC32_NEGL; }
static void deinit(void *a) { LTC_ARGCHKVD(a != NULL); mpa_free_static_temp_var((mpanum *) &a, external_mem_pool); }
/** 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); }
/** 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); }
/** 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; }
/** 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); }
static void deinit(void *a) { LTC_ARGCHKVD(a != NULL); mpa_free_static_temp_var((mpanum *) &a, NULL); }