Rizin
unix-like reverse engineering framework and cli tools
sha1.h File Reference
#include <rz_types.h>

Go to the source code of this file.

Classes

struct  sha1_context_t
 

Macros

#define RZ_HASH_SHA1_DIGEST_SIZE   0x14
 
#define RZ_HASH_SHA1_BLOCK_LENGTH   0x40
 

Typedefs

typedef struct sha1_context_t RzSHA1
 

Functions

void rz_sha1_init (RzSHA1 *context)
 
bool rz_sha1_update (RzSHA1 *context, const ut8 *data, ut64 length)
 
void rz_sha1_fini (ut8 *hash, RzSHA1 *context)
 

Macro Definition Documentation

◆ RZ_HASH_SHA1_BLOCK_LENGTH

#define RZ_HASH_SHA1_BLOCK_LENGTH   0x40

Definition at line 10 of file sha1.h.

◆ RZ_HASH_SHA1_DIGEST_SIZE

#define RZ_HASH_SHA1_DIGEST_SIZE   0x14

Definition at line 9 of file sha1.h.

Typedef Documentation

◆ RzSHA1

typedef struct sha1_context_t RzSHA1

Function Documentation

◆ rz_sha1_fini()

void rz_sha1_fini ( ut8 hash,
RzSHA1 context 
)

Definition at line 137 of file sha1.c.

137  {
138  rz_return_if_fail(context && hash);
139 
141 
142  for (ut32 t = 0; t < 5; ++t) {
143  rz_write_at_be32(hash, context->digest[t], t * 4);
144  }
145 }
uint32_t ut32
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
static void rz_write_at_be32(void *dest, ut32 val, size_t offset)
Definition: rz_endian.h:103
void sha1_padding(RzSHA1 *context)
Definition: sha1.c:112

References rz_return_if_fail, rz_write_at_be32(), and sha1_padding().

Referenced by plugin_sha1_final(), and plugin_sha1_small_block().

◆ rz_sha1_init()

void rz_sha1_init ( RzSHA1 context)

Definition at line 9 of file sha1.c.

9  {
11 
12  context->digest[0] = 0x67452301;
13  context->digest[1] = 0xEFCDAB89;
14  context->digest[2] = 0x98BADCFE;
15  context->digest[3] = 0x10325476;
16  context->digest[4] = 0xC3D2E1F0;
17  context->index = 0;
18  context->len_high = 0;
19  context->len_low = 0;
20 }

References rz_return_if_fail.

Referenced by plugin_sha1_init(), and plugin_sha1_small_block().

◆ rz_sha1_update()

bool rz_sha1_update ( RzSHA1 context,
const ut8 data,
ut64  length 
)

Definition at line 88 of file sha1.c.

88  {
89  rz_return_val_if_fail(context && data, false);
90  for (ut64 i = 0; i < length; ++i) {
91  context->block[context->index++] = data[i];
92 
93  context->len_low += 8;
94  if (context->len_low > 0xFFFFFFFFull) {
95  context->len_low &= 0xFFFFFFFFull;
96  context->len_high++;
97  // check if digested data overflows UT64
98  if (context->len_high > 0xFFFFFFFFull) {
99  return false;
100  }
101  }
102 
103  // digest only 512 bit blocks
104  if (context->index == RZ_HASH_SHA1_BLOCK_LENGTH) {
106  }
107  }
108 
109  return true;
110 }
lzma_index ** i
Definition: index.h:629
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
static void sha1_digest_block(RzSHA1 *context)
Definition: sha1.c:26
#define RZ_HASH_SHA1_BLOCK_LENGTH
Definition: sha1.h:10
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References i, length, RZ_HASH_SHA1_BLOCK_LENGTH, rz_return_val_if_fail, sha1_digest_block(), and ut64().

Referenced by plugin_sha1_small_block(), and plugin_sha1_update().