mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Add Curve25519 method in help.txt + add new specs file (#1096)
This commit is contained in:
parent
39b0a9c03e
commit
51cd83f674
2 changed files with 48 additions and 0 deletions
32
test/tool/net/curve25519_test.lua
Normal file
32
test/tool/net/curve25519_test.lua
Normal file
|
@ -0,0 +1,32 @@
|
|||
-- Copyright 2022 Justine Alexandra Roberts Tunney
|
||||
--
|
||||
-- Permission to use, copy, modify, and/or distribute this software for
|
||||
-- any purpose with or without fee is hereby granted, provided that the
|
||||
-- above copyright notice and this permission notice appear in all copies.
|
||||
--
|
||||
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||
-- WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||
-- WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||
-- AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
-- DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
-- PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
-- TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
-- PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
local secret1 = GetRandomBytes(32)
|
||||
local public1 = Curve25519(secret1, "\9")
|
||||
local secret2 = GetRandomBytes(32)
|
||||
local public2 = Curve25519(secret2, "\9")
|
||||
local secret3 = GetRandomBytes(32)
|
||||
local public3 = Curve25519(secret3, "\9")
|
||||
|
||||
local shared_key1 = Curve25519(secret1, public2)
|
||||
local shared_key2 = Curve25519(secret2, public1)
|
||||
|
||||
local shared_key3 = Curve25519(secret2, public3)
|
||||
local shared_key4 = Curve25519(secret3, public2)
|
||||
|
||||
assert(shared_key1 == shared_key2)
|
||||
assert(shared_key1 ~= shared_key3)
|
||||
assert(shared_key2 ~= shared_key3)
|
||||
assert(shared_key4 == shared_key3)
|
|
@ -1137,6 +1137,22 @@ FUNCTIONS
|
|||
The name can be one of the following strings: MD5, SHA1, SHA224,
|
||||
SHA256, SHA384, SHA512, and BLAKE2B256.
|
||||
|
||||
Curve25519(secret:str, public_or_basepoint:str) -> str
|
||||
Returns the shared key for the specified secret and public values.
|
||||
The second argument can be either a public key or a basepoint, used
|
||||
for generating a shared or public key.
|
||||
|
||||
Here a small usage sample :
|
||||
|
||||
>: secret1 = GetRandomBytes(32)
|
||||
>: public1 = Curve25519(secret1, "\9")
|
||||
>: secret2 = GetRandomBytes(32)
|
||||
>: public2 = Curve25519(secret2, "\9")
|
||||
>: shared_key1 = Curve25519(secret1, public2)
|
||||
>: shared_key2 = Curve25519(secret2, public1)
|
||||
>: shared_key1 == shared_key2
|
||||
true
|
||||
|
||||
GetRemoteAddr() → ip:uint32,port:uint16
|
||||
Returns client ip4 address and port, e.g. 0x01020304,31337 would
|
||||
represent 1.2.3.4:31337. This is the same as GetClientAddr except
|
||||
|
|
Loading…
Reference in a new issue