crypto-algorithms.c

Basic implementations of standard cryptography algorithms, like AES and SHA-1
git clone git://git.finwo.net/lib/crypto-algorithms.c
Log | Files | Refs | README

commit 87712589d0ed8508d5c32f496ba9075f1f3c93d2
parent 917c813c88a5d33f47e68cba0affcbc5aa761841
Author: finwo <finwo@pm.me>
Date:   Wed, 23 Sep 2026 23:51:46 +0200

Update fragile typedefs to stdints

Diffstat:
Maes.h | 7++++---
Marcfour.h | 3++-
Mbase64.h | 3++-
Mblowfish.h | 5+++--
Mdes.h | 5+++--
Mmd2.h | 3++-
Mmd5.h | 5+++--
Msha1.h | 5+++--
8 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/aes.h b/aes.h @@ -10,14 +10,15 @@ #define AES_H /*************************** HEADER FILES ***************************/ -#include <stddef.h> +#include <stddef.h> +#include <stdint.h> /****************************** MACROS ******************************/ #define AES_BLOCK_SIZE 16 // AES operates on 16 bytes at a time /**************************** DATA TYPES ****************************/ -typedef unsigned char BYTE; // 8-bit byte -typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines +typedef uint8_t BYTE; // 8-bit byte +typedef uint32_t WORD; // 32-bit word /*********************** FUNCTION DECLARATIONS **********************/ /////////////////// diff --git a/arcfour.h b/arcfour.h @@ -11,9 +11,10 @@ /*************************** HEADER FILES ***************************/ #include <stddef.h> +#include <stdint.h> /**************************** DATA TYPES ****************************/ -typedef unsigned char BYTE; // 8-bit byte +typedef uint8_t BYTE; // 8-bit byte /*********************** FUNCTION DECLARATIONS **********************/ // Input: state - the state used to generate the keystream diff --git a/base64.h b/base64.h @@ -11,9 +11,10 @@ /*************************** HEADER FILES ***************************/ #include <stddef.h> +#include <stdint.h> /**************************** DATA TYPES ****************************/ -typedef unsigned char BYTE; // 8-bit byte +typedef uint8_t BYTE; // 8-bit byte /*********************** FUNCTION DECLARATIONS **********************/ // Returns the size of the output. If called with out = NULL, will just return diff --git a/blowfish.h b/blowfish.h @@ -11,13 +11,14 @@ /*************************** HEADER FILES ***************************/ #include <stddef.h> +#include <stdint.h> /****************************** MACROS ******************************/ #define BLOWFISH_BLOCK_SIZE 8 // Blowfish operates on 8 bytes at a time /**************************** DATA TYPES ****************************/ -typedef unsigned char BYTE; // 8-bit byte -typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines +typedef uint8_t BYTE; // 8-bit byte +typedef uint32_t WORD; // 32-bit word typedef struct { WORD p[18]; diff --git a/des.h b/des.h @@ -14,13 +14,14 @@ /*************************** HEADER FILES ***************************/ #include <stddef.h> +#include <stdint.h> /****************************** MACROS ******************************/ #define DES_BLOCK_SIZE 8 // DES operates on 8 bytes at a time /**************************** DATA TYPES ****************************/ -typedef unsigned char BYTE; // 8-bit byte -typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines +typedef uint8_t BYTE; // 8-bit byte +typedef uint32_t WORD; // 32-bit word typedef enum { DES_ENCRYPT, diff --git a/md2.h b/md2.h @@ -11,12 +11,13 @@ /*************************** HEADER FILES ***************************/ #include <stddef.h> +#include <stdint.h> /****************************** MACROS ******************************/ #define MD2_BLOCK_SIZE 16 /**************************** DATA TYPES ****************************/ -typedef unsigned char BYTE; // 8-bit byte +typedef uint8_t BYTE; // 8-bit byte typedef struct { BYTE data[16]; diff --git a/md5.h b/md5.h @@ -11,13 +11,14 @@ /*************************** HEADER FILES ***************************/ #include <stddef.h> +#include <stdint.h> /****************************** MACROS ******************************/ #define MD5_BLOCK_SIZE 16 // MD5 outputs a 16 byte digest /**************************** DATA TYPES ****************************/ -typedef unsigned char BYTE; // 8-bit byte -typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines +typedef uint8_t BYTE; // 8-bit byte +typedef uint32_t WORD; // 32-bit word typedef struct { BYTE data[64]; diff --git a/sha1.h b/sha1.h @@ -11,13 +11,14 @@ /*************************** HEADER FILES ***************************/ #include <stddef.h> +#include <stdint.h> /****************************** MACROS ******************************/ #define SHA1_BLOCK_SIZE 20 // SHA1 outputs a 20 byte digest /**************************** DATA TYPES ****************************/ -typedef unsigned char BYTE; // 8-bit byte -typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines +typedef uint8_t BYTE; // 8-bit byte +typedef uint32_t WORD; // 32-bit word typedef struct { BYTE data[64];