Пример #1
0
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);
	}
Пример #2
0
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);
	}
Пример #3
0
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");
	}
ikptr
ikrt_openssl_mdc2_final (ikptr s_ctx, ikpcb * pcb)
{
#ifdef HAVE_MDC2_FINAL
  ikptr		s_pointer	= IK_MDC2_CTX_POINTER(s_ctx);
  MDC2_CTX *	ctx		= IK_POINTER_DATA_VOIDP(s_pointer);
  unsigned char	sum[MDC2_DIGEST_LENGTH];
  int		rv = 0;
  if (ctx) {
    rv = MDC2_Final(sum, ctx);
    free(ctx);
    IK_POINTER_SET_NULL(s_pointer);
  }
  return (rv)? ika_bytevector_from_memory_block(pcb, sum, MDC2_DIGEST_LENGTH) : IK_FALSE;
#else
  feature_failure(__func__);
#endif
}
Пример #6
0
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;
}