adding original ip_cryptohash from vx7 (#7)

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>
This commit is contained in:
2026-07-30 18:54:53 +05:30
committed by neelimap
co-authored by neelimap
parent b4aed7ab58
commit e1f2913de8
8 changed files with 1552 additions and 0 deletions
@@ -0,0 +1,43 @@
# Makefile - makefile for hash layer
#
# Copyright (c) 2014-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
# Makefile for hash layer
#
LIB_BASE_NAME = ip_crypto
LIB_FORMAT = both
ifeq ($(SPACE),user)
include $(WIND_USR_MK)/defs.library.mk
else
include $(WIND_KRNL_MK)/defs.library.mk
endif
ifeq ($(_WRS_CONFIG_SEC_HASH),y)
ifneq ($(SPACE),user)
OBJS = secHashMd5Openssl.o
OBJS += secHashRmdOpenssl.o
OBJS += secHashSha1Openssl.o
OBJS += secHashSha256Openssl.o
OBJS += secHashSha384Openssl.o
OBJS += secHashSha512Openssl.o
OBJS += secHashWhirlpoolOpenssl.o
endif
endif
ifeq ($(SPACE),user)
include $(WIND_USR_MK)/rules.library.mk
else
include $(WIND_KRNL_MK)/rules.library.mk
endif
@@ -0,0 +1,214 @@
/* 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);
}
@@ -0,0 +1,214 @@
/* secHashRmdOpenssl.c - secHash Ripemd Provider */
/*
* Copyright (c) 2015, 2019, 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 Ripemd provider, using openssl low-level APIs.
*/
/* includes */
#include <vxWorks.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <secHash.h>
#include <openssl/ripemd.h>
/* defines */
/* typedefs */
/* globals */
/* locals */
/* forward declarations */
#ifndef OPENSSL_NO_RMD160
/*******************************************************************************
*
* secHashRmdInit - Initialize a SEC_HASH_CTX for Ripemd
*
* Initialize a SEC_HASH_CTX for Ripemd
*
* RETURNS: OK on success, ERROR otherwise
*/
static STATUS secHashRmdInit
(
SEC_HASH_CTX* ctx,
const SEC_HASH_TEMPLATE* template
)
{
if (!ctx || !template)
return ERROR;
ctx->data = malloc(sizeof(RIPEMD160_CTX));
if (!ctx->data)
return ERROR;
if(!RIPEMD160_Init((RIPEMD160_CTX*)ctx->data))
return ERROR;
return OK;
}
/*******************************************************************************
*
* secHashRmdUpdate - Add data to a Ripemd hash calculation
*
* Add data to a Ripemd hash calculation
*
* RETURNS: OK on success, ERROR otherwise
*/
static STATUS secHashRmdUpdate
(
SEC_HASH_CTX* ctx,
const void* data,
size_t count)
{
if (!ctx || !ctx->data || !data)
return ERROR;
if (!RIPEMD160_Update((RIPEMD160_CTX*)ctx->data, data, count))
return ERROR;
return OK;
}
/*******************************************************************************
*
* secHashRmdFinal - Finalize a Ripemd hash calculation
*
* Finalize a Ripemd hash calculation
*
* RETURNS: OK on success, ERROR otherwise
*/
static STATUS secHashRmdFinal
(
SEC_HASH_CTX* ctx,
unsigned char* digest,
unsigned int* digestLen
)
{
if (!ctx || !ctx->data || !digest || !digestLen)
return ERROR;
if (!RIPEMD160_Final(digest, (RIPEMD160_CTX*)ctx->data))
return ERROR;
*digestLen = RIPEMD160_DIGEST_LENGTH;
return OK;
}
/*******************************************************************************
*
* secHashRmdCopy - Make a copy of an Ripemd SEC_HASH_CTX
*
* Make a copy of an Ripemd SEC_HASH_CTX
*
* RETURNS: OK on success, ERROR otherwise
*
*/
static STATUS secHashRmdCopy
(
SEC_HASH_CTX* copy,
SEC_HASH_CTX* org
)
{
if (!copy || !org || !org->data)
return ERROR;
copy->data = malloc(sizeof(RIPEMD160_CTX));
if (!copy->data)
return ERROR;
memcpy(copy->data, org->data, sizeof(RIPEMD160_CTX));
return OK;
}
/*******************************************************************************
*
* secHashRmdCleanup - Ripemd secHash cleanup callback
*
* Ripemd secHash cleanup callback
*
* RETURNS: N/A
*/
static void secHashRmdCleanup
(
SEC_HASH_CTX* ctx
)
{
if (ctx && ctx->data)
{
free(ctx->data);
ctx->data = NULL;
}
}
const SEC_HASH_TEMPLATE secHashRmdOpensslTempl =
{
SEC_HASH_ID_RMD,
RIPEMD160_DIGEST_LENGTH,
RIPEMD160_CBLOCK,
secHashRmdInit,
secHashRmdUpdate,
secHashRmdFinal,
NULL,
secHashRmdCopy,
secHashRmdCleanup,
};
/*******************************************************************************
*
* secHashRmdOpensslInit - Initialize the openssl Ripemd provider
*
* Initialize the openssl Ripemd provider as the default Ripemd secHash provider.
* This function is called as a CDF init function.
*
* RETURNS: N/A
*/
void secHashRmdOpensslInit
(
void
)
{
secHashRmdTemplateSet(&secHashRmdOpensslTempl);
}
/*******************************************************************************
*
* secHashRmdOpensslTemplateGet - Get an Ripemd SEC_HASH_TEMPLATE
*
* Get an Ripemd SEC_HASH_TEMPLATE
*
* RETURNS: A pointer to a SEC_HASH_TEMPLATE
*/
const SEC_HASH_TEMPLATE* secHashRmdOpensslTemplateGet
(
void
)
{
return &secHashRmdOpensslTempl;
}
#endif
@@ -0,0 +1,211 @@
/* secHashSha1Openssl.c - secHash SHA1 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 SHA1 provider, using openssl low-level SHA1 APIs.
*/
/* includes */
#include <vxWorks.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <secHash.h>
#include <openssl/sha.h>
/* defines */
/* typedefs */
/* globals */
/* locals */
/* forward declarations */
/*******************************************************************************
*
* secHashSha1Init - Initialize a SEC_HASH_CTX for SHA1
*
* Initialize a SEC_HASH_CTX for SHA1
*
* RETURNS: OK on success, ERROR otherwise
*/
static STATUS secHashSha1Init
(
SEC_HASH_CTX* ctx,
const SEC_HASH_TEMPLATE* template
)
{
if (!ctx || !template)
return ERROR;
ctx->data = malloc(sizeof(SHA_CTX));
if (!ctx->data)
return ERROR;
if(!SHA1_Init((SHA_CTX*)ctx->data))
return ERROR;
return OK;
}
/*******************************************************************************
*
* secHashSha1Update - Add data to a SHA1 hash calculation
*
* Add data to a SHA1 hash calculation
*
* RETURNS: OK on success, ERROR otherwise
*/
static STATUS secHashSha1Update
(
SEC_HASH_CTX* ctx,
const void* data,
size_t count
)
{
if (!ctx || !ctx->data || !data)
return ERROR;
if (!SHA1_Update((SHA_CTX*)ctx->data, data, count))
return ERROR;
return OK;
}
/*******************************************************************************
*
* secHashSha1Final - Finalize a SHA1 hash calculation
*
* Finalize a SHA1 hash calculation
*
* RETURNS: OK on success, ERROR otherwise
*/
static STATUS secHashSha1Final
(
SEC_HASH_CTX* ctx,
unsigned char* digest,
unsigned int* digestLen
)
{
if (!ctx || !ctx->data || !digest || !digestLen)
return ERROR;
if (!SHA1_Final(digest, (SHA_CTX*)ctx->data))
return ERROR;
*digestLen = SHA_DIGEST_LENGTH;
return OK;
}
/*******************************************************************************
*
* secHashSha1Copy - Make a copy of a SHA1 SEC_HASH_CTX
*
* Make a copy of a SHA1 SEC_HASH_CTX
*
* RETURNS: OK on success, ERROR otherwise
*/
static STATUS secHashSha1Copy
(
SEC_HASH_CTX* copy,
SEC_HASH_CTX* org
)
{
if (!copy || !org || !org->data)
return ERROR;
copy->data = malloc(sizeof(SHA_CTX));
if (!copy->data)
return ERROR;
memcpy(copy->data, org->data, sizeof(SHA_CTX));
return OK;
}
/*******************************************************************************
*
* secHashSha1Cleanup - Cleanup SHA1 SEC_HASH_CTX
*
* Cleanup SHA1 SEC_HASH_CTX
*
* RETURNS: N/A
*/
static void secHashSha1Cleanup
(
SEC_HASH_CTX* ctx
)
{
if (ctx && ctx->data)
{
free(ctx->data);
ctx->data = NULL;
}
}
static const SEC_HASH_TEMPLATE secHashSha1OpensslTemplate =
{
SEC_HASH_ID_SHA1,
SHA_DIGEST_LENGTH,
SHA_CBLOCK,
secHashSha1Init,
secHashSha1Update,
secHashSha1Final,
NULL,
secHashSha1Copy,
secHashSha1Cleanup,
};
/*******************************************************************************
*
* secHashSha1OpensslInit - Initialize the openssl SHA1 provider
*
* Initialize the openssl SHA1 provider as the default SHA1 secHash provider.
* This function is called as a CDF init function.
*
* RETURNS: N/A
*/
void secHashSha1OpensslInit
(
void
)
{
secHashSha1TemplateSet(&secHashSha1OpensslTemplate);
}
/*******************************************************************************
*
* secHashSha1OpensslTemplateGet - Get a SHA1 SEC_HASH_TEMPLATE
*
* Get a SHA1 SEC_HASH_TEMPLATE
*
* RETURNS: A pointer to a SEC_HASH_TEMPLATE if successful, or NULL otherwise
*/
const SEC_HASH_TEMPLATE* secHashSha1OpensslTemplateGet
(
void
)
{
return &secHashSha1OpensslTemplate;
}
@@ -0,0 +1,215 @@
/* secHashSha256Openssl.c - secHash SHA256 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 SHA256 provider, using openssl low-level SHA256 APIs.
*/
/* includes */
#include <vxWorks.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <secHash.h>
#include <openssl/sha.h>
/* defines */
/* typedefs */
/* globals */
/* locals */
/* forward declarations */
/*******************************************************************************
*
* secHashSha256Init - Initialize a SEC_HASH_CTX for SHA256
*
* Initialize a SEC_HASH_CTX for SHA256
*
* RETURNS: OK on success, ERROR otherwise
*/
static STATUS secHashSha256Init
(
SEC_HASH_CTX* ctx,
const SEC_HASH_TEMPLATE* template
)
{
if (!ctx || !template)
return ERROR;
ctx->data = malloc(sizeof(SHA256_CTX));
if (!ctx->data)
return ERROR;
if(!SHA256_Init((SHA256_CTX*)ctx->data))
return ERROR;
return OK;
}
/*******************************************************************************
*
* secHashSha256Update - Add data to a SHA256 hash calculation
*
* Add data to a SHA256 hash calculation
*
* RETURNS: OK on success, ERROR otherwise
*/
static STATUS secHashSha256Update
(
SEC_HASH_CTX* ctx,
const void* data,
size_t count
)
{
if (!ctx || !ctx->data || !data)
return ERROR;
if (!SHA256_Update((SHA256_CTX*)ctx->data, data, count))
return ERROR;
return OK;
}
/*******************************************************************************
*
* secHashSha256Final - Finalize a SHA256 hash calculation
*
* Finalize a SHA256 hash calculation
*
* RETURNS: OK on success, ERROR otherwise
*/
static STATUS secHashSha256Final
(
SEC_HASH_CTX* ctx,
unsigned char* digest,
unsigned int* digestLen
)
{
if (!ctx || !ctx->data || !digest || !digestLen)
return ERROR;
if (!SHA256_Final(digest, (SHA256_CTX*)ctx->data))
return ERROR;
*digestLen = SHA256_DIGEST_LENGTH;
return OK;
}
/*******************************************************************************
*
* secHashSha256Copy - Make a copy of a SHA256 SEC_HASH_CTX
*
* Make a copy of a SHA256 SEC_HASH_CTX
*
* RETURNS: OK on success, ERROR otherwise
*/
static STATUS secHashSha256Copy
(
SEC_HASH_CTX* copy,
SEC_HASH_CTX* org
)
{
if (!copy || !org || !org->data)
return ERROR;
copy->data = malloc(sizeof(SHA256_CTX));
if (!copy->data)
return ERROR;
memcpy(copy->data, org->data, sizeof(SHA256_CTX));
return OK;
}
/*******************************************************************************
*
* secHashSha256Cleanup - Cleanup SHA256 SEC_HASH_CTX
*
* Cleanup SHA256 SEC_HASH_CTX
*
* RETURNS: N/A
*
* ERRNO: N/A
*/
static void secHashSha256Cleanup
(
SEC_HASH_CTX* ctx
)
{
if (ctx && ctx->data)
{
free(ctx->data);
ctx->data = NULL;
}
}
static const SEC_HASH_TEMPLATE secHashSha256OpensslTempl =
{
SEC_HASH_ID_SHA256,
SHA256_DIGEST_LENGTH,
SHA256_CBLOCK,
secHashSha256Init,
secHashSha256Update,
secHashSha256Final,
NULL,
secHashSha256Copy,
secHashSha256Cleanup,
};
/*******************************************************************************
*
* secHashSha256OpensslInit - Initialize the openssl SHA256 provider
*
* Initialize the openssl SHA256 provider
*
* RETURNS: N/A
*
* ERRNO: N/A
*/
void secHashSha256OpensslInit
(
void
)
{
secHashSha256TemplateSet(&secHashSha256OpensslTempl);
}
/*******************************************************************************
*
* secHashSha256OpensslTemplateGet - Get a SHA256 SEC_HASH_TEMPLATE
*
* Get a SHA256 SEC_HASH_TEMPLATE
*
* RETURNS: A pointer to a SEC_HASH_TEMPLATE if successful, or NULL otherwise
*
* ERRNO: N/A
*/
const SEC_HASH_TEMPLATE* secHashSha256OpensslTemplateGet
(
void
)
{
return &secHashSha256OpensslTempl;
}
@@ -0,0 +1,216 @@
/* secHashSha384Openssl.c - secHash SHA384 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 SHA384 provider, using openssl low-level SHA384 APIs.
*/
/* includes */
#include <vxWorks.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <secHash.h>
#include <openssl/sha.h>
/* defines */
/* typedefs */
/* globals */
/* locals */
/* forward declarations */
/*******************************************************************************
*
* secHashSha384Init - Initialize a SEC_HASH_CTX for SHA384
*
* Initialize a SEC_HASH_CTX for SHA384
*
* RETURNS: OK on success, ERROR otherwise
*/
static STATUS secHashSha384Init
(
SEC_HASH_CTX* ctx,
const SEC_HASH_TEMPLATE* template
)
{
if (!ctx || !template)
return ERROR;
ctx->data = malloc(sizeof(SHA512_CTX));
if (!ctx->data)
return ERROR;
if(!SHA384_Init((SHA512_CTX*)ctx->data))
return ERROR;
return OK;
}
/*******************************************************************************
*
* secHashSha384Update - Add data to a SHA384 hash calculation
*
* Add data to a SHA384 hash calculation
*
* RETURNS: OK on success, ERROR otherwise
*/
static STATUS secHashSha384Update
(
SEC_HASH_CTX* ctx,
const void* data,
size_t count
)
{
if (!ctx || !ctx->data || !data)
return ERROR;
if (!SHA384_Update((SHA512_CTX*)ctx->data, data, count))
return ERROR;
return OK;
}
/*******************************************************************************
*
* secHashSha384Final - Finalize a SHA384 hash calculation
*
* Finalize a SHA384 hash calculation
*
* RETURNS: OK on success, ERROR otherwise
*/
static STATUS secHashSha384Final
(
SEC_HASH_CTX* ctx,
unsigned char* digest,
unsigned int* digestLen
)
{
if (!ctx || !ctx->data || !digest || !digestLen)
return ERROR;
if (!SHA384_Final(digest, (SHA512_CTX*)ctx->data))
return ERROR;
*digestLen = SHA384_DIGEST_LENGTH;
return OK;
}
/*******************************************************************************
*
* secHashSha384Copy - Make a copy of a SHA384 SEC_HASH_CTX
*
* Make a copy of a SHA384 SEC_HASH_CTX
*
* RETURNS: OK on success, ERROR otherwise
*/
static STATUS secHashSha384Copy
(
SEC_HASH_CTX* copy,
SEC_HASH_CTX* org
)
{
if (!copy || !org || !org->data)
return ERROR;
copy->data = malloc(sizeof(SHA512_CTX));
if (!copy->data)
return ERROR;
memcpy(copy->data, org->data, sizeof(SHA512_CTX));
return OK;
}
/*******************************************************************************
*
* secHashSha384Cleanup - Cleanup SHA384 SEC_HASH_CTX
*
* Cleanup SHA384 SEC_HASH_CTX
*
* RETURNS: N/A
*
* ERRNO: N/A
*/
static void secHashSha384Cleanup
(
SEC_HASH_CTX* ctx
)
{
if (ctx && ctx->data)
{
free(ctx->data);
ctx->data = NULL;
}
}
static const SEC_HASH_TEMPLATE secHashSha384OpensslTempl =
{
SEC_HASH_ID_SHA384,
SHA384_DIGEST_LENGTH,
SHA512_CBLOCK,
secHashSha384Init,
secHashSha384Update,
secHashSha384Final,
NULL,
secHashSha384Copy,
secHashSha384Cleanup,
};
/*******************************************************************************
*
* secHashSha384OpensslInit - Initialize the openssl SHA384 provider
*
* Initialize the openssl SHA384 provider
*
* RETURNS: N/A
*
* ERRNO: N/A
*/
void secHashSha384OpensslInit
(
void
)
{
secHashSha384TemplateSet(&secHashSha384OpensslTempl);
}
/*******************************************************************************
*
* secHashSha384OpensslTemplateGet - Get a SHA384 SEC_HASH_TEMPLATE
*
* Get a SHA384 SEC_HASH_TEMPLATE
*
* RETURNS: A pointer to a SEC_HASH_TEMPLATE if successful, or NULL otherwise
*
* ERRNO: N/A
*/
const SEC_HASH_TEMPLATE* secHashSha384OpensslTemplateGet
(
void
)
{
return &secHashSha384OpensslTempl;
}
@@ -0,0 +1,222 @@
/* secHashSha512Openssl.c - secHash SHA512 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 SHA512 provider, using openssl low-level SHA512 APIs.
*/
/* includes */
#include <vxWorks.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <secHash.h>
#include <openssl/sha.h>
/* defines */
/* typedefs */
/* globals */
/* locals */
/* forward declarations */
/*******************************************************************************
*
* secHashSha512Init - Initialize a SEC_HASH_CTX for SHA512
*
* Initialize a SEC_HASH_CTX for SHA512
*
* RETURNS: RET_DESC
*
* ERRNO:
* \is
* \i S_fooLib_BAR
* ERRNO_DESC
* \ie
*/
static STATUS secHashSha512Init
(
SEC_HASH_CTX* ctx,
const SEC_HASH_TEMPLATE* template
)
{
if (!ctx || !template)
return ERROR;
ctx->data = malloc(sizeof(SHA512_CTX));
if (!ctx->data)
return ERROR;
if(!SHA512_Init((SHA512_CTX*)ctx->data))
return ERROR;
return OK;
}
/*******************************************************************************
*
* secHashSha512Update - Add data to a SHA512 hash calculation
*
* Add data to a SHA512 hash calculation
*
* RETURNS: RET_DESC
*/
static STATUS secHashSha512Update
(
SEC_HASH_CTX* ctx,
const void* data,
size_t count
)
{
if (!ctx || !ctx->data || !data)
return ERROR;
if (!SHA512_Update((SHA512_CTX*)ctx->data, data, count))
return ERROR;
return OK;
}
/*******************************************************************************
*
* secHashSha512Final - Finalize a SHA512 hash calculation
*
* Finalize a SHA512 hash calculation
*
* RETURNS: RET_DESC
*/
static STATUS secHashSha512Final
(
SEC_HASH_CTX* ctx,
unsigned char* digest,
unsigned int* digestLen
)
{
if (!ctx || !ctx->data || !digest || !digestLen)
return ERROR;
if (!SHA512_Final(digest, (SHA512_CTX*)ctx->data))
return ERROR;
*digestLen = SHA512_DIGEST_LENGTH;
return OK;
}
/*******************************************************************************
*
* secHashSha512Copy - Make a copy of a SHA512 SEC_HASH_CTX
*
* Make a copy of a SHA512 SEC_HASH_CTX
*
* RETURNS: RET_DESC
*/
static STATUS secHashSha512Copy
(
SEC_HASH_CTX* copy,
SEC_HASH_CTX* org
)
{
if (!copy || !org || !org->data)
return ERROR;
copy->data = malloc(sizeof(SHA512_CTX));
if (!copy->data)
return ERROR;
memcpy(copy->data, org->data, sizeof(SHA512_CTX));
return OK;
}
/*******************************************************************************
*
* secHashSha512Cleanup - Cleanup SHA512 SEC_HASH_CTX
*
* Cleanup SHA512 SEC_HASH_CTX
*
* RETURNS: N/A
*
* ERRNO: N/A
*/
static void secHashSha512Cleanup
(
SEC_HASH_CTX* ctx
)
{
if (ctx && ctx->data)
{
free(ctx->data);
ctx->data = NULL;
}
}
static const SEC_HASH_TEMPLATE secHashSha512OpensslTempl =
{
SEC_HASH_ID_SHA512,
SHA512_DIGEST_LENGTH,
SHA512_CBLOCK,
secHashSha512Init,
secHashSha512Update,
secHashSha512Final,
NULL,
secHashSha512Copy,
secHashSha512Cleanup,
};
/*******************************************************************************
*
* secHashSha512OpensslInit - Initialize the openssl SHA512 provider
*
* Initialize the openssl SHA512 provider
*
* RETURNS: N/A
*
* ERRNO: N/A
*/
void secHashSha512OpensslInit
(
void
)
{
secHashSha512TemplateSet(&secHashSha512OpensslTempl);
}
/*******************************************************************************
*
* secHashSha512OpensslTemplateGet - Get a SHA512 SEC_HASH_TEMPLATE
*
* Get a SHA512 SEC_HASH_TEMPLATE
*
* RETURNS: A pointer to a SEC_HASH_TEMPLATE if successful, or NULL otherwise
*
* ERRNO: N/A
*/
const SEC_HASH_TEMPLATE* secHashSha512OpensslTemplateGet
(
void
)
{
return &secHashSha512OpensslTempl;
}
@@ -0,0 +1,217 @@
/* secHashWhirlpoolOpenssl.c - secHash Whirlpool Provider Callbacks */
/*
* Copyright (c) 2015, 2019, 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 Whirlpool provider, using openssl low-level Whirlpool APIs.
*/
/* includes */
#include <vxWorks.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <secHash.h>
#include <openssl/whrlpool.h>
/* defines */
/* typedefs */
/* globals */
/* locals */
/* forward declarations */
#ifndef OPENSSL_NO_WHIRLPOOL
/*******************************************************************************
*
* secHashWhirlpoolInit - Initialize a SEC_HASH_CTX for Whirlpool
*
* Initialize a SEC_HASH_CTX for Whirlpool
*
* RETURNS: RET_DESC
*/
static STATUS secHashWhirlpoolInit
(
SEC_HASH_CTX* ctx,
const SEC_HASH_TEMPLATE* template
)
{
if (!ctx || !template)
return ERROR;
ctx->data = malloc(sizeof(WHIRLPOOL_CTX));
if (!ctx->data)
return ERROR;
if(!WHIRLPOOL_Init((WHIRLPOOL_CTX*)ctx->data))
return ERROR;
return OK;
}
/*******************************************************************************
*
* secHashWhirlpoolUpdate - Add data to a Whirlpool hash calculation
*
* Add data to a Whirlpool hash calculation
*
* RETURNS: RET_DESC
*/
static STATUS secHashWhirlpoolUpdate
(
SEC_HASH_CTX* ctx,
const void* data,
size_t count
)
{
if (!ctx || !ctx->data || !data)
return ERROR;
if (!WHIRLPOOL_Update((WHIRLPOOL_CTX*)ctx->data, data, count))
return ERROR;
return OK;
}
/*******************************************************************************
*
* secHashWhirlpoolFinal - Finalize a Whirlpool hash calculation
*
* Finalize a Whirlpool hash calculation
*
* RETURNS: RET_DESC
*/
static STATUS secHashWhirlpoolFinal
(
SEC_HASH_CTX* ctx,
unsigned char* digest,
unsigned int* digestLen
)
{
if (!ctx || !ctx->data || !digest || !digestLen)
return ERROR;
if (!WHIRLPOOL_Final(digest, (WHIRLPOOL_CTX*)ctx->data))
return ERROR;
*digestLen = WHIRLPOOL_DIGEST_LENGTH;
return OK;
}
/*******************************************************************************
*
* secHashWhirlpoolCopy - Make a copy of a Whirlpool SEC_HASH_CTX
*
* Make a copy of a Whirlpool SEC_HASH_CTX
*
* RETURNS: RET_DESC
*/
static STATUS secHashWhirlpoolCopy
(
SEC_HASH_CTX* copy,
SEC_HASH_CTX* org
)
{
if (!copy || !org || !org->data)
return ERROR;
copy->data = malloc(sizeof(WHIRLPOOL_CTX));
if (!copy->data)
return ERROR;
memcpy(copy->data, org->data, sizeof(WHIRLPOOL_CTX));
return OK;
}
/*******************************************************************************
*
* secHashWhirlpoolCleanup - Cleanup Whirlpool SEC_HASH_CTX
*
* Cleanup Whirlpool SEC_HASH_CTX
*
* RETURNS: N/A
*
* ERRNO: N/A
*/
static void secHashWhirlpoolCleanup
(
SEC_HASH_CTX* ctx
)
{
if (ctx && ctx->data)
{
free(ctx->data);
ctx->data = NULL;
}
}
static const SEC_HASH_TEMPLATE secHashWhirlpoolOpensslTemplate =
{
SEC_HASH_ID_WHIRLPOOL,
WHIRLPOOL_DIGEST_LENGTH,
WHIRLPOOL_BBLOCK / 8,
secHashWhirlpoolInit,
secHashWhirlpoolUpdate,
secHashWhirlpoolFinal,
NULL,
secHashWhirlpoolCopy,
secHashWhirlpoolCleanup,
};
/*******************************************************************************
*
* secHashWhirlpoolOpensslInit - Initialize the openssl Whirlpool provider
*
* Initialize the openssl Whirlpool provider as the default Whirlpool secHash provider.
* This function is called as a CDF init function.
*
* RETURNS: N/A
*
* ERRNO: N/A
*/
void secHashWhirlpoolOpensslInit
(
void
)
{
secHashWhirlpoolTemplateSet(&secHashWhirlpoolOpensslTemplate);
}
/*******************************************************************************
*
* secHashWhirlpoolOpensslTemplateGet - Get a Whirlpool SEC_HASH_TEMPLATE
*
* Get a Whirlpool SEC_HASH_TEMPLATE
*
* RETURNS: A pointer to a SEC_HASH_TEMPLATE if successful, or NULL otherwise
*
* ERRNO: N/A
*/
const SEC_HASH_TEMPLATE* secHashWhirlpoolOpensslTemplateGet
(
void
)
{
return &secHashWhirlpoolOpensslTemplate;
}
#endif