commit inicial do projeto

This commit is contained in:
Júnior
2025-05-23 10:44:32 -03:00
commit 8f04473c0b
106 changed files with 5673 additions and 0 deletions

21
internal/crypto/crypto.go Normal file
View File

@ -0,0 +1,21 @@
package crypto
import (
"crypto/ed25519"
"crypto/sha256"
"encoding/hex"
"encoding/json"
)
// GenerateHash gera um hash SHA-256 de qualquer estrutura
func GenerateHash(v interface{}) string {
b, _ := json.Marshal(v)
h := sha256.Sum256(b)
return hex.EncodeToString(h[:])
}
// SignMessage assina uma string com uma chave privada
func SignMessage(message string, privateKey ed25519.PrivateKey) string {
sig := ed25519.Sign(privateKey, []byte(message))
return hex.EncodeToString(sig)
}

7
internal/crypto/keys.go Normal file
View File

@ -0,0 +1,7 @@
package crypto
import "crypto/ecdsa"
// GlobalPrivateKey é usada temporariamente como referência global para testes e simulações.
// Em produção, isso deve ser gerenciado de forma segura.
var GlobalPrivateKey *ecdsa.PrivateKey

View File

@ -0,0 +1,26 @@
package crypto
import "fmt"
// PQSigner é um placeholder para um algoritmo de assinatura pós-quântico (ex: Dilithium, Falcon)
type PQSigner struct{}
func (s *PQSigner) GenerateKeys() (string, string, error) {
return "", "", fmt.Errorf("PQSigner ainda não implementado")
}
func (s *PQSigner) Sign(message, privKey string) (string, error) {
return "", fmt.Errorf("PQSigner ainda não implementado")
}
func (s *PQSigner) Verify(message, signature, pubKey string) bool {
return false
}
func (s *PQSigner) Name() string {
return "pq"
}
func init() {
Register(&PQSigner{})
}

27
internal/crypto/signer.go Normal file
View File

@ -0,0 +1,27 @@
package crypto
import "errors"
// Signer representa qualquer esquema de assinatura digital
// (ex: ECDSA, pós-quântico, etc)
type Signer interface {
GenerateKeys() (privKey string, pubKey string, err error)
Sign(message, privKey string) (string, error)
Verify(message, signature, pubKey string) bool
Name() string
}
var registered = make(map[string]Signer)
// Register um novo esquema de assinatura
func Register(signer Signer) {
registered[signer.Name()] = signer
}
// Get retorna o esquema de assinatura por nome
func Get(name string) (Signer, error) {
if s, ok := registered[name]; ok {
return s, nil
}
return nil, errors.New("assinador não encontrado")
}