mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-30 19:22:25 -05:00 
			
		
		
		
	# Description ## Checklist Please put an x inside each checkbox to indicate that you've read and followed it: `[ ]` -> `[x]` If this is a documentation change, only the first checkbox must be filled (you can delete the others if you want). - [x] I/we have read the [GoToSocial contribution guidelines](https://codeberg.org/superseriousbusiness/gotosocial/src/branch/main/CONTRIBUTING.md). - [ ] I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat. - [x] I/we have not leveraged AI to create the proposed changes. - [ ] I/we have performed a self-review of added code. - [ ] I/we have written code that is legible and maintainable by others. - [ ] I/we have commented the added code, particularly in hard-to-understand areas. - [ ] I/we have made any necessary changes to documentation. - [ ] I/we have added tests that cover new code. - [ ] I/we have run tests and they pass locally with the changes. - [ ] I/we have run `go fmt ./...` and `golangci-lint run`. Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4255 Co-authored-by: Daenney <daenney@noreply.codeberg.org> Co-committed-by: Daenney <daenney@noreply.codeberg.org>
		
			
				
	
	
		
			68 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			68 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2012 The Go Authors. All rights reserved.
 | |
| // Use of this source code is governed by a BSD-style
 | |
| // license that can be found in the LICENSE file.
 | |
| 
 | |
| package ssh
 | |
| 
 | |
| // Message authentication support
 | |
| 
 | |
| import (
 | |
| 	"crypto/hmac"
 | |
| 	"crypto/sha1"
 | |
| 	"crypto/sha256"
 | |
| 	"crypto/sha512"
 | |
| 	"hash"
 | |
| )
 | |
| 
 | |
| type macMode struct {
 | |
| 	keySize int
 | |
| 	etm     bool
 | |
| 	new     func(key []byte) hash.Hash
 | |
| }
 | |
| 
 | |
| // truncatingMAC wraps around a hash.Hash and truncates the output digest to
 | |
| // a given size.
 | |
| type truncatingMAC struct {
 | |
| 	length int
 | |
| 	hmac   hash.Hash
 | |
| }
 | |
| 
 | |
| func (t truncatingMAC) Write(data []byte) (int, error) {
 | |
| 	return t.hmac.Write(data)
 | |
| }
 | |
| 
 | |
| func (t truncatingMAC) Sum(in []byte) []byte {
 | |
| 	out := t.hmac.Sum(in)
 | |
| 	return out[:len(in)+t.length]
 | |
| }
 | |
| 
 | |
| func (t truncatingMAC) Reset() {
 | |
| 	t.hmac.Reset()
 | |
| }
 | |
| 
 | |
| func (t truncatingMAC) Size() int {
 | |
| 	return t.length
 | |
| }
 | |
| 
 | |
| func (t truncatingMAC) BlockSize() int { return t.hmac.BlockSize() }
 | |
| 
 | |
| var macModes = map[string]*macMode{
 | |
| 	HMACSHA512ETM: {64, true, func(key []byte) hash.Hash {
 | |
| 		return hmac.New(sha512.New, key)
 | |
| 	}},
 | |
| 	HMACSHA256ETM: {32, true, func(key []byte) hash.Hash {
 | |
| 		return hmac.New(sha256.New, key)
 | |
| 	}},
 | |
| 	HMACSHA512: {64, false, func(key []byte) hash.Hash {
 | |
| 		return hmac.New(sha512.New, key)
 | |
| 	}},
 | |
| 	HMACSHA256: {32, false, func(key []byte) hash.Hash {
 | |
| 		return hmac.New(sha256.New, key)
 | |
| 	}},
 | |
| 	HMACSHA1: {20, false, func(key []byte) hash.Hash {
 | |
| 		return hmac.New(sha1.New, key)
 | |
| 	}},
 | |
| 	InsecureHMACSHA196: {20, false, func(key []byte) hash.Hash {
 | |
| 		return truncatingMAC{12, hmac.New(sha1.New, key)}
 | |
| 	}},
 | |
| }
 |