mirror of
				https://github.com/smaeul/u-boot.git
				synced 2025-11-04 05:50:17 +00:00 
			
		
		
		
	lib: sha256: Add support for hardware specific sha256_process
Mark sha256_process as weak to allow hardware specific implementation. Add parameter for supporting multiple blocks processing. Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
This commit is contained in:
		
							parent
							
								
									084d8e6bf9
								
							
						
					
					
						commit
						915047048f
					
				
							
								
								
									
										26
									
								
								lib/sha256.c
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								lib/sha256.c
									
									
									
									
									
								
							@ -14,6 +14,8 @@
 | 
				
			|||||||
#include <watchdog.h>
 | 
					#include <watchdog.h>
 | 
				
			||||||
#include <u-boot/sha256.h>
 | 
					#include <u-boot/sha256.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/compiler_attributes.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const uint8_t sha256_der_prefix[SHA256_DER_LEN] = {
 | 
					const uint8_t sha256_der_prefix[SHA256_DER_LEN] = {
 | 
				
			||||||
	0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
 | 
						0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
 | 
				
			||||||
	0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
 | 
						0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
 | 
				
			||||||
@ -55,7 +57,7 @@ void sha256_starts(sha256_context * ctx)
 | 
				
			|||||||
	ctx->state[7] = 0x5BE0CD19;
 | 
						ctx->state[7] = 0x5BE0CD19;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void sha256_process(sha256_context *ctx, const uint8_t data[64])
 | 
					static void sha256_process_one(sha256_context *ctx, const uint8_t data[64])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t temp1, temp2;
 | 
						uint32_t temp1, temp2;
 | 
				
			||||||
	uint32_t W[64];
 | 
						uint32_t W[64];
 | 
				
			||||||
@ -186,6 +188,18 @@ static void sha256_process(sha256_context *ctx, const uint8_t data[64])
 | 
				
			|||||||
	ctx->state[7] += H;
 | 
						ctx->state[7] += H;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					__weak void sha256_process(sha256_context *ctx, const unsigned char *data,
 | 
				
			||||||
 | 
								   unsigned int blocks)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (!blocks)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (blocks--) {
 | 
				
			||||||
 | 
							sha256_process_one(ctx, data);
 | 
				
			||||||
 | 
							data += 64;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length)
 | 
					void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t left, fill;
 | 
						uint32_t left, fill;
 | 
				
			||||||
@ -204,17 +218,15 @@ void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_t length)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (left && length >= fill) {
 | 
						if (left && length >= fill) {
 | 
				
			||||||
		memcpy((void *) (ctx->buffer + left), (void *) input, fill);
 | 
							memcpy((void *) (ctx->buffer + left), (void *) input, fill);
 | 
				
			||||||
		sha256_process(ctx, ctx->buffer);
 | 
							sha256_process(ctx, ctx->buffer, 1);
 | 
				
			||||||
		length -= fill;
 | 
							length -= fill;
 | 
				
			||||||
		input += fill;
 | 
							input += fill;
 | 
				
			||||||
		left = 0;
 | 
							left = 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while (length >= 64) {
 | 
						sha256_process(ctx, input, length / 64);
 | 
				
			||||||
		sha256_process(ctx, input);
 | 
						input += length / 64 * 64;
 | 
				
			||||||
		length -= 64;
 | 
						length = length % 64;
 | 
				
			||||||
		input += 64;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (length)
 | 
						if (length)
 | 
				
			||||||
		memcpy((void *) (ctx->buffer + left), (void *) input, length);
 | 
							memcpy((void *) (ctx->buffer + left), (void *) input, length);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user