mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-28 18:30:06 +00:00
Merge branch 'master' of https://github.com/odin-lang/Odin
This commit is contained in:
@@ -9,6 +9,7 @@ package poly1305
|
||||
import "core:crypto"
|
||||
import field "core:crypto/_fiat/field_poly1305"
|
||||
import "core:encoding/endian"
|
||||
import "core:math/bits"
|
||||
import "core:mem"
|
||||
|
||||
// KEY_SIZE is the Poly1305 key size in bytes.
|
||||
@@ -50,7 +51,7 @@ verify :: proc(tag, msg, key: []byte) -> bool {
|
||||
Context :: struct {
|
||||
_r: field.Tight_Field_Element,
|
||||
_a: field.Tight_Field_Element,
|
||||
_s: field.Tight_Field_Element,
|
||||
_s: [2]u64,
|
||||
_buffer: [_BLOCK_SIZE]byte,
|
||||
_leftover: int,
|
||||
_is_initialized: bool,
|
||||
@@ -66,11 +67,12 @@ init :: proc(ctx: ^Context, key: []byte) {
|
||||
// r = le_bytes_to_num(key[0..15])
|
||||
// r = clamp(r) (r &= 0xffffffc0ffffffc0ffffffc0fffffff)
|
||||
tmp_lo := endian.unchecked_get_u64le(key[0:]) & 0x0ffffffc0fffffff
|
||||
tmp_hi := endian.unchecked_get_u64le(key[8:]) & 0xffffffc0ffffffc
|
||||
tmp_hi := endian.unchecked_get_u64le(key[8:]) & 0x0ffffffc0ffffffc
|
||||
field.fe_from_u64s(&ctx._r, tmp_lo, tmp_hi)
|
||||
|
||||
// s = le_bytes_to_num(key[16..31])
|
||||
field.fe_from_bytes(&ctx._s, key[16:32], 0)
|
||||
ctx._s[0] = endian.unchecked_get_u64le(key[16:])
|
||||
ctx._s[1] = endian.unchecked_get_u64le(key[24:])
|
||||
|
||||
// a = 0
|
||||
field.fe_zero(&ctx._a)
|
||||
@@ -138,14 +140,20 @@ final :: proc(ctx: ^Context, dst: []byte) {
|
||||
_blocks(ctx, ctx._buffer[:], true)
|
||||
}
|
||||
|
||||
// a += s
|
||||
field.fe_add(field.fe_relax_cast(&ctx._a), &ctx._a, &ctx._s) // _a unreduced
|
||||
field.fe_carry(&ctx._a, field.fe_relax_cast(&ctx._a)) // _a reduced
|
||||
|
||||
// return num_to_16_le_bytes(a)
|
||||
// a += s (NOT mod p)
|
||||
tmp: [32]byte = ---
|
||||
field.fe_to_bytes(&tmp, &ctx._a)
|
||||
copy_slice(dst, tmp[0:16])
|
||||
|
||||
c: u64
|
||||
lo := endian.unchecked_get_u64le(tmp[0:])
|
||||
hi := endian.unchecked_get_u64le(tmp[8:])
|
||||
|
||||
lo, c = bits.add_u64(lo, ctx._s[0], 0)
|
||||
hi, _ = bits.add_u64(hi, ctx._s[1], c)
|
||||
|
||||
// return num_to_16_le_bytes(a)
|
||||
endian.unchecked_put_u64le(dst[0:], lo)
|
||||
endian.unchecked_put_u64le(dst[8:], hi)
|
||||
}
|
||||
|
||||
// reset sanitizes the Context. The Context must be re-initialized to
|
||||
|
||||
@@ -39,7 +39,6 @@ init_from_f64 :: proc(x: ^$T/Fixed($Backing, $Fraction_Width), val: f64) {
|
||||
}
|
||||
|
||||
init_from_parts :: proc(x: ^$T/Fixed($Backing, $Fraction_Width), integer, fraction: Backing) {
|
||||
i, f := math.modf(val)
|
||||
x.i = fraction
|
||||
x.i &= 1<<Fraction_Width - 1
|
||||
x.i |= integer
|
||||
|
||||
@@ -324,6 +324,7 @@ foreign kernel32 {
|
||||
lpName: LPCWSTR,
|
||||
) -> HANDLE ---
|
||||
ResetEvent :: proc(hEvent: HANDLE) -> BOOL ---
|
||||
SetEvent :: proc(hEvent: HANDLE) -> BOOL ---
|
||||
WaitForMultipleObjects :: proc(
|
||||
nCount: DWORD,
|
||||
lpHandles: ^HANDLE,
|
||||
@@ -545,6 +546,10 @@ FILE_MAP_RESERVE :: DWORD(0x80000000)
|
||||
FILE_MAP_TARGETS_INVALID :: DWORD(0x40000000)
|
||||
FILE_MAP_LARGE_PAGES :: DWORD(0x20000000)
|
||||
|
||||
// Flags for `SetFileCompletionNotificationModes`.
|
||||
FILE_SKIP_COMPLETION_PORT_ON_SUCCESS :: 0x1
|
||||
FILE_SKIP_SET_EVENT_ON_HANDLE :: 0x2
|
||||
|
||||
PAGE_NOACCESS :: 0x01
|
||||
PAGE_READONLY :: 0x02
|
||||
PAGE_READWRITE :: 0x04
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
package sys_windows
|
||||
|
||||
// Define flags to be used with the WSAAsyncSelect() call.
|
||||
FD_READ :: 0x01
|
||||
FD_WRITE :: 0x02
|
||||
FD_OOB :: 0x04
|
||||
FD_ACCEPT :: 0x08
|
||||
FD_CONNECT :: 0x10
|
||||
FD_CLOSE :: 0x20
|
||||
FD_READ :: 0x01
|
||||
FD_WRITE :: 0x02
|
||||
FD_OOB :: 0x04
|
||||
FD_ACCEPT :: 0x08
|
||||
FD_CONNECT :: 0x10
|
||||
FD_CLOSE :: 0x20
|
||||
FD_MAX_EVENTS :: 10
|
||||
|
||||
INADDR_LOOPBACK :: 0x7f000001
|
||||
@@ -24,10 +24,10 @@ POLLERR :: 0x0001
|
||||
POLLHUP :: 0x0002
|
||||
POLLNVAL :: 0x0004
|
||||
|
||||
WSA_POLLFD::struct{
|
||||
fd:SOCKET,
|
||||
events:c_short,
|
||||
revents:c_short,
|
||||
WSA_POLLFD :: struct{
|
||||
fd: SOCKET,
|
||||
events: c_short,
|
||||
revents: c_short,
|
||||
}
|
||||
|
||||
WSANETWORKEVENTS :: struct {
|
||||
@@ -37,16 +37,43 @@ WSANETWORKEVENTS :: struct {
|
||||
|
||||
WSAEVENT :: HANDLE
|
||||
|
||||
WSAID_ACCEPTEX :: GUID{0xb5367df1, 0xcbac, 0x11cf, {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}}
|
||||
WSAID_ACCEPTEX :: GUID{0xb5367df1, 0xcbac, 0x11cf, {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}}
|
||||
WSAID_GETACCEPTEXSOCKADDRS :: GUID{0xb5367df2, 0xcbac, 0x11cf, {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}}
|
||||
WSAID_CONNECTX :: GUID{0x25a207b9, 0xddf3, 0x4660, {0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e}}
|
||||
|
||||
SIO_GET_EXTENSION_FUNCTION_POINTER :: IOC_INOUT | IOC_WS2 | 6
|
||||
IOC_OUT :: 0x40000000
|
||||
IOC_IN :: 0x80000000
|
||||
|
||||
IOC_OUT :: 0x40000000
|
||||
IOC_IN :: 0x80000000
|
||||
IOC_INOUT :: (IOC_IN | IOC_OUT)
|
||||
IOC_WS2 :: 0x08000000
|
||||
IOC_WS2 :: 0x08000000
|
||||
|
||||
SO_UPDATE_ACCEPT_CONTEXT :: 28683
|
||||
|
||||
LPFN_CONNECTEX :: #type proc "system" (
|
||||
s: SOCKET,
|
||||
sockaddr: ^SOCKADDR_STORAGE_LH,
|
||||
namelen: c_int,
|
||||
lpSendBuffer: PVOID,
|
||||
dwSendDataLength: DWORD,
|
||||
lpdwBytesSent: LPDWORD,
|
||||
lpOverlapped: LPOVERLAPPED,
|
||||
) -> BOOL
|
||||
|
||||
LPFN_ACCEPTEX :: #type proc "system" (
|
||||
sListenSocket: SOCKET,
|
||||
sAcceptSocket: SOCKET,
|
||||
lpOutputBuffer: PVOID,
|
||||
dwReceiveDataLength: DWORD,
|
||||
dwLocalAddressLength: DWORD,
|
||||
dwRemoteAddressLength: DWORD,
|
||||
lpdwBytesReceived: LPDWORD,
|
||||
lpOverlapped: LPOVERLAPPED,
|
||||
) -> BOOL
|
||||
|
||||
/*
|
||||
Example Load:
|
||||
load_accept_ex :: proc(listener: SOCKET, fn_acceptex: rawptr) {
|
||||
load_accept_ex :: proc(listener: SOCKET, fn_acceptex: ^LPFN_ACCEPTEX) {
|
||||
bytes: u32
|
||||
guid_accept_ex := WSAID_ACCEPTEX
|
||||
rc := WSAIoctl(listener, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid_accept_ex, size_of(guid_accept_ex),
|
||||
|
||||
Reference in New Issue
Block a user