int main(int argc, char *argv[]) { int ret=0; unsigned char md[MDC2_DIGEST_LENGTH]; int i; MDC2_CTX c; static char *text="Now is the time for all "; #ifdef CHARSET_EBCDIC ebcdic2ascii(text,text,strlen(text)); #endif MDC2_Init(&c); MDC2_Update(&c,(unsigned char *)text,strlen(text)); MDC2_Final(&(md[0]),&c); if (memcmp(md,pad1,MDC2_DIGEST_LENGTH) != 0) { for (i=0; i<MDC2_DIGEST_LENGTH; i++) printf("%02X",md[i]); printf(" <- generated\n"); for (i=0; i<MDC2_DIGEST_LENGTH; i++) printf("%02X",pad1[i]); printf(" <- correct\n"); ret=1; } else printf("pad1 - ok\n"); MDC2_Init(&c); c.pad_type=2; MDC2_Update(&c,(unsigned char *)text,strlen(text)); MDC2_Final(&(md[0]),&c); if (memcmp(md,pad2,MDC2_DIGEST_LENGTH) != 0) { for (i=0; i<MDC2_DIGEST_LENGTH; i++) printf("%02X",md[i]); printf(" <- generated\n"); for (i=0; i<MDC2_DIGEST_LENGTH; i++) printf("%02X",pad2[i]); printf(" <- correct\n"); ret=1; } else printf("pad2 - ok\n"); EXIT(ret); return(ret); }
unsigned char *MDC2(const unsigned char *d, size_t n, unsigned char *md) { MDC2_CTX c; static unsigned char m[MDC2_DIGEST_LENGTH]; if (md == NULL) md=m; if (!MDC2_Init(&c)) return NULL; MDC2_Update(&c,d,n); MDC2_Final(md,&c); OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */ return(md); }
ikptr ikrt_openssl_mdc2_update (ikptr s_ctx, ikptr s_input, ikptr s_input_len, ikpcb * pcb) { #ifdef HAVE_MDC2_UPDATE MDC2_CTX * ctx = IK_MDC2_CTX(s_ctx); const void * in = IK_GENERALISED_C_STRING(s_input); size_t in_len = ik_generalised_c_buffer_len(s_input, s_input_len); int rv; rv = MDC2_Update(ctx, in, (unsigned long)in_len); return IK_BOOLEAN_FROM_INT(rv); #else feature_failure(__func__); #endif }
main() { unsigned char md[MDC2_DIGEST_LENGTH]; int i; MDC2_CTX c; static char *text="Now is the time for all "; MDC2_Init(&c); MDC2_Update(&c,text,strlen(text)); MDC2_Final(&(md[0]),&c); for (i=0; i<MDC2_DIGEST_LENGTH; i++) printf("%02X",md[i]); printf("\n"); }
main() { unsigned char md[MDC2_DIGEST_LENGTH]; int i; MDC2_CTX c; static char *text="Now is the time for all "; MDC2_Init(&c); MDC2_Update(&c,text,TINYCLR_SSL_STRLEN(text)); MDC2_Final(&(md[0]),&c); for (i=0; i<MDC2_DIGEST_LENGTH; i++) TINYCLR_SSL_PRINTF("%02X",md[i]); TINYCLR_SSL_PRINTF("\n"); }
static int test_mdc2(int idx) { unsigned char md[MDC2_DIGEST_LENGTH]; MDC2_CTX c; const TESTDATA testdata = tests[idx]; MDC2_Init(&c); MDC2_Update(&c, (const unsigned char *)testdata.input, strlen(testdata.input)); MDC2_Final(&(md[0]), &c); if (!TEST_mem_eq(testdata.expected, MDC2_DIGEST_LENGTH, md, MDC2_DIGEST_LENGTH)) { TEST_info("mdc2 test %d: unexpected output", idx); return 0; } return 1; }
static int update(EVP_MD_CTX *ctx,const void *data,size_t count) { return MDC2_Update(ctx->md_data,data,count); }
static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count) { return MDC2_Update(ctx->md_data,data,count); }