added the original ipcryptohash from vx7 to vx6.9 Co-authored-by: neelimap <neelimaps@neominds.in> Reviewed-on: http://13.234.246.121:3000/Neominds/ossl35vx69/pulls/7 Co-authored-by: Neelima P S <neelima.ps@neominds.in> Co-committed-by: Neelima P S <neelima.ps@neominds.in>
215 lines
4.1 KiB
C
215 lines
4.1 KiB
C
/* secHashMd5Openssl.c - secHash MD5 Provider Callbacks */
|
|
|
|
/*
|
|
* Copyright (c) 2015, 2021, 2024 Wind River Systems, Inc.
|
|
*
|
|
* The right to copy, distribute, modify or otherwise make use
|
|
* of this software may be licensed only pursuant to the terms
|
|
* of an applicable Wind River license agreement.
|
|
*/
|
|
|
|
/*
|
|
DESCRIPTION
|
|
This file implements a secHash MD5 provider, using openssl low-level MD5 APIs.
|
|
|
|
*/
|
|
|
|
/* includes */
|
|
|
|
#include <vxWorks.h>
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <secHash.h>
|
|
|
|
#include <openssl/md5.h>
|
|
|
|
|
|
/* defines */
|
|
|
|
/* typedefs */
|
|
|
|
/* globals */
|
|
|
|
/* locals */
|
|
|
|
/* forward declarations */
|
|
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* secHashMd5Init - Initialize a SEC_HASH_CTX for MD5
|
|
*
|
|
* Initialize a SEC_HASH_CTX for MD5
|
|
*
|
|
* RETURNS: OK on success, ERROR otherwise
|
|
*
|
|
*/
|
|
|
|
static STATUS secHashMd5Init
|
|
(
|
|
SEC_HASH_CTX* ctx,
|
|
const SEC_HASH_TEMPLATE* template
|
|
)
|
|
{
|
|
if (!ctx || !template)
|
|
return ERROR;
|
|
ctx->data = malloc(sizeof(MD5_CTX));
|
|
if (!ctx->data)
|
|
return ERROR;
|
|
if(!MD5_Init((MD5_CTX*)ctx->data))
|
|
return ERROR;
|
|
|
|
return OK;
|
|
}
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* secHashMd5Update - Add data to an MD5 hash calculation
|
|
*
|
|
* Add data to an MD5 hash calculation
|
|
*
|
|
* RETURNS: OK on success, ERROR otherwise
|
|
*
|
|
*/
|
|
|
|
static STATUS secHashMd5Update
|
|
(
|
|
SEC_HASH_CTX* ctx,
|
|
const void* data,
|
|
size_t count)
|
|
{
|
|
if (!ctx || !ctx->data || !data)
|
|
return ERROR;
|
|
if (!MD5_Update((MD5_CTX*)ctx->data, data, count))
|
|
return ERROR;
|
|
return OK;
|
|
}
|
|
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* secHashMd5Final - Finalize an MD5 hash calculation
|
|
*
|
|
* Finalize an MD5 hash calculation
|
|
*
|
|
* RETURNS: OK on success, ERROR otherwise
|
|
*
|
|
*/
|
|
|
|
static STATUS secHashMd5Final
|
|
(
|
|
SEC_HASH_CTX* ctx,
|
|
unsigned char* digest,
|
|
unsigned int* digestLen
|
|
)
|
|
{
|
|
if (!ctx || !ctx->data || !digest || !digestLen)
|
|
return ERROR;
|
|
if (!MD5_Final(digest, (MD5_CTX*)ctx->data))
|
|
return ERROR;
|
|
*digestLen = MD5_DIGEST_LENGTH;
|
|
return OK;
|
|
}
|
|
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* secHashMd5Copy - Make a copy of an MD5 SEC_HASH_CTX
|
|
*
|
|
* Make a copy of an MD5 SEC_HASH_CTX
|
|
*
|
|
* RETURNS: OK on success, ERROR otherwise
|
|
*
|
|
*/
|
|
|
|
static STATUS secHashMd5Copy
|
|
(
|
|
SEC_HASH_CTX* copy,
|
|
SEC_HASH_CTX* org
|
|
)
|
|
{
|
|
if (!copy || !org || !org->data)
|
|
return ERROR;
|
|
|
|
copy->data = malloc(sizeof(MD5_CTX));
|
|
if (!copy->data)
|
|
return ERROR;
|
|
memcpy(copy->data, org->data, sizeof(MD5_CTX));
|
|
|
|
return OK;
|
|
}
|
|
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* secHashMd5Cleanup - MD5 secHash cleanup callback
|
|
*
|
|
* MD5 secHash cleanup callback
|
|
*
|
|
* RETURNS: N/A
|
|
*/
|
|
|
|
static void secHashMd5Cleanup
|
|
(
|
|
SEC_HASH_CTX* ctx
|
|
)
|
|
{
|
|
if (ctx && ctx->data)
|
|
{
|
|
free(ctx->data);
|
|
ctx->data = NULL;
|
|
}
|
|
}
|
|
|
|
|
|
static SEC_HASH_TEMPLATE secHashMd5OpensslTempl =
|
|
{
|
|
SEC_HASH_ID_MD5,
|
|
MD5_DIGEST_LENGTH,
|
|
MD5_CBLOCK,
|
|
secHashMd5Init,
|
|
secHashMd5Update,
|
|
secHashMd5Final,
|
|
NULL,
|
|
secHashMd5Copy,
|
|
secHashMd5Cleanup,
|
|
};
|
|
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* secHashMd5OpensslTemplateGet - Get an MD5 SEC_HASH_TEMPLATE
|
|
*
|
|
* Get an MD5 SEC_HASH_TEMPLATE
|
|
*
|
|
* RETURNS: A pointer to a SEC_HASH_TEMPLATE if successful, or NULL otherwise
|
|
*/
|
|
|
|
SEC_HASH_TEMPLATE* secHashMd5OpensslTemplateGet
|
|
(
|
|
void
|
|
)
|
|
{
|
|
return &secHashMd5OpensslTempl;
|
|
}
|
|
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* secHashMd5OpensslInit - Initialize the openssl MD5 provider
|
|
*
|
|
* Initialize the openssl MD5 provider as the default MD5 secHash provider.
|
|
* This function is called as a CDF init function.
|
|
*
|
|
* RETURNS: N/A
|
|
*/
|
|
|
|
void secHashMd5OpensslInit
|
|
(
|
|
void
|
|
)
|
|
{
|
|
secHashMd5TemplateSet(&secHashMd5OpensslTempl);
|
|
}
|