All Projects â†’ vikyd â†’ go-checksum

vikyd / go-checksum

Licence: MIT license
Simple tool to calc Golang module checksum of go.mod and module dir.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-checksum

Gos
Gos: Armed Golang 💊 ( solutions for go module, goproxy, cross compilation, etc.)
Stars: ✭ 369 (+720%)
Mutual labels:  module, mod
BruteForce
A simple brute forcer written in GO for SHA1, SHA256, SHA512, MD5 and bcrypt
Stars: ✭ 49 (+8.89%)
Mutual labels:  hash, sha256
Darkage
ðŸŽŪ Darkage mod for Minetest
Stars: ✭ 6 (-86.67%)
Mutual labels:  module, mod
ngx http hmac secure link module
HMAC Secure Link module for NGINX.
Stars: ✭ 47 (+4.44%)
Mutual labels:  module, hash
rust-hmac-sha256
A small, self-contained SHA256 and HMAC-SHA256 implementation.
Stars: ✭ 24 (-46.67%)
Mutual labels:  hash, sha256
note
äļ€äš›æŠ€æœŊįŽ”čŪ°
Stars: ✭ 174 (+286.67%)
Mutual labels:  module, mod
Blooddy crypto
ActionScript (AS3) library for processing binary data. This library contains MD5, SHA-1, SHA-2 ( SHA-224 Ðļ SHA-256 ), Base64, CRC32 algorithms, JSON encoder & decoder as well as PNG and JPEG encoders.
Stars: ✭ 83 (+84.44%)
Mutual labels:  base64, sha256
Digestpp
C++11 header-only message digest library
Stars: ✭ 116 (+157.78%)
Mutual labels:  hash, sha256
SHA256
A C++ SHA256 implementation.
Stars: ✭ 79 (+75.56%)
Mutual labels:  hash, sha256
nim-mod
A Nim MOD player just for fun
Stars: ✭ 40 (-11.11%)
Mutual labels:  module, mod
Nsec
A modern and easy-to-use cryptographic library for .NET Core based on libsodium
Stars: ✭ 217 (+382.22%)
Mutual labels:  hash, sha256
noble-hashes
Audited & minimal JS implementation of SHA2, SHA3, RIPEMD, BLAKE2/3, HMAC, HKDF, PBKDF2 & Scrypt
Stars: ✭ 213 (+373.33%)
Mutual labels:  hash, sha256
Gtkhash
A cross-platform desktop utility for computing message digests or checksums
Stars: ✭ 167 (+271.11%)
Mutual labels:  hash, sha256
libxm
A small XM (FastTracker II Extended Module) player library.
Stars: ✭ 94 (+108.89%)
Mutual labels:  module, mod
Merkle
Node.js module implementing Merkle tree algorithm
Stars: ✭ 123 (+173.33%)
Mutual labels:  hash, sha256
Securitydriven.inferno
✅ .NET crypto done right. Professionally audited.
Stars: ✭ 501 (+1013.33%)
Mutual labels:  base64, hash
Digestif
Simple hash algorithms in OCaml
Stars: ✭ 69 (+53.33%)
Mutual labels:  hash, sha256
Hashcobra
HashCobra Hash Cracking tool.
Stars: ✭ 96 (+113.33%)
Mutual labels:  hash, sha256
fhash
fHash - an open source files hash calculator for Windows and macOS
Stars: ✭ 222 (+393.33%)
Mutual labels:  hash, sha256
WebCrypto.swift
A small collection of cryptographic functions based on the JavaScript WebCrypto API.
Stars: ✭ 16 (-64.44%)
Mutual labels:  hash, sha256

go-checksum

Simple tool to calc Golang module checksum of go.mod and module directory.

This README also describes how Golang go.sum calc hash from file conent.

Maybe this is the missing official doc for how Golang go.sum calc hash from file conent

Usage

Example Golang Module

Clone and checkout a version

git clone https://github.com/gin-gonic/gin.git
git checkout v1.4.0

Install go-checksum

go get -u github.com/vikyd/go-checksum

Calc checksum of go.mod

go-checksum relOrAbsPathOfGinDir/go.mod

will print like:

file: /Users/viky/tmp/gin/go.mod
{
	"Hash": "b1946b355a09fedc3865073bbeb5214de686542bbeaea9e1bf83cb3a08f66b99",
	"HashBase64": "sZRrNVoJ/tw4ZQc7vrUhTeaGVCu+rqnhv4PLOgj2a5k=",
	"HashSynthesized": "396d84667dc33bc2e7f6820a3af33ef8b04efb950f1c92431fbdbfabfdeb65d3",
	"HashSynthesizedBase64": "OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM=",
	"GoCheckSum": "h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM="
}

The output hash "GoCheckSum": "h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM="

is the same as

the online checksum: github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM=

(from here)

Calc checksum of module directory

go-checksum relOrAbsPathOfGinDir github.com/gin-gonic/[email protected]
  • 1st param: module directory
    • no need to remove .git, will ignore
  • 2nd param: module prefix with version
    • necessary for dir checksum

will print like:

directory: /Users/viky/tmp/gin
{
	"HashSynthesized": "ded3280827ccee9a6ab11d29b73ff08b58a6a4da53efff7042d319f25af59824",
	"HashSynthesizedBase64": "3tMoCCfM7ppqsR0ptz/wi1impNpT7/9wQtMZ8lr1mCQ=",
	"GoCheckSum": "h1:3tMoCCfM7ppqsR0ptz/wi1impNpT7/9wQtMZ8lr1mCQ="
}

The output hash "GoCheckSum": "h1:3tMoCCfM7ppqsR0ptz/wi1impNpT7/9wQtMZ8lr1mCQ="

is the same as

the online checksum: github.com/gin-gonic/gin v1.4.0 h1:3tMoCCfM7ppqsR0ptz/wi1impNpT7/9wQtMZ8lr1mCQ=

(from here)

Explain

How go.mod checksum works?

Steps:

  • tell me the path of go.mod
  • read content from go.mod, as variable content
  • calc SHA256 hash from content, as variable hash
  • mix some string with hash, as variable mixedHash
    • hash  go.mod\n
      
    • if hash is: CDa7N
    • then mixedHash is:
    • CDa7N  go.mod\n
      
    • yeah, that's a strange string
  • calc SHA256 hash from mixedHash, as variable hashSynthesized
  • calc Base64 from hashSynthesized, as variable hashSynthesizedBase64
  • finally, in go.sum, the string is: h1:hashSynthesizedBase64, as variable GoCheckSum

How module direcory checksum works?

Steps:

  • tell me the path of module's dir and module's prefix (also named import path)
    • module's prefix is used to calc hash, as part of the content string
  • clean the dir path, to remove duplicate path seperator etc.
  • loop each file in module's dir
    • only consider file, not dir
    • find the relative path of the file (relative to module's dir)
    • join file relative path with module's prefix, as variable fileImportPath
    • example:
      • one file in gin project: gin.go
      • its module's dir: /dir01/dir02/gin
      • its absolute path: /dir01/dir02/gin/gin.go
      • its relative path: gin.go
      • final string fileImportPath: github.com/gin-gonic/[email protected]/gin.go
  • after the loop, we got a list fileImportPath of all files, as variable files
    • except files in .git
  • sort files as string in increasion order
  • then begin hash steps
  • loop sorted files
    • read content from a file of files, as variable content
    • calc SHA256 hash from content, as variable hash
    • mix some string with hash, as variable mixedHash
      • hash  fileImportPath\n
        
      • if hash is: CDa7N
      • if fileImportPath is: github.com/gin-gonic/[email protected]/gin.go
      • then mixedHash is:
      • CDa7N  github.com/gin-gonic/[email protected]/gin.go\n
        
      • yeah, that's a strange string
  • after this loop, we can get a single long string joined by all files' mixedHash, as variable mixedHashAll
  • calc SHA256 hash from mixedHashAll, as variable hashSynthesized
  • calc Base64 from hashSynthesized, as variable hashSynthesizedBase64
  • finally, in go.sum, the string is: h1:hashSynthesizedBase64, as variable GoCheckSum

Ref

Golang source code about how to calc hash for modules: https://github.com/golang/mod/blob/release-branch.go1.15/sumdb/dirhash/hash.go

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].