mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
e044fcf359
The rewrite's plan and decisions are in revamp.md. Steps 0 to 10 are done: the workspace and checks, bakashrot-proto, bakashrot-pki and bakashrot-cert, bakashrot-config, bakashrot-storage (schema v9), the server and the client library (every request but replication's, attachments and retention included), the C DLL with its C, PureBasic and Python bindings, and the bakashrot tool. Step 11 (replication) is next. OldSource/ is the old implementation, kept building and passing as the reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RwFeVTGs2SsufaH6zquzcb
69 lines
2.0 KiB
Plaintext
69 lines
2.0 KiB
Plaintext
;{- Code Header
|
|
; ==- Basic Info -================================
|
|
; Name: BakaShrotGenerateKeyPairs.pb
|
|
; Version: 0.0.1
|
|
; Author: Herwin Bozet (NibblePoker)
|
|
;
|
|
; ==- Compatibility -=============================
|
|
; Tested compiler versions:
|
|
; * PureBasic 5.73 LTS (Windows x64, Linux x64)
|
|
; * PureBasic 6.40 C Backend (Windows x64)
|
|
; * PureBasic 6.41 (Linux x64)
|
|
; * PureBasic 6.41 C Backend (Linux x64)
|
|
;
|
|
; ==- Links -=====================================
|
|
; GitHub: https://github.com/aziascreations/BakaShrot
|
|
;}
|
|
|
|
; ============================================================================
|
|
; BakaShrotGenerateKeyPairs
|
|
;
|
|
; Generates a new Ed25519 keypair and prints it as two ini-style lines:
|
|
; PrivateKey = <Base64>
|
|
; PublicKey = <Base64>
|
|
;
|
|
; The private key goes in the node's own [BakaShrot] PrivateKey, the public
|
|
; key goes in the configs of whoever needs to trust that node.
|
|
;
|
|
; Compile as a console program, exits with 0 on success, 1 on failure.
|
|
; ============================================================================
|
|
|
|
EnableExplicit
|
|
|
|
XIncludeFile "../Common/ToolConsole.pbi"
|
|
XIncludeFile "../../Commons/Cryptography/Libsodium.pbi"
|
|
|
|
|
|
Define *PublicKey, *PrivateKey
|
|
|
|
OpenConsole()
|
|
|
|
If Not InitCryptography()
|
|
PrintN("Failed to initialize libsodium")
|
|
ToolConsole_End(1)
|
|
EndIf
|
|
|
|
*PublicKey = AllocateMemory(#BakaShrot_Ed25519_PublicKeySize)
|
|
If Not *PublicKey
|
|
PrintN("Failed to allocate the public key")
|
|
ToolConsole_End(1)
|
|
EndIf
|
|
|
|
*PrivateKey = AllocateMemory(#BakaShrot_Ed25519_PrivateKeySize)
|
|
If Not *PrivateKey
|
|
PrintN("Failed to allocate the private key")
|
|
ToolConsole_End(1)
|
|
EndIf
|
|
|
|
GenerateKeyPair(*PublicKey, *PrivateKey)
|
|
|
|
PrintN("PrivateKey = " + EncodeKeyToString(*PrivateKey, #BakaShrot_Ed25519_PrivateKeySize))
|
|
PrintN("PublicKey = " + EncodeKeyToString(*PublicKey, #BakaShrot_Ed25519_PublicKeySize))
|
|
|
|
; Don't leave the private key lying around in freed memory.
|
|
FillMemory(*PrivateKey, #BakaShrot_Ed25519_PrivateKeySize, 0)
|
|
FreeMemory(*PrivateKey)
|
|
FreeMemory(*PublicKey)
|
|
|
|
ToolConsole_End(0)
|