예제 #1
0
파일: sha512.c 프로젝트: woo2/gatekeeper-v2
void sha512Final(Sha512Context *context, uint8_t *digest)
{
   uint_t i;
   size_t paddingSize;
   uint64_t totalSize;

   //Length of the original message (before padding)
   totalSize = context->totalSize * 8;

   //Pad the message so that its length is congruent to 112 modulo 128
   if(context->size < 112)
      paddingSize = 112 - context->size;
   else
      paddingSize = 128 + 112 - context->size;

   //Append padding
   sha512Update(context, padding, paddingSize);

   //Append the length of the original message
   context->w[14] = 0;
   context->w[15] = htobe64(totalSize);

   //Calculate the message digest
   sha512ProcessBlock(context);

   //Convert from host byte order to big-endian byte order
   for(i = 0; i < 8; i++)
      context->h[i] = htobe64(context->h[i]);

   //Copy the resulting digest
   if(digest != NULL)
      memcpy(digest, context->digest, SHA512_DIGEST_SIZE);
}
void JNICALL Java_beecrypt_provider_SHA512_update__J_3BII(JNIEnv* env, jclass dummy, jlong param, jbyteArray input, jint off, jint len)
{
	jbyte* data = (*env)->GetByteArrayElements(env, input, 0);
	if (data)
	{
		sha512Update((sha512Param*) param, data+off, len);

		(*env)->ReleaseByteArrayElements(env, input, data, JNI_ABORT);
	}
	else
	{
		jclass ex = (*env)->FindClass(env, "java/lang/NullPointerException");
		if (ex)
			(*env)->ThrowNew(env, ex, (const char*) 0);
	}
}
예제 #3
0
파일: sha512.c 프로젝트: woo2/gatekeeper-v2
error_t sha512Compute(const void *data, size_t length, uint8_t *digest)
{
   //Allocate a memory buffer to hold the SHA-512 context
   Sha512Context *context = osAllocMem(sizeof(Sha512Context));
   //Failed to allocate memory?
   if(!context) return ERROR_OUT_OF_MEMORY;

   //Initialize the SHA-512 context
   sha512Init(context);
   //Digest the message
   sha512Update(context, data, length);
   //Finalize the SHA-512 message digest
   sha512Final(context, digest);

   //Free previously allocated memory
   osFreeMem(context);
   //Successful processing
   return NO_ERROR;
}
예제 #4
0
int main()
{
	int i, failures = 0;
	sha512Param param;
	byte digest[64];

	for (i = 0; i < 1; i++)
	{
		if (sha512Reset(&param))
			return -1;
		if (sha512Update(&param, table[i].input, table[i].input_size))
			return -1;
		if (sha512Digest(&param, digest))
			return -1;

		if (memcmp(digest, table[i].expect, 64))
		{
			printf("failed test vector %d\n", i+1);
			failures++;
		}
	}
	return failures;
}
예제 #5
0
void sha512_224Update(Sha512_224Context *context, const void *data, size_t length)
{
   //The function is defined in the exact same manner as SHA-512
   sha512Update(context, data, length);
}
void JNICALL Java_beecrypt_provider_SHA512_update__JB(JNIEnv* env, jclass dummy, jlong param, jbyte input)
{
	sha512Update((sha512Param*) param, &input, 1);
}