mirror of
https://github.com/SELinuxProject/selinux
synced 2025-05-03 16:17:59 +00:00
This replaces the openssl library with SHA1 hash functions extracted from [1] as this is a public domain implementation. util/selabel_digest -v option still compares the result with the openssl command "openssl dgst -sha1 -hex .." for validation. [1] https://github.com/WaterJuice/CryptLib Signed-off-by: Richard Haines <richard_c_haines@btinternet.com>
86 lines
3.5 KiB
C
86 lines
3.5 KiB
C
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// LibSha1
|
|
//
|
|
// Implementation of SHA1 hash function.
|
|
// Original author: Steve Reid <sreid@sea-to-sky.net>
|
|
// Contributions by: James H. Brown <jbrown@burgoyne.com>, Saul Kravitz <Saul.Kravitz@celera.com>,
|
|
// and Ralph Giles <giles@ghostscript.com>
|
|
// Modified by WaterJuice retaining Public Domain license.
|
|
//
|
|
// This is free and unencumbered software released into the public domain - June 2013 waterjuice.org
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef _sha1_h_
|
|
#define _sha1_h_
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// IMPORTS
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// TYPES
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Sha1Context - This must be initialised using Sha1Initialised. Do not modify the contents of this structure directly.
|
|
typedef struct
|
|
{
|
|
uint32_t State[5];
|
|
uint32_t Count[2];
|
|
uint8_t Buffer[64];
|
|
} Sha1Context;
|
|
|
|
#define SHA1_HASH_SIZE ( 160 / 8 )
|
|
|
|
typedef struct
|
|
{
|
|
uint8_t bytes [SHA1_HASH_SIZE];
|
|
} SHA1_HASH;
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// PUBLIC FUNCTIONS
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Sha1Initialise
|
|
//
|
|
// Initialises an SHA1 Context. Use this to initialise/reset a context.
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void
|
|
Sha1Initialise
|
|
(
|
|
Sha1Context* Context
|
|
);
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Sha1Update
|
|
//
|
|
// Adds data to the SHA1 context. This will process the data and update the internal state of the context. Keep on
|
|
// calling this function until all the data has been added. Then call Sha1Finalise to calculate the hash.
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void
|
|
Sha1Update
|
|
(
|
|
Sha1Context* Context,
|
|
void* Buffer,
|
|
uint32_t BufferSize
|
|
);
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Sha1Finalise
|
|
//
|
|
// Performs the final calculation of the hash and returns the digest (20 byte buffer containing 160bit hash). After
|
|
// calling this, Sha1Initialised must be used to reuse the context.
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void
|
|
Sha1Finalise
|
|
(
|
|
Sha1Context* Context,
|
|
SHA1_HASH* Digest
|
|
);
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
#endif //_sha1_h_
|