- NAME
- SHA1Init, SHA1Update, SHA1Final, SHA1Transform
- SYNOPSIS
#include <sys/types.h>
#include <sha1.h>
- void SHA1Transform(
- uint32_t state[5], const unsigned char buffer[64]);
- void SHA1Init(
- SHA1_CTX * context);
- void SHA1Update(
- SHA1_CTX * context, const unsigned char *data, uint32_t len);
- void SHA1Final(
- unsigned char digest[20], SHA1_CTX * context);
- DESCRIPTION
The SHA1 functions implement the NIST Secure Hash Algorithm (SHA-1), FIPS PUB 180-1. SHA-1 is used to generate a condensed representation of a message called a message digest. The algorithm takes a message less than 2^64 bits as input and produces a 160-bit digest suitable for use as a digital signature.
The SHA1Init() function initializes a SHA1_CTX context for use with SHA1Update(), and SHA1Final(). The SHA1Update() function adds data of length len to the SHA1_CTX specified by context. SHA1Final() is called when all data has been added via SHA1Update() and stores a message digest in the digest parameter. When a null pointer is passed to SHA1Final() as first argument only the final padding will be applied and the current context can still be used with SHA1Update().
The SHA1Transform() function is used by SHA1Update() to hash 512-bit blocks and forms the core of the algorithm. Most programs should use the interface provided by SHA1Init(), SHA1Update() and SHA1Final() instead of calling SHA1Transform() directly.
- EXAMPLES
The follow code fragment will calculate the digest for the string "abc" which is ``0xa9993e36476816aba3e25717850c26c9cd0d89d''.
SHA1_CTX sha; uint8_t results[20]; char *buf; int n;
buf = "abc"; n = strlen(buf); SHA1Init(&sha); SHA1Update(&sha, (uint8_t *)buf, n); SHA1Final(results, &sha);
/* Print the digest as one long hex value */ printf("0x"); for (n = 0; n < 20; n++)
printf("%02x", results[n]);
putchar('n');
Alternately, the helper functions could be used in the following way:
SHA1_CTX sha; uint8_t output[41]; char *buf = "abc";
printf("0x%s", SHA1Data(buf, strlen(buf), output));
- AUTHORS
- This implementation of SHA-1 was written by Steve Reid.
- BUGS
This implementation of SHA-1 has not been validated by NIST and as such is not in official compliance with the standard.
If a message digest is to be copied to a multi-byte type (ie: an array of five 32-bit integers) it will be necessary to perform byte swapping on little endian machines such as the i386, alpha, and VAX.
CARVIEW |
Select Language
HTTP/2 200
date: Wed, 23 Jul 2025 22:55:58 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"3383c86214fc4179df4bcd3d47d0902c"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=Lb24x3eRQniXPrYdaQ9kzAznjlL8Jaen8kXoYgPnEL8IMxicQHHAwGsabvP3k8CHkvnNMoqwrlwMOixzxHowquwoNReWFGbL89kzbuPSaXRaYaewI4zsvXTpORjd2zOHQUbxDck%2F6aq63D5nNdLIb91Xc2cJjIszsbgYn4omtdXov4B2DDFTNH6srEonnqDcKbmXevJlyfzpiaeQUTLkh31BI43VJBilSSF3bTth8HEDXHs%2FEa9qi%2BS9fBNiAv1mF1poW%2FPFgkjNhylCculuFQ%3D%3D--WRuOCdRm0719nqXQ--RExYUAM4PJQLevvaQPTCCg%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.571865521.1753311358; Path=/; Domain=github.com; Expires=Thu, 23 Jul 2026 22:55:58 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Thu, 23 Jul 2026 22:55:58 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: E5A8:941DF:1137DDB:14A50DB:6881687E
GitHub - clibs/sha1: sha1 hash alogrithm
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 85
clibs/sha1
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
You can’t perform that action at this time.