1 /// Implementation of SHA digesters. 2 module tern.digest.sha; 3 4 import tern.digest; 5 6 /** 7 * Implementation of Secure Hash Algorithm (SHA) digester. 8 * 9 * SHA is a family of cryptographic hash functions used to generate a fixed-size hash value from 10 * input data of variable length. The SHA family includes variants such as SHA-1, SHA-256, SHA-512, 11 * SHA-224, and SHA-384, each with different bit lengths. 12 * 13 * Example: 14 * ```d 15 * import tern.digest.sha; 16 * 17 * ubyte[] data = [1, 2, 3, 4, 5]; 18 * auto sha1Hash = SHA1.hash(data); 19 * ``` 20 */ 21 public static @digester class SHA1 22 { 23 public: 24 static: 25 pure: 26 /** 27 * Computes the SHA-1 hash of the given byte array `data`. 28 * 29 * Params: 30 * data = Input byte array to compute the hash. 31 * 32 * Returns: 33 * SHA-1 hash value as a byte array. 34 */ 35 auto hash(ubyte[] data) 36 { 37 import std.digest; 38 import std.digest.sha; 39 return digest!(std.digest.sha.SHA1)(data); 40 } 41 } 42 43 /** 44 * Implementation of Secure Hash Algorithm (SHA) digester. 45 * 46 * SHA is a family of cryptographic hash functions used to generate a fixed-size hash value from 47 * input data of variable length. The SHA family includes variants such as SHA-1, SHA-256, SHA-512, 48 * SHA-224, and SHA-384, each with different bit lengths. 49 * 50 * Example: 51 * ```d 52 * import tern.digest.sha; 53 * 54 * ubyte[] data = [1, 2, 3, 4, 5]; 55 * auto sha256Hash = SHA256.hash(data); 56 * ``` 57 */ 58 public static @digester class SHA256 59 { 60 public: 61 static: 62 pure: 63 /** 64 * Computes the SHA-256 hash of the given byte array `data`. 65 * 66 * Params: 67 * data = Input byte array to compute the hash. 68 * 69 * Returns: 70 * SHA-256 hash value as a byte array. 71 */ 72 auto hash(ubyte[] data) 73 { 74 import std.digest; 75 import std.digest.sha; 76 return digest!(std.digest.sha.SHA256)(data); 77 } 78 } 79 80 /** 81 * Implementation of Secure Hash Algorithm (SHA) digester. 82 * 83 * SHA is a family of cryptographic hash functions used to generate a fixed-size hash value from 84 * input data of variable length. The SHA family includes variants such as SHA-1, SHA-256, SHA-512, 85 * SHA-224, and SHA-384, each with different bit lengths. 86 * 87 * Example: 88 * ```d 89 * import tern.digest.sha; 90 * 91 * ubyte[] data = [1, 2, 3, 4, 5]; 92 * auto sha512Hash = SHA512.hash(data); 93 * ``` 94 */ 95 public static @digester class SHA512 96 { 97 public: 98 static: 99 pure: 100 /** 101 * Computes the SHA-512 hash of the given byte array `data`. 102 * 103 * Params: 104 * data = Input byte array to compute the hash. 105 * 106 * Returns: 107 * SHA-512 hash value as a byte array. 108 */ 109 auto hash(ubyte[] data) 110 { 111 import std.digest; 112 import std.digest.sha; 113 return digest!(std.digest.sha.SHA512)(data); 114 } 115 } 116 117 /** 118 * Implementation of Secure Hash Algorithm (SHA) digester. 119 * 120 * SHA is a family of cryptographic hash functions used to generate a fixed-size hash value from 121 * input data of variable length. The SHA family includes variants such as SHA-1, SHA-256, SHA-512, 122 * SHA-224, and SHA-384, each with different bit lengths. 123 * 124 * Example: 125 * ```d 126 * import tern.digest.sha; 127 * 128 * ubyte[] data = [1, 2, 3, 4, 5]; 129 * auto sha224Hash = SHA224.hash(data); 130 * ``` 131 */ 132 public static @digester class SHA224 133 { 134 public: 135 static: 136 pure: 137 /** 138 * Computes the SHA-224 hash of the given byte array `data`. 139 * 140 * Params: 141 * data = Input byte array to compute the hash. 142 * 143 * Returns: 144 * SHA-224 hash value as a byte array. 145 */ 146 auto hash(ubyte[] data) 147 { 148 import std.digest; 149 import std.digest.sha; 150 return digest!(std.digest.sha.SHA224)(data); 151 } 152 } 153 154 /** 155 * Implementation of Secure Hash Algorithm (SHA) digester. 156 * 157 * SHA is a family of cryptographic hash functions used to generate a fixed-size hash value from 158 * input data of variable length. The SHA family includes variants such as SHA-1, SHA-256, SHA-512, 159 * SHA-224, and SHA-384, each with different bit lengths. 160 * 161 * Example: 162 * ```d 163 * import tern.digest.sha; 164 * 165 * ubyte[] data = [1, 2, 3, 4, 5]; 166 * auto sha384Hash = SHA384.hash(data); 167 * ``` 168 */ 169 public static @digester class SHA384 170 { 171 public: 172 static: 173 pure: 174 /** 175 * Computes the SHA-384 hash of the given byte array `data`. 176 * 177 * Params: 178 * data = Input byte array to compute the hash. 179 * 180 * Returns: 181 * SHA-384 hash value as a byte array. 182 */ 183 auto hash(ubyte[] data) 184 { 185 import std.digest; 186 import std.digest.sha; 187 return digest!(std.digest.sha.SHA384)(data); 188 } 189 }