From b33af62270e0afdde1dda082f00cd94ccb2fdc53 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Wed, 11 Jan 2023 18:42:24 +0100 Subject: [PATCH 01/66] DTLS support --- webrtc/dtls.nim | 211 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 webrtc/dtls.nim diff --git a/webrtc/dtls.nim b/webrtc/dtls.nim new file mode 100644 index 0000000..2a1f8e5 --- /dev/null +++ b/webrtc/dtls.nim @@ -0,0 +1,211 @@ +# Nim-WebRTC +# Copyright (c) 2023 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +# * MIT license ([LICENSE-MIT](LICENSE-MIT)) +# at your option. +# This file may not be copied, modified, or distributed except according to +# those terms. + +import std/[openssl, os] +import posix +import chronos, chronicles +import stew/byteutils + +export chronicles + +logScope: + topics = "webrtc dtls" + +# Missing openssl procs things +const + BIO_NOCLOSE = 0x0 + #BIO_CLOSE = 0x1 + BIO_CTRL_DGRAM_SET_CONNECTED = 32 + BIO_C_SET_FD = 104 + +proc DTLS_client_method(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} +proc DTLS_server_method(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} +proc BIO_new_dgram(fd: SocketHandle, closeFlag: int): BIO {.cdecl, dynlib: DLLUtilName, importc.} +proc DTLSv1_listen(ssl: SslPtr, peer: ptr): int {.cdecl, dynlib: DLLSSLName, importc.} +proc SSL_CTX_set_cookie_generate_cb(ctx: SslCtx, cb: proc (ssl: SslPtr, cookie: ptr byte, cookieLen: ptr int): int {.cdecl.}) {.cdecl, dynlib: DLLSSLName, importc.} +proc SSL_CTX_set_cookie_verify_cb(ctx: SslCtx, cb: proc (ssl: SslPtr, cookie: ptr byte, cookieLen: ptr int): int {.cdecl.}) {.cdecl, dynlib: DLLSSLName, importc.} +# --- openssl + +type + DtlsSocket = ref object + udp: DatagramTransport + gotData: AsyncEvent + sslCtx: SslCtx + ctxIsView: bool + ssl: SslPtr + +template wrapSslCallRes(dtlsSocket, call: untyped): untyped = + block: + var err: type(call) + while true: + err = call + if err <= 0: + let openSslErr = SSL_get_error(dtlsSocket.ssl, cint(err)) + if openSslErr == SSL_ERROR_WANT_READ: + dtlsSocket.gotData.clear() + #TODO timeouts? + await dtlsSocket.gotData.wait()#.withTimeout(1.seconds) + continue + elif openSslErr == SSL_ERROR_SYSCALL: + let err = osLastError() + if cint(err) == EAGAIN: + dtlsSocket.gotData.clear() + await dtlsSocket.gotData.wait()#.withTimeout(1.seconds) + continue + raiseTransportOsError(err) + echo ERR_error_string(culong(ERR_peek_last_error()), nil) + raise ValueError.newException("openssl error" & $openSslErr) + break + err + +template wrapSslCall(dtlsSocket, call: untyped) = + discard wrapSslCallRes(dtlsSocket, call) + +proc generateSslCookie(ssl: SslPtr, cookie: ptr byte, cookieLen: ptr int): int {.cdecl.} = + #TODO + cookieLen[] = 30 + 1 + +proc verifySslCookie(ssl: SslPtr, cookie: ptr byte, cookieLen: ptr int): int {.cdecl.} = + #TODO + 1 + +proc createDtlsSocket( + localAddress = AnyAddress, + remoteAddress = AnyAddress, + flags: set[ServerFlags] = {NoAutoRead}): DtlsSocket = + + let gotData = newAsyncEvent() + proc callback(transp: DatagramTransport, remote: TransportAddress) {.async.} = discard + proc callback2(udata: pointer) = + gotData.fire() + let datagram = newDatagramTransport( + callback, + local = localAddress, + remote = remoteAddress, + flags = flags) + addReader(datagram.fd, callback2) + return DtlsSocket(udp: datagram, gotData: gotData) + + +proc createDtlsServer*(host: TransportAddress): Future[DtlsSocket] {.async.} = + result = createDtlsSocket( + localAddress = host, + flags = {NoAutoRead, ReuseAddr} + ) + + result.sslCtx = SSL_CTX_new(DTLS_server_method()) + #TODO if we close the server with connections alive, + #they have a ref to this ctx + + #TODO handle certificates + echo SSL_CTX_use_certificate_file(result.sslCtx, "certs/server-cert.pem", SSL_FILETYPE_PEM) + echo SSL_CTX_use_PrivateKey_file(result.sslCtx, "certs/server-key.pem", SSL_FILETYPE_PEM) + SSL_CTX_set_cookie_generate_cb(result.sslCtx, generateSslCookie) + SSL_CTX_set_cookie_verify_cb(result.sslCtx, verifySslCookie) + +proc accept*(sock: DtlsSocket): Future[DtlsSocket] {.async.} = + let + ctx = sock.sslCtx + ssl = SSL_new(ctx) + bio = BIO_new_dgram(SocketHandle(sock.udp.fd), BIO_NOCLOSE) + + sslSetBio(ssl, bio, bio) + + var + clientSockAddr: Sockaddr_storage + clientAddr: TransportAddress + doAssert isNil(sock.ssl) + sock.ssl = ssl + wrapSslCall(sock, DTLSv1_listen(ssl, addr clientSockAddr)) + sock.ssl = nil + let size = + if int(clientSockAddr.ss_family) == ord(Domain.AF_INET): + sizeof(Sockaddr_in) + elif int(clientSockAddr.ss_family) == ord(Domain.AF_INET6): + sizeof(Sockaddr_in6) + elif int(clientSockAddr.ss_family) == ord(Domain.AF_UNIX): + sizeof(Sockaddr_storage) + else: doAssert(false); -1 + fromSAddr(addr clientSockAddr, SockLen(size), clientAddr) + + # create new socket + result = createDtlsSocket( + localAddress = sock.udp.localAddress, + remoteAddress = clientAddr, + flags = {NoAutoRead, ReuseAddr} + ) + + let sockHandle = SocketHandle(result.udp.fd) + doAssert BIO_ctrl(bio, BIO_C_SET_FD, 0, cast[cstring](addr sockHandle)) > 0 + doAssert BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_CONNECTED, 0, cast[cstring](addr clientSockAddr)) > 0 + + result.sslCtx = ctx + result.ssl = ssl + result.ctxIsView = true + wrapSslCall(result, SSL_accept(ssl)) + +proc connect*(address: TransportAddress): Future[DtlsSocket] {.async.} = + result = createDtlsSocket( + remoteAddress = address + ) + + let + ctx = SSL_CTX_new(DTLS_client_method()) + ssl = SSL_new(ctx) + bio = BIO_new_dgram(SocketHandle(result.udp.fd), BIO_NOCLOSE) + + #TODO handle certs + echo SSL_CTX_use_certificate_file(ctx, "certs/client-cert.pem", SSL_FILETYPE_PEM) + echo SSL_CTX_use_PrivateKey_file(ctx, "certs/client-key.pem", SSL_FILETYPE_PEM) + echo SSL_CTX_check_private_key(ctx) + + result.sslCtx = ctx + result.ssl = ssl + var slen: SockLen + var remoteSaddr: Sockaddr_storage + toSAddr(address, remoteSaddr, slen) + doAssert BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_CONNECTED, 0, cast[cstring](addr remoteSaddr)) > 0 + sslSetBio(ssl, bio, bio) + wrapSslCall(result, SSL_connect(ssl)) + +proc write*(sock: DtlsSocket, data: seq[byte]) {.async.} = + wrapSslCall(sock, SSL_write(sock.ssl, cast[cstring](addr data[0]), data.len)) + +proc read*(sock: DtlsSocket): Future[seq[byte]] {.async.} = + result = newSeq[byte](1000) + let length = wrapSslCallRes(sock, SSL_read(sock.ssl, cast[cstring](addr result[0]), result.len)) + result.setLen(length) + +proc close*(sock: DtlsSocket) {.async.} = + if not isNil(sock.ssl): + let shutdownRes = SSL_shutdown(sock.ssl) + if shutdownRes == 0: + wrapSslCall(sock, SSL_shutdown(sock.ssl)) + SSL_free(sock.ssl) + if not isNil(sock.sslCtx) and not sock.ctxIsView: + SSL_CTX_free(sock.sslCtx) + sock.udp.close() + +proc main {.async.} = + let + address = initTAddress("127.0.0.1:8090") + server = await createDtlsServer(address) + client = connect(address) + + let + servConn = await server.accept() + clientConn = await client + await clientConn.write("Hello world!".toBytes()) + echo string.fromBytes(await servConn.read()) + + await allFutures(servConn.close(), clientConn.close()) + await server.close() + +waitFor(main()) From ca02de251ae4015e0cadafe5d1fa69915981efb2 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Thu, 12 Jan 2023 10:34:06 +0100 Subject: [PATCH 02/66] handle timeout --- webrtc/dtls.nim | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/webrtc/dtls.nim b/webrtc/dtls.nim index 2a1f8e5..730dd6a 100644 --- a/webrtc/dtls.nim +++ b/webrtc/dtls.nim @@ -22,6 +22,7 @@ const BIO_NOCLOSE = 0x0 #BIO_CLOSE = 0x1 BIO_CTRL_DGRAM_SET_CONNECTED = 32 + DTLS_CTRL_GET_TIMEOUT = 73 BIO_C_SET_FD = 104 proc DTLS_client_method(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} @@ -40,6 +41,18 @@ type ctxIsView: bool ssl: SslPtr +proc waitForData(socket: DtlsSocket) {.async.} = + socket.gotData.clear() + var timeout: Timeval + if (SSL_ctrl(socket.ssl, DTLS_CTRL_GET_TIMEOUT, 0, addr timeout) == 1): + let + momentTimeout = seconds(clong(timeout.tv_sec)) + nanoseconds(timeout.tv_usec) + fut = socket.gotData.wait() + if not await fut.withTimeout(momentTimeout): + fut.cancel + else: + await socket.gotData.wait() + template wrapSslCallRes(dtlsSocket, call: untyped): untyped = block: var err: type(call) @@ -47,20 +60,17 @@ template wrapSslCallRes(dtlsSocket, call: untyped): untyped = err = call if err <= 0: let openSslErr = SSL_get_error(dtlsSocket.ssl, cint(err)) - if openSslErr == SSL_ERROR_WANT_READ: - dtlsSocket.gotData.clear() - #TODO timeouts? - await dtlsSocket.gotData.wait()#.withTimeout(1.seconds) + if openSslErr in [SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE]: + await dtlsSocket.waitForData() continue elif openSslErr == SSL_ERROR_SYSCALL: let err = osLastError() if cint(err) == EAGAIN: - dtlsSocket.gotData.clear() - await dtlsSocket.gotData.wait()#.withTimeout(1.seconds) + await dtlsSocket.waitForData() continue raiseTransportOsError(err) - echo ERR_error_string(culong(ERR_peek_last_error()), nil) - raise ValueError.newException("openssl error" & $openSslErr) + let errorMsg = ERR_error_string(culong(ERR_peek_last_error()), nil) + raise ValueError.newException("openssl error: " & $errorMsg) break err From ab4b045d774a56d4c4815b320e6f7b1ffaf23f92 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Thu, 12 Jan 2023 11:06:45 +0100 Subject: [PATCH 03/66] Add cookie --- webrtc/dtls.nim | 77 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 21 deletions(-) diff --git a/webrtc/dtls.nim b/webrtc/dtls.nim index 730dd6a..8c76d8b 100644 --- a/webrtc/dtls.nim +++ b/webrtc/dtls.nim @@ -10,7 +10,7 @@ import std/[openssl, os] import posix import chronos, chronicles -import stew/byteutils +import stew/[byteutils, ptrops] export chronicles @@ -22,15 +22,18 @@ const BIO_NOCLOSE = 0x0 #BIO_CLOSE = 0x1 BIO_CTRL_DGRAM_SET_CONNECTED = 32 + BIO_CTRL_DGRAM_GET_PEER = 46 DTLS_CTRL_GET_TIMEOUT = 73 BIO_C_SET_FD = 104 proc DTLS_client_method(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} proc DTLS_server_method(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} proc BIO_new_dgram(fd: SocketHandle, closeFlag: int): BIO {.cdecl, dynlib: DLLUtilName, importc.} +proc SSL_get_rbio(ssl: SslPtr): BIO {.cdecl, dynlib: DLLSSLName, importc.} +proc RAND_bytes(buf: pointer, length: int): int {.cdecl, dynlib: DLLSSLName, importc.} proc DTLSv1_listen(ssl: SslPtr, peer: ptr): int {.cdecl, dynlib: DLLSSLName, importc.} proc SSL_CTX_set_cookie_generate_cb(ctx: SslCtx, cb: proc (ssl: SslPtr, cookie: ptr byte, cookieLen: ptr int): int {.cdecl.}) {.cdecl, dynlib: DLLSSLName, importc.} -proc SSL_CTX_set_cookie_verify_cb(ctx: SslCtx, cb: proc (ssl: SslPtr, cookie: ptr byte, cookieLen: ptr int): int {.cdecl.}) {.cdecl, dynlib: DLLSSLName, importc.} +proc SSL_CTX_set_cookie_verify_cb(ctx: SslCtx, cb: proc (ssl: SslPtr, cookie: ptr byte, cookieLen: int): int {.cdecl.}) {.cdecl, dynlib: DLLSSLName, importc.} # --- openssl type @@ -77,14 +80,56 @@ template wrapSslCallRes(dtlsSocket, call: untyped): untyped = template wrapSslCall(dtlsSocket, call: untyped) = discard wrapSslCallRes(dtlsSocket, call) -proc generateSslCookie(ssl: SslPtr, cookie: ptr byte, cookieLen: ptr int): int {.cdecl.} = - #TODO - cookieLen[] = 30 - 1 +proc fromSAddr(storeAddr: Sockaddr_storage): TransportAddress = + let size = + if int(storeAddr.ss_family) == ord(Domain.AF_INET): + sizeof(Sockaddr_in) + elif int(storeAddr.ss_family) == ord(Domain.AF_INET6): + sizeof(Sockaddr_in6) + elif int(storeAddr.ss_family) == ord(Domain.AF_UNIX): + sizeof(Sockaddr_storage) + else: -1 + fromSAddr(addr storeAddr, SockLen(size), result) -proc verifySslCookie(ssl: SslPtr, cookie: ptr byte, cookieLen: ptr int): int {.cdecl.} = - #TODO - 1 +var cookieSecret: array[32, byte] +doAssert RAND_bytes(addr cookieSecret[0], cookieSecret.len) > 0 + +proc generateSslCookie(ssl: SslPtr, cookie: ptr byte, cookieLen: ptr int): int {.cdecl.} = + var peerSockaddr: Sockaddr_storage + if BIO_ctrl(SSL_get_rbio(ssl), BIO_CTRL_DGRAM_GET_PEER, 0, cast[cstring](addr peerSockaddr)) <= 0: + return 0 + + let transportAddress = fromSAddr(peerSockaddr) + if + HMAC(EVP_sha1(), + addr cookieSecret[0], cint(cookieSecret.len), + cast[cstring](addr transportAddress), csize_t(sizeof(TransportAddress)), + cast[cstring](cookie), cast[ptr cuint](cookieLen)) == nil: + 0 + else: + 1 + +proc verifySslCookie(ssl: SslPtr, cookie: ptr byte, cookieLen: int): int {.cdecl.} = + var peerSockaddr: Sockaddr_storage + if BIO_ctrl(SSL_get_rbio(ssl), BIO_CTRL_DGRAM_GET_PEER, 0, cast[cstring](addr peerSockaddr)) <= 0: + return 0 + + let transportAddress = fromSAddr(peerSockaddr) + var + buffer: array[1024, byte] + bufferLength: cuint + if + HMAC(EVP_sha1(), + addr cookieSecret[0], cint(cookieSecret.len), + cast[cstring](addr transportAddress), csize_t(sizeof(TransportAddress)), + cast[cstring](addr buffer[0]), addr bufferLength) == nil: + return 0 + + if bufferLength != cuint(cookieLen): return 0 + if cookie.makeOpenArray(byte, cookieLen) == buffer[0 ..< bufferLength]: + 1 + else: + 0 proc createDtlsSocket( localAddress = AnyAddress, @@ -128,22 +173,12 @@ proc accept*(sock: DtlsSocket): Future[DtlsSocket] {.async.} = sslSetBio(ssl, bio, bio) - var - clientSockAddr: Sockaddr_storage - clientAddr: TransportAddress + var clientSockAddr: Sockaddr_storage doAssert isNil(sock.ssl) sock.ssl = ssl wrapSslCall(sock, DTLSv1_listen(ssl, addr clientSockAddr)) sock.ssl = nil - let size = - if int(clientSockAddr.ss_family) == ord(Domain.AF_INET): - sizeof(Sockaddr_in) - elif int(clientSockAddr.ss_family) == ord(Domain.AF_INET6): - sizeof(Sockaddr_in6) - elif int(clientSockAddr.ss_family) == ord(Domain.AF_UNIX): - sizeof(Sockaddr_storage) - else: doAssert(false); -1 - fromSAddr(addr clientSockAddr, SockLen(size), clientAddr) + let clientAddr = fromSAddr(clientSockAddr) # create new socket result = createDtlsSocket( From 2e26deb37709724cbd4e69e97ea08af8aabdce26 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Tue, 11 Apr 2023 14:31:30 +0200 Subject: [PATCH 04/66] Stun protocol encoding / decoding --- tests/teststun.nim | 14 ++++++++ webrtc.nimble | 3 +- webrtc/stun.nim | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 tests/teststun.nim create mode 100644 webrtc/stun.nim diff --git a/tests/teststun.nim b/tests/teststun.nim new file mode 100644 index 0000000..8b5eb28 --- /dev/null +++ b/tests/teststun.nim @@ -0,0 +1,14 @@ +import ../webrtc/stun +import ./asyncunit +import binary_serialization + +suite "Stun suite": + test "Stun encoding/decoding with padding": + let msg = @[ 0x00'u8, 0x01, 0x00, 0xa4, 0x21, 0x12, 0xa4, 0x42, 0x75, 0x6a, 0x58, 0x46, 0x42, 0x58, 0x4e, 0x72, 0x6a, 0x50, 0x4d, 0x2b, 0x00, 0x06, 0x00, 0x63, 0x6c, 0x69, 0x62, 0x70, 0x32, 0x70, 0x2b, 0x77, 0x65, 0x62, 0x72, 0x74, 0x63, 0x2b, 0x76, 0x31, 0x2f, 0x62, 0x71, 0x36, 0x67, 0x69, 0x43, 0x75, 0x4a, 0x38, 0x6e, 0x78, 0x59, 0x46, 0x4a, 0x36, 0x43, 0x63, 0x67, 0x45, 0x59, 0x58, 0x58, 0x2f, 0x78, 0x51, 0x58, 0x56, 0x4c, 0x74, 0x39, 0x71, 0x7a, 0x3a, 0x6c, 0x69, 0x62, 0x70, 0x32, 0x70, 0x2b, 0x77, 0x65, 0x62, 0x72, 0x74, 0x63, 0x2b, 0x76, 0x31, 0x2f, 0x62, 0x71, 0x36, 0x67, 0x69, 0x43, 0x75, 0x4a, 0x38, 0x6e, 0x78, 0x59, 0x46, 0x4a, 0x36, 0x43, 0x63, 0x67, 0x45, 0x59, 0x58, 0x58, 0x2f, 0x78, 0x51, 0x58, 0x56, 0x4c, 0x74, 0x39, 0x71, 0x7a, 0x00, 0xc0, 0x57, 0x00, 0x04, 0x00, 0x00, 0x03, 0xe7, 0x80, 0x2a, 0x00, 0x08, 0x86, 0x63, 0xfd, 0x45, 0xa9, 0xe5, 0x4c, 0xdb, 0x00, 0x24, 0x00, 0x04, 0x6e, 0x00, 0x1e, 0xff, 0x00, 0x08, 0x00, 0x14, 0x16, 0xff, 0x70, 0x8d, 0x97, 0x0b, 0xd6, 0xa3, 0x5b, 0xac, 0x8f, 0x4c, 0x85, 0xe6, 0xa6, 0xac, 0xaa, 0x7a, 0x68, 0x27, 0x80, 0x28, 0x00, 0x04, 0x79, 0x5e, 0x03, 0xd8 ] + check msg == encode(StunMessage.decode(msg)) + + test "Error while encoding": + let msgLengthFailed = @[ 0x00'u8, 0x01, 0x00, 0xa4, 0x21, 0x12, 0xa4, 0x42, 0x75, 0x6a, 0x58, 0x46, 0x42, 0x58, 0x4e, 0x72, 0x6a, 0x50, 0x4d ] + expect AssertionDefect: discard StunMessage.decode(msgLengthFailed) + let msgAttrFailed = @[ 0x00'u8, 0x01, 0x00, 0x08, 0x21, 0x12, 0xa4, 0x42, 0x75, 0x6a, 0x58, 0x46, 0x42, 0x58, 0x4e, 0x72, 0x6a, 0x50, 0x4d, 0x2b, 0x28, 0x00, 0x05, 0x79, 0x5e, 0x03, 0xd8 ] + expect AssertionDefect: discard StunMessage.decode(msgAttrFailed) diff --git a/webrtc.nimble b/webrtc.nimble index b6d70e0..11c781d 100644 --- a/webrtc.nimble +++ b/webrtc.nimble @@ -7,4 +7,5 @@ license = "MIT" requires "nim >= 1.2.0", "chronicles >= 0.10.2", - "chronos >= 3.0.6" + "chronos >= 3.0.6", + "https://github.com/status-im/nim-binary-serialization.git" diff --git a/webrtc/stun.nim b/webrtc/stun.nim new file mode 100644 index 0000000..21e5cc6 --- /dev/null +++ b/webrtc/stun.nim @@ -0,0 +1,88 @@ +import bitops +import chronos, chronicles +import binary_serialization + +logScope: + topics = "webrtc stun" + +const + msgHeaderSize = 20 + magicCookieSeq = @[ 0x21'u8, 0x12, 0xa4, 0x42 ] + magicCookie = 0x2112a442 + +type +# Stun Attribute +# 0 1 2 3 +# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +# | Type | Length | +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +# | Value (variable) .... +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + StunAttribute* = object + attributeType*: uint16 + length* {.bin_value: it.value.len.}: uint16 + value* {.bin_len: it.length.}: seq[byte] + +proc decode(T: typedesc[StunAttribute], cnt: seq[byte]): seq[StunAttribute] = + const val = @[0, 3, 2, 1] + var padding = 0 + while padding < cnt.len(): + let attr = Binary.decode(cnt[padding ..^ 1], StunAttribute) + result.add(attr) + padding += 4 + attr.value.len() + padding += val[padding mod 4] + +proc seqAttrLen(s: seq[StunAttribute]): uint16 = + for it in s: + result = it.length + 4 + +type +# Stun Header +# 0 1 2 3 +# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +# |0 0| STUN Message Type | Message Length | +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +# | Magic Cookie | +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +# | | +# | Transaction ID (96 bits) | +# | | +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + StunMessageInner = object + msgType: uint16 + length* {.bin_value: it.content.len().}: uint16 + magicCookie: uint32 + transactionId: array[12, byte] + content* {.bin_len: it.length.}: seq[byte] + + StunMessage* = object + msgType*: uint16 + transactionId*: array[12, byte] + attributes*: seq[StunAttribute] + + Stun* = object + +proc isMessage*(T: typedesc[Stun], msg: seq[byte]): bool = + msg.len >= msgHeaderSize and msg[4..<8] == magicCookie and bitand(0xC0'u8, msg[0]) == 0'u8 + +proc decode*(T: typedesc[StunMessage], msg: seq[byte]): StunMessage = + let smi = Binary.decode(msg, StunMessageInner) + return T(msgType: smi.msgType, + transactionId: smi.transactionId, + attributes: StunAttribute.decode(smi.content)) + +proc encode*(msg: StunMessage): seq[byte] = + const val = @[0, 3, 2, 1] + var smi = StunMessageInner(msgType: msg.msgType, + magicCookie: magicCookie, + transactionId: msg.transactionId) + for attr in msg.attributes: + smi.content.add(Binary.encode(attr)) + smi.content.add(newSeq[byte](val[smi.content.len() mod 4])) + + return Binary.encode(smi) + +proc new*(T: typedesc[Stun]): T = + result = T() From 2521ed9f84fc6c59e003dad005ab765fb5585ab6 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Thu, 20 Apr 2023 16:58:52 +0200 Subject: [PATCH 05/66] Stun attributes --- tests/teststun.nim | 2 +- webrtc/stun.nim | 87 ++++++++++++++++++++++----------- webrtc/stunattributes.nim | 100 ++++++++++++++++++++++++++++++++++++++ webrtc/usrsctp.nim | 2 +- 4 files changed, 160 insertions(+), 31 deletions(-) create mode 100644 webrtc/stunattributes.nim diff --git a/tests/teststun.nim b/tests/teststun.nim index 8b5eb28..c850484 100644 --- a/tests/teststun.nim +++ b/tests/teststun.nim @@ -7,7 +7,7 @@ suite "Stun suite": let msg = @[ 0x00'u8, 0x01, 0x00, 0xa4, 0x21, 0x12, 0xa4, 0x42, 0x75, 0x6a, 0x58, 0x46, 0x42, 0x58, 0x4e, 0x72, 0x6a, 0x50, 0x4d, 0x2b, 0x00, 0x06, 0x00, 0x63, 0x6c, 0x69, 0x62, 0x70, 0x32, 0x70, 0x2b, 0x77, 0x65, 0x62, 0x72, 0x74, 0x63, 0x2b, 0x76, 0x31, 0x2f, 0x62, 0x71, 0x36, 0x67, 0x69, 0x43, 0x75, 0x4a, 0x38, 0x6e, 0x78, 0x59, 0x46, 0x4a, 0x36, 0x43, 0x63, 0x67, 0x45, 0x59, 0x58, 0x58, 0x2f, 0x78, 0x51, 0x58, 0x56, 0x4c, 0x74, 0x39, 0x71, 0x7a, 0x3a, 0x6c, 0x69, 0x62, 0x70, 0x32, 0x70, 0x2b, 0x77, 0x65, 0x62, 0x72, 0x74, 0x63, 0x2b, 0x76, 0x31, 0x2f, 0x62, 0x71, 0x36, 0x67, 0x69, 0x43, 0x75, 0x4a, 0x38, 0x6e, 0x78, 0x59, 0x46, 0x4a, 0x36, 0x43, 0x63, 0x67, 0x45, 0x59, 0x58, 0x58, 0x2f, 0x78, 0x51, 0x58, 0x56, 0x4c, 0x74, 0x39, 0x71, 0x7a, 0x00, 0xc0, 0x57, 0x00, 0x04, 0x00, 0x00, 0x03, 0xe7, 0x80, 0x2a, 0x00, 0x08, 0x86, 0x63, 0xfd, 0x45, 0xa9, 0xe5, 0x4c, 0xdb, 0x00, 0x24, 0x00, 0x04, 0x6e, 0x00, 0x1e, 0xff, 0x00, 0x08, 0x00, 0x14, 0x16, 0xff, 0x70, 0x8d, 0x97, 0x0b, 0xd6, 0xa3, 0x5b, 0xac, 0x8f, 0x4c, 0x85, 0xe6, 0xa6, 0xac, 0xaa, 0x7a, 0x68, 0x27, 0x80, 0x28, 0x00, 0x04, 0x79, 0x5e, 0x03, 0xd8 ] check msg == encode(StunMessage.decode(msg)) - test "Error while encoding": + test "Error while decoding": let msgLengthFailed = @[ 0x00'u8, 0x01, 0x00, 0xa4, 0x21, 0x12, 0xa4, 0x42, 0x75, 0x6a, 0x58, 0x46, 0x42, 0x58, 0x4e, 0x72, 0x6a, 0x50, 0x4d ] expect AssertionDefect: discard StunMessage.decode(msgLengthFailed) let msgAttrFailed = @[ 0x00'u8, 0x01, 0x00, 0x08, 0x21, 0x12, 0xa4, 0x42, 0x75, 0x6a, 0x58, 0x46, 0x42, 0x58, 0x4e, 0x72, 0x6a, 0x50, 0x4d, 0x2b, 0x28, 0x00, 0x05, 0x79, 0x5e, 0x03, 0xd8 ] diff --git a/webrtc/stun.nim b/webrtc/stun.nim index 21e5cc6..16d9a36 100644 --- a/webrtc/stun.nim +++ b/webrtc/stun.nim @@ -1,6 +1,11 @@ import bitops -import chronos, chronicles -import binary_serialization +import chronos, + chronicles, + binary_serialization, + stew/objects +import stunattributes + +export binary_serialization logScope: topics = "webrtc stun" @@ -9,34 +14,18 @@ const msgHeaderSize = 20 magicCookieSeq = @[ 0x21'u8, 0x12, 0xa4, 0x42 ] magicCookie = 0x2112a442 + BindingRequest = 0x0001'u16 + BindingResponse = 0x0101'u16 -type -# Stun Attribute -# 0 1 2 3 -# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -# | Type | Length | -# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -# | Value (variable) .... -# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - StunAttribute* = object - attributeType*: uint16 - length* {.bin_value: it.value.len.}: uint16 - value* {.bin_len: it.length.}: seq[byte] - -proc decode(T: typedesc[StunAttribute], cnt: seq[byte]): seq[StunAttribute] = +proc decode(T: typedesc[RawStunAttribute], cnt: seq[byte]): seq[RawStunAttribute] = const val = @[0, 3, 2, 1] var padding = 0 while padding < cnt.len(): - let attr = Binary.decode(cnt[padding ..^ 1], StunAttribute) + let attr = Binary.decode(cnt[padding ..^ 1], RawStunAttribute) result.add(attr) padding += 4 + attr.value.len() padding += val[padding mod 4] -proc seqAttrLen(s: seq[StunAttribute]): uint16 = - for it in s: - result = it.length + 4 - type # Stun Header # 0 1 2 3 @@ -50,32 +39,46 @@ type # | Transaction ID (96 bits) | # | | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - StunMessageInner = object +# Message type: +# 0x0001: Binding Request +# 0x0101: Binding Response +# 0x0111: Binding Error Response +# 0x0002: Shared Secret Request +# 0x0102: Shared Secret Response +# 0x0112: Shared Secret Error Response + + RawStunMessage = object msgType: uint16 length* {.bin_value: it.content.len().}: uint16 magicCookie: uint32 transactionId: array[12, byte] content* {.bin_len: it.length.}: seq[byte] - + StunMessage* = object msgType*: uint16 transactionId*: array[12, byte] - attributes*: seq[StunAttribute] + attributes*: seq[RawStunAttribute] Stun* = object +proc getAttribute(attrs: seq[RawStunAttribute], typ: uint16): Option[seq[byte]] = + for attr in attrs: + if attr.attributeType == typ: + return some(attr.value) + return none(seq[byte]) + proc isMessage*(T: typedesc[Stun], msg: seq[byte]): bool = - msg.len >= msgHeaderSize and msg[4..<8] == magicCookie and bitand(0xC0'u8, msg[0]) == 0'u8 + msg.len >= msgHeaderSize and msg[4..<8] == magicCookieSeq and bitand(0xC0'u8, msg[0]) == 0'u8 proc decode*(T: typedesc[StunMessage], msg: seq[byte]): StunMessage = - let smi = Binary.decode(msg, StunMessageInner) + let smi = Binary.decode(msg, RawStunMessage) return T(msgType: smi.msgType, transactionId: smi.transactionId, - attributes: StunAttribute.decode(smi.content)) + attributes: RawStunAttribute.decode(smi.content)) proc encode*(msg: StunMessage): seq[byte] = const val = @[0, 3, 2, 1] - var smi = StunMessageInner(msgType: msg.msgType, + var smi = RawStunMessage(msgType: msg.msgType, magicCookie: magicCookie, transactionId: msg.transactionId) for attr in msg.attributes: @@ -84,5 +87,31 @@ proc encode*(msg: StunMessage): seq[byte] = return Binary.encode(smi) +proc getResponse*(T: typedesc[Stun], msg: seq[byte], + address: TransportAddress): Option[StunMessage] = + let sm = + try: + StunMessage.decode(msg) + except CatchableError as exc: + return none(StunMessage) + + if sm.msgType != BindingRequest: + return none(StunMessage) + + var res = StunMessage(msgType: BindingResponse, + transactionId: sm.transactionId) + + var unknownAttr: seq[uint16] + for attr in sm.attributes: + let typ = attr.attributeType + if typ.isRequired() and typ notin StunAttributeEnum: + unknownAttr.add(typ) + if unknownAttr.len() > 0: + res.attributes.add(ErrorCode.encode(ECUnknownAttribute)) + res.attributes.add(UnknownAttribute.encode(unknownAttr)) + return some(res) + + #if sm.attributes.getAttribute()) + proc new*(T: typedesc[Stun]): T = result = T() diff --git a/webrtc/stunattributes.nim b/webrtc/stunattributes.nim new file mode 100644 index 0000000..fef8fc5 --- /dev/null +++ b/webrtc/stunattributes.nim @@ -0,0 +1,100 @@ +import binary_serialization, + stew/byteutils + +type +# Stun Attribute +# 0 1 2 3 +# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +# | Type | Length | +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +# | Value (variable) .... +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + RawStunAttribute* = object + attributeType*: uint16 + length* {.bin_value: it.value.len.}: uint16 + value* {.bin_len: it.length.}: seq[byte] + + StunAttributeEnum* = enum + AttrMappedAddress = 0x0001 + AttrChangeRequest = 0x0003 # RFC5780 Nat Behavior Discovery + AttrSourceAddress = 0x0004 # Deprecated + AttrChangedAddress = 0x0005 # Deprecated + AttrUsername = 0x0006 + AttrMessageIntegrity = 0x0008 + AttrErrorCode = 0x0009 + AttrUnknownAttributes = 0x000A + AttrChannelNumber = 0x000C # RFC5766 TURN + AttrLifetime = 0x000D # RFC5766 TURN + AttrXORPeerAddress = 0x0012 # RFC5766 TURN + AttrData = 0x0013 # RFC5766 TURN + AttrRealm = 0x0014 + AttrNonce = 0x0015 + AttrXORRelayedAddress = 0x0016 # RFC5766 TURN + AttrRequestedAddressFamily = 0x0017 # RFC6156 + AttrEvenPort = 0x0018 # RFC5766 TURN + AttrRequestedTransport = 0x0019 # RFC5766 TURN + AttrDontFragment = 0x001A # RFC5766 TURN + AttrMessageIntegritySHA256 = 0x001C # RFC8489 STUN (v2) + AttrPasswordAlgorithm = 0x001D # RFC8489 STUN (v2) + AttrUserhash = 0x001E # RFC8489 STUN (v2) + AttrXORMappedAddress = 0x0020 + AttrReservationToken = 0x0022 # RFC5766 TURN + AttrPriority = 0x0024 # RFC5245 ICE + AttrUseCandidate = 0x0025 # RFC5245 ICE + AttrPadding = 0x0026 # RFC5780 Nat Behavior Discovery + AttrResponsePort = 0x0027 # RFC5780 Nat Behavior Discovery + AttrConnectionID = 0x002a # RFC6062 TURN Extensions + AttrPasswordAlgorithms = 0x8002 # RFC8489 STUN (v2) + AttrAlternateDomain = 0x8003 # RFC8489 STUN (v2) + AttrSoftware = 0x8022 + AttrAlternateServer = 0x8023 + AttrCacheTimeout = 0x8027 # RFC5780 Nat Behavior Discovery + AttrFingerprint = 0x8028 + AttrICEControlled = 0x8029 # RFC5245 ICE + AttrICEControlling = 0x802A # RFC5245 ICE + AttrResponseOrigin = 0x802b # RFC5780 Nat Behavior Discovery + AttrOtherAddress = 0x802C # RFC5780 Nat Behavior Discovery + AttrOrigin = 0x802F + +proc isRequired*(typ: uint16): bool = typ <= 0x7FFF'u16 +proc isOptional*(typ: uint16): bool = typ >= 0x8000'u16 + +# Error Code +type + ErrorCodeEnum* = enum + ECTryAlternate = 300 + ECBadRequest = 400 + ECUnauthenticated = 401 + ECUnknownAttribute = 420 + ECStaleNonce = 438 + ECServerError = 500 + ErrorCode* = object + reserved1: uint16 # should be 0 + reserved2 {.bin_bitsize: 5.}: uint8 # should be 0 + class {.bin_bitsize: 3.}: uint8 + number: uint8 + reason: seq[byte] + +proc encode*(T: typedesc[ErrorCode], code: ErrorCodeEnum, reason: string = ""): RawStunAttribute = + let + ec = T(class: (code.uint16 div 100'u16).uint8, + number: (code.uint16 mod 100'u16).uint8, + reason: reason.toBytes()) + value = Binary.encode(ec) + result = RawStunAttribute(attributeType: AttrErrorCode.uint16, + length: value.len().uint16, + value: value) + +# Unknown Attribute +type + UnknownAttribute* = object + unknownAttr: seq[uint16] + +proc encode*(T: typedesc[UnknownAttribute], unknownAttr: seq[uint16]): RawStunAttribute = + let + ua = T(unknownAttr: unknownAttr) + value = Binary.encode(ua) + result = RawStunAttribute(attributeType: AttrUnknownAttributes.uint16, + length: value.len().uint16, + value: value) diff --git a/webrtc/usrsctp.nim b/webrtc/usrsctp.nim index 3aa7180..25acb33 100644 --- a/webrtc/usrsctp.nim +++ b/webrtc/usrsctp.nim @@ -9,7 +9,7 @@ const usrsctpInclude = root/"usrsctp"/"usrsctplib" {.passc: fmt"-I{usrsctpInclude}".} -# Generated @ 2022-11-23T14:21:00+01:00 +# Generated @ 2023-03-30T13:55:23+02:00 # Command line: # /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --compile=./usrsctp/usrsctplib/netinet/sctp_input.c --compile=./usrsctp/usrsctplib/netinet/sctp_asconf.c --compile=./usrsctp/usrsctplib/netinet/sctp_pcb.c --compile=./usrsctp/usrsctplib/netinet/sctp_usrreq.c --compile=./usrsctp/usrsctplib/netinet/sctp_cc_functions.c --compile=./usrsctp/usrsctplib/netinet/sctp_auth.c --compile=./usrsctp/usrsctplib/netinet/sctp_userspace.c --compile=./usrsctp/usrsctplib/netinet/sctp_output.c --compile=./usrsctp/usrsctplib/netinet/sctp_callout.c --compile=./usrsctp/usrsctplib/netinet/sctp_crc32.c --compile=./usrsctp/usrsctplib/netinet/sctp_sysctl.c --compile=./usrsctp/usrsctplib/netinet/sctp_sha1.c --compile=./usrsctp/usrsctplib/netinet/sctp_timer.c --compile=./usrsctp/usrsctplib/netinet/sctputil.c --compile=./usrsctp/usrsctplib/netinet/sctp_bsd_addr.c --compile=./usrsctp/usrsctplib/netinet/sctp_peeloff.c --compile=./usrsctp/usrsctplib/netinet/sctp_indata.c --compile=./usrsctp/usrsctplib/netinet/sctp_ss_functions.c --compile=./usrsctp/usrsctplib/user_socket.c --compile=./usrsctp/usrsctplib/netinet6/sctp6_usrreq.c --compile=./usrsctp/usrsctplib/user_mbuf.c --compile=./usrsctp/usrsctplib/user_environment.c --compile=./usrsctp/usrsctplib/user_recv_thread.c --pnim --preprocess --noHeader --defines=SCTP_PROCESS_LEVEL_LOCKS --defines=SCTP_SIMPLE_ALLOCATOR --defines=__Userspace__ --defines=STDC_HEADERS=1 --defines=HAVE_SYS_TYPES_H=1 --defines=HAVE_SYS_STAT_H=1 --defines=HAVE_STDLIB_H=1 --defines=HAVE_STRING_H=1 --defines=HAVE_MEMORY_H=1 --defines=HAVE_STRINGS_H=1 --defines=HAVE_INTTYPES_H=1 --defines=HAVE_STDINT_H=1 --defines=HAVE_UNISTD_H=1 --defines=HAVE_DLFCN_H=1 --defines=LT_OBJDIR=".libs/" --defines=SCTP_DEBUG=1 --defines=INET=1 --defines=INET6=1 --defines=HAVE_SOCKET=1 --defines=HAVE_INET_ADDR=1 --defines=HAVE_STDATOMIC_H=1 --defines=HAVE_SYS_QUEUE_H=1 --defines=HAVE_LINUX_IF_ADDR_H=1 --defines=HAVE_LINUX_RTNETLINK_H=1 --defines=HAVE_NETINET_IP_ICMP_H=1 --defines=HAVE_NET_ROUTE_H=1 --defines=_GNU_SOURCE --replace=sockaddr=SockAddr --replace=SockAddr_storage=Sockaddr_storage --replace=SockAddr_in=Sockaddr_in --replace=SockAddr_conn=Sockaddr_conn --replace=socklen_t=SockLen --includeDirs=./usrsctp/usrsctplib ./usrsctp/usrsctplib/usrsctp.h From 5bc19f3e03a629e88e813b090fbe2f741a165aed Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 21 Apr 2023 12:01:14 +0200 Subject: [PATCH 06/66] Added Fingerprint attribute --- webrtc/stun.nim | 5 +++-- webrtc/stunattributes.nim | 11 +++++++++++ webrtc/utils.nim | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 webrtc/utils.nim diff --git a/webrtc/stun.nim b/webrtc/stun.nim index 16d9a36..9ef11da 100644 --- a/webrtc/stun.nim +++ b/webrtc/stun.nim @@ -49,7 +49,7 @@ type RawStunMessage = object msgType: uint16 - length* {.bin_value: it.content.len().}: uint16 + length* {.bin_value: it.content.len() + 8.}: uint16 magicCookie: uint32 transactionId: array[12, byte] content* {.bin_len: it.length.}: seq[byte] @@ -85,7 +85,8 @@ proc encode*(msg: StunMessage): seq[byte] = smi.content.add(Binary.encode(attr)) smi.content.add(newSeq[byte](val[smi.content.len() mod 4])) - return Binary.encode(smi) + result = Binary.encode(smi) + result.add(Binary.encode(Fingerprint.encode(result))) proc getResponse*(T: typedesc[Stun], msg: seq[byte], address: TransportAddress): Option[StunMessage] = diff --git a/webrtc/stunattributes.nim b/webrtc/stunattributes.nim index fef8fc5..f908568 100644 --- a/webrtc/stunattributes.nim +++ b/webrtc/stunattributes.nim @@ -1,5 +1,6 @@ import binary_serialization, stew/byteutils +import utils type # Stun Attribute @@ -98,3 +99,13 @@ proc encode*(T: typedesc[UnknownAttribute], unknownAttr: seq[uint16]): RawStunAt result = RawStunAttribute(attributeType: AttrUnknownAttributes.uint16, length: value.len().uint16, value: value) + +type + Fingerprint* = object + crc32: uint32 + +proc encode*(T: typedesc[Fingerprint], msg: seq[byte]): RawStunAttribute = + let value = Binary.encode(Fingerprint(crc32: crc32(msg) xor 0x5354554e'u32)) + result = RawStunAttribute(attributeType: AttrFingerprint.uint16, + length: value.len().uint16, + value: value) diff --git a/webrtc/utils.nim b/webrtc/utils.nim new file mode 100644 index 0000000..0e75d4c --- /dev/null +++ b/webrtc/utils.nim @@ -0,0 +1,16 @@ +import strutils, bitops + +proc createCrc32Table(): array[0..255, uint32] = + for i in 0..255: + var rem = i.uint32 + for j in 0..7: + if (rem and 1) > 0: rem = (rem shr 1) xor 0xedb88320'u32 + else: rem = rem shr 1 + result[i] = rem + +proc crc32*(s: seq[byte]): uint32 = + const crc32table = createCrc32Table() + result = 0xffffffff'u32 + for c in s: + result = (result shr 8) xor crc32table[(result and 0xff) xor c] + result = not result From 472306f5ce8b5fd9ab515f953b8ac623f5128d7e Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 21 Apr 2023 17:41:42 +0200 Subject: [PATCH 07/66] Added Xor-Mapped-Address attribute --- webrtc/stun.nim | 8 +++++-- webrtc/stunattributes.nim | 45 +++++++++++++++++++++++++++++++++++++-- webrtc/webrtc.nim | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 webrtc/webrtc.nim diff --git a/webrtc/stun.nim b/webrtc/stun.nim index 9ef11da..9e575ff 100644 --- a/webrtc/stun.nim +++ b/webrtc/stun.nim @@ -49,6 +49,7 @@ type RawStunMessage = object msgType: uint16 + # it.conten.len() + 8 Because the Fingerprint is added after the encoding length* {.bin_value: it.content.len() + 8.}: uint16 magicCookie: uint32 transactionId: array[12, byte] @@ -89,7 +90,9 @@ proc encode*(msg: StunMessage): seq[byte] = result.add(Binary.encode(Fingerprint.encode(result))) proc getResponse*(T: typedesc[Stun], msg: seq[byte], - address: TransportAddress): Option[StunMessage] = + ta: TransportAddress): Option[StunMessage] = + if ta.family != AddressFamily.IPv4 and ta.family != AddressFamily.IPv6: + return none(StunMessage) let sm = try: StunMessage.decode(msg) @@ -112,7 +115,8 @@ proc getResponse*(T: typedesc[Stun], msg: seq[byte], res.attributes.add(UnknownAttribute.encode(unknownAttr)) return some(res) - #if sm.attributes.getAttribute()) + res.attributes.add(XorMappedAddress.encode(ta, sm.transactionId)) + return some(res) proc new*(T: typedesc[Stun]): T = result = T() diff --git a/webrtc/stunattributes.nim b/webrtc/stunattributes.nim index f908568..e57a829 100644 --- a/webrtc/stunattributes.nim +++ b/webrtc/stunattributes.nim @@ -1,8 +1,11 @@ +import sequtils, typetraits import binary_serialization, - stew/byteutils + stew/byteutils, + chronos import utils type + StunAttributeEncodingError* = object of CatchableError # Stun Attribute # 0 1 2 3 # 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 @@ -100,12 +103,50 @@ proc encode*(T: typedesc[UnknownAttribute], unknownAttr: seq[uint16]): RawStunAt length: value.len().uint16, value: value) +# Fingerprint + type Fingerprint* = object crc32: uint32 proc encode*(T: typedesc[Fingerprint], msg: seq[byte]): RawStunAttribute = - let value = Binary.encode(Fingerprint(crc32: crc32(msg) xor 0x5354554e'u32)) + let value = Binary.encode(T(crc32: crc32(msg) xor 0x5354554e'u32)) result = RawStunAttribute(attributeType: AttrFingerprint.uint16, length: value.len().uint16, value: value) + +# Xor Mapped Address + +type + MappedAddressFamily {.size: 1.} = enum + MAFIPv4 = 0x01 + MAFIPv6 = 0x02 + + XorMappedAddress* = object + reserved: uint8 # should be 0 + family: MappedAddressFamily + port: uint16 + address: seq[byte] + +proc encode*(T: typedesc[XorMappedAddress], ta: TransportAddress, + tid: array[12, byte]): RawStunAttribute = + const magicCookie = @[ 0x21'u8, 0x12, 0xa4, 0x42 ] + let + address = + if ta.family == AddressFamily.IPv4: + var s = newSeq[uint8](4) + for i in 0..3: + s[i] = ta.address_v4[i] xor magicCookie[i] + s + else: + let magicCookieTid = magicCookie.concat(@tid) + var s = newSeq[uint8](16) + for i in 0..15: + s[i] = ta.address_v6[i] xor magicCookieTid[i] + s + xma = T(family: if ta.family == AddressFamily.IPv4: MAFIPv4 else: MAFIPv6, + port: ta.port.distinctBase xor 0x2112'u16, address: address) + value = Binary.encode(xma) + result = RawStunAttribute(attributeType: AttrXORMappedAddress.uint16, + length: value.len().uint16, + value: value) diff --git a/webrtc/webrtc.nim b/webrtc/webrtc.nim new file mode 100644 index 0000000..05f451b --- /dev/null +++ b/webrtc/webrtc.nim @@ -0,0 +1,40 @@ +import chronos, chronicles +import stun + +logScope: + topics = "webrtc" + +let fut = newFuture[void]() +type + WebRTC* = object + udp: DatagramTransport + +proc new*(T: typedesc[WebRTC], port: uint16 = 42657): T = + logScope: topics = "webrtc" + var webrtc = T() + proc onReceive(udp: DatagramTransport, address: TransportAddress) {.async, gcsafe.} = + let + msg = udp.getMessage() + if Stun.isMessage(msg): + let res = Stun.getResponse(msg, address) + echo res + if res.isSome(): + await udp.sendTo(address, res.get().encode()) + + trace "onReceive", isStun = Stun.isMessage(msg) + if not fut.completed(): fut.complete() + + let + laddr = initTAddress("127.0.0.1:" & $port) + udp = newDatagramTransport(onReceive, local = laddr) + trace "local address", laddr + webrtc.udp = udp + return webrtc +# +#proc main {.async.} = +# echo "/ip4/127.0.0.1/udp/42657/webrtc/certhash/uEiDKBGpmOW3zQhiCHagHZ8igwfKNIp8rQCJWd5E5mIhGHw/p2p/12D3KooWFjMiMZLaCKEZRvMqKp5qUGduS6iBZ9RWQgYZXYtAAaPC" +# discard WebRTC.new() +# await fut +# await sleepAsync(10.seconds) +# +#waitFor(main()) From d1ba2ee0bc691964067955ffd9d4a4de3ad83476 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Tue, 25 Apr 2023 11:56:30 +0200 Subject: [PATCH 08/66] Stun done --- webrtc/stun.nim | 58 +++++++++++++++++++++++++++++---------- webrtc/stunattributes.nim | 21 ++++++++++++++ webrtc/webrtc.nim | 12 ++++++-- 3 files changed, 75 insertions(+), 16 deletions(-) diff --git a/webrtc/stun.nim b/webrtc/stun.nim index 9e575ff..344195c 100644 --- a/webrtc/stun.nim +++ b/webrtc/stun.nim @@ -1,8 +1,18 @@ -import bitops +# Nim-WebRTC +# Copyright (c) 2023 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +# * MIT license ([LICENSE-MIT](LICENSE-MIT)) +# at your option. +# This file may not be copied, modified, or distributed except according to +# those terms. + +import bitops, strutils import chronos, chronicles, binary_serialization, - stew/objects + stew/objects, + stew/byteutils import stunattributes export binary_serialization @@ -18,13 +28,13 @@ const BindingResponse = 0x0101'u16 proc decode(T: typedesc[RawStunAttribute], cnt: seq[byte]): seq[RawStunAttribute] = - const val = @[0, 3, 2, 1] + const pad = @[0, 3, 2, 1] var padding = 0 while padding < cnt.len(): let attr = Binary.decode(cnt[padding ..^ 1], RawStunAttribute) result.add(attr) padding += 4 + attr.value.len() - padding += val[padding mod 4] + padding += pad[padding mod 4] type # Stun Header @@ -50,7 +60,7 @@ type RawStunMessage = object msgType: uint16 # it.conten.len() + 8 Because the Fingerprint is added after the encoding - length* {.bin_value: it.content.len() + 8.}: uint16 + length* {.bin_value: it.content.len().}: uint16 magicCookie: uint32 transactionId: array[12, byte] content* {.bin_len: it.length.}: seq[byte] @@ -71,36 +81,56 @@ proc getAttribute(attrs: seq[RawStunAttribute], typ: uint16): Option[seq[byte]] proc isMessage*(T: typedesc[Stun], msg: seq[byte]): bool = msg.len >= msgHeaderSize and msg[4..<8] == magicCookieSeq and bitand(0xC0'u8, msg[0]) == 0'u8 +proc addLength(msgEncoded: var seq[byte], length: uint16) = + let + hi = (length div 256'u16).uint8 + lo = (length mod 256'u16).uint8 + msgEncoded[2] = msgEncoded[2] + hi + if msgEncoded[3].int + lo.int >= 256: + msgEncoded[2] = msgEncoded[2] + 1 + msgEncoded[3] = ((msgEncoded[3].int + lo.int) mod 256).uint8 + else: + msgEncoded[3] = msgEncoded[3] + lo + proc decode*(T: typedesc[StunMessage], msg: seq[byte]): StunMessage = let smi = Binary.decode(msg, RawStunMessage) return T(msgType: smi.msgType, transactionId: smi.transactionId, attributes: RawStunAttribute.decode(smi.content)) -proc encode*(msg: StunMessage): seq[byte] = - const val = @[0, 3, 2, 1] +proc encode*(msg: StunMessage, userOpt: Option[seq[byte]]): seq[byte] = + const pad = @[0, 3, 2, 1] var smi = RawStunMessage(msgType: msg.msgType, magicCookie: magicCookie, transactionId: msg.transactionId) for attr in msg.attributes: smi.content.add(Binary.encode(attr)) - smi.content.add(newSeq[byte](val[smi.content.len() mod 4])) + smi.content.add(newSeq[byte](pad[smi.content.len() mod 4])) result = Binary.encode(smi) + + if userOpt.isSome(): + let username = string.fromBytes(userOpt.get()) + let usersplit = username.split(":") + if usersplit.len() == 2 and usersplit[0].startsWith("libp2p+webrtc+v1/"): + result.addLength(24) + result.add(Binary.encode(MessageIntegrity.encode(result, toBytes(usersplit[0])))) + + result.addLength(8) result.add(Binary.encode(Fingerprint.encode(result))) proc getResponse*(T: typedesc[Stun], msg: seq[byte], - ta: TransportAddress): Option[StunMessage] = + ta: TransportAddress): Option[seq[byte]] = if ta.family != AddressFamily.IPv4 and ta.family != AddressFamily.IPv6: - return none(StunMessage) + return none(seq[byte]) let sm = try: StunMessage.decode(msg) except CatchableError as exc: - return none(StunMessage) + return none(seq[byte]) if sm.msgType != BindingRequest: - return none(StunMessage) + return none(seq[byte]) var res = StunMessage(msgType: BindingResponse, transactionId: sm.transactionId) @@ -113,10 +143,10 @@ proc getResponse*(T: typedesc[Stun], msg: seq[byte], if unknownAttr.len() > 0: res.attributes.add(ErrorCode.encode(ECUnknownAttribute)) res.attributes.add(UnknownAttribute.encode(unknownAttr)) - return some(res) + return some(res.encode(sm.attributes.getAttribute(AttrUsername.uint16))) res.attributes.add(XorMappedAddress.encode(ta, sm.transactionId)) - return some(res) + return some(res.encode(sm.attributes.getAttribute(AttrUsername.uint16))) proc new*(T: typedesc[Stun]): T = result = T() diff --git a/webrtc/stunattributes.nim b/webrtc/stunattributes.nim index e57a829..bf2b471 100644 --- a/webrtc/stunattributes.nim +++ b/webrtc/stunattributes.nim @@ -1,3 +1,12 @@ +# Nim-WebRTC +# Copyright (c) 2023 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +# * MIT license ([LICENSE-MIT](LICENSE-MIT)) +# at your option. +# This file may not be copied, modified, or distributed except according to +# those terms. + import sequtils, typetraits import binary_serialization, stew/byteutils, @@ -150,3 +159,15 @@ proc encode*(T: typedesc[XorMappedAddress], ta: TransportAddress, result = RawStunAttribute(attributeType: AttrXORMappedAddress.uint16, length: value.len().uint16, value: value) + +# Message Integrity + +type + MessageIntegrity* = object + msgInt: seq[byte] + +proc encode*(T: typedesc[MessageIntegrity], msg: seq[byte], key: seq[byte]): RawStunAttribute = + let value = Binary.encode(T(msgInt: hmacSha1(key, msg))) + result = RawStunAttribute(attributeType: AttrMessageIntegrity.uint16, + length: value.len().uint16, + value: value) diff --git a/webrtc/webrtc.nim b/webrtc/webrtc.nim index 05f451b..ce8eb0b 100644 --- a/webrtc/webrtc.nim +++ b/webrtc/webrtc.nim @@ -1,3 +1,12 @@ +# Nim-WebRTC +# Copyright (c) 2023 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +# * MIT license ([LICENSE-MIT](LICENSE-MIT)) +# at your option. +# This file may not be copied, modified, or distributed except according to +# those terms. + import chronos, chronicles import stun @@ -17,9 +26,8 @@ proc new*(T: typedesc[WebRTC], port: uint16 = 42657): T = msg = udp.getMessage() if Stun.isMessage(msg): let res = Stun.getResponse(msg, address) - echo res if res.isSome(): - await udp.sendTo(address, res.get().encode()) + await udp.sendTo(address, res.get()) trace "onReceive", isStun = Stun.isMessage(msg) if not fut.completed(): fut.complete() From 34dd277bc9cfb2e9bc6660c160e0eb35e041ab09 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 28 Apr 2023 17:06:33 +0200 Subject: [PATCH 09/66] Creation of the webrtc connection object --- webrtc/stun_connection.nim | 48 ++++++++++++++++++++++++++++++++++++ webrtc/udp_connection.nim | 43 ++++++++++++++++++++++++++++++++ webrtc/webrtc_connection.nim | 30 ++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 webrtc/stun_connection.nim create mode 100644 webrtc/udp_connection.nim create mode 100644 webrtc/webrtc_connection.nim diff --git a/webrtc/stun_connection.nim b/webrtc/stun_connection.nim new file mode 100644 index 0000000..8199450 --- /dev/null +++ b/webrtc/stun_connection.nim @@ -0,0 +1,48 @@ +# Nim-WebRTC +# Copyright (c) 2023 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +# * MIT license ([LICENSE-MIT](LICENSE-MIT)) +# at your option. +# This file may not be copied, modified, or distributed except according to +# those terms. + +import chronos +import webrtc_connection, stun + +type + StunConn* = ref object of WebRTCConn + recvData: seq[seq[byte]] + recvEvent: AsyncEvent + handlesFut: Future[void] + +proc handles(self: StunConn) {.async.} = + while true: # TODO: while not self.conn.atEof() + let msg = await self.conn.read() + if Stun.isMessage(msg): + let res = Stun.getResponse(msg, self.address) + if res.isSome(): + await self.conn.write(res.get()) + else: + recvData.add(msg) + recvEvent.fire() + +method init(self: StunConn, conn: WebRTCConn, address: TransportAddress) {.async.} = + procCall(WebRTCConn(self).init(conn, address)) + + self.recvEvent = newAsyncEvent() + self.handlesFut = handles() + +method close(self: StunConn) {.async.} = + self.handlesFut.cancel() # check before? + self.conn.close() + +method write(self: StunConn, msg: seq[byte]) {.async.} = + await self.conn.write(msg) + +method read(self: StunConn): seq[byte] {.async.} = + while self.recvData.len() <= 0: + self.recvEvent.clear() + await self.recvEvent.wait() + result = self.recvData[0] + self.recvData.delete(0..0) diff --git a/webrtc/udp_connection.nim b/webrtc/udp_connection.nim new file mode 100644 index 0000000..25f3ba4 --- /dev/null +++ b/webrtc/udp_connection.nim @@ -0,0 +1,43 @@ +# Nim-WebRTC +# Copyright (c) 2023 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +# * MIT license ([LICENSE-MIT](LICENSE-MIT)) +# at your option. +# This file may not be copied, modified, or distributed except according to +# those terms. + +import chronos +import webrtc_connection + +type + UdpConn* = ref object of WebRTCConn + udp: DatagramTransport + recvData: seq[seq[byte]] + recvEvent: AsyncEvent + +method init(self: UdpConn, conn: WebRTCConn, address: TransportAddress) {.async.} = + procCall(WebRTCConn(self).init(conn, address)) + + proc onReceive(udp: DatagramTransport, address: TransportAddress) {.async, gcsafe.} = + let msg = udp.getMessage() + self.recvData.add(msg) + self.recvEvent.fire() + + self.recvEvent = newAsyncEvent() + self.udp = newDatagramTransport(onReceive) + +method close(self: UdpConn) {.async.} = + self.udp.close() + if not self.conn.isNil(): + self.conn.close() + +method write(self: UdpConn, msg: seq[byte]) {.async.} = + await self.udp.sendTo(self.address, msg) + +method read(self: UdpConn): seq[byte] {.async.} = + while self.recvData.len() <= 0: + self.recvEvent.clear() + await self.recvEvent.wait() + result = self.recvData[0] + self.recvData.delete(0..0) diff --git a/webrtc/webrtc_connection.nim b/webrtc/webrtc_connection.nim new file mode 100644 index 0000000..76b61ee --- /dev/null +++ b/webrtc/webrtc_connection.nim @@ -0,0 +1,30 @@ +# Nim-WebRTC +# Copyright (c) 2023 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +# * MIT license ([LICENSE-MIT](LICENSE-MIT)) +# at your option. +# This file may not be copied, modified, or distributed except according to +# those terms. + +import chronos + +type + WebRTCConn* = ref object of RootObj + conn: WebRTCConn + address: TransportAddress + # isClosed: bool + # isEof: bool + +method init(self: WebRTCConn, conn: WebRTCConn, address: TransportAddress) {.async, base.} = + self.conn = conn + self.address = address + +method close(self: WebRTCConn) {.async, base.} = + doAssert(false, "not implemented!") + +method write(self: WebRTCConn, msg: seq[byte]) {.async, base.} = + doAssert(false, "not implemented!") + +method read(self: WebRTCConn): seq[byte] = + doAssert(false, "not implemented!") From 77832545924cbd3d547154afba535ef7f1570d93 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Tue, 9 May 2023 15:22:34 +0200 Subject: [PATCH 10/66] First draft of the mbedtls wrapper --- .gitmodules | 3 + build_mbedtls.sh | 100 ++++++ build.sh => build_usrsctp.sh | 2 +- mbedtls | 1 + prelude_mbedtls.nim | 13 + prelude.nim => prelude_usrsctp.nim | 0 webrtc/dtls.nim | 494 +++++++++++++++-------------- webrtc/utils.nim | 32 +- 8 files changed, 397 insertions(+), 248 deletions(-) create mode 100755 build_mbedtls.sh rename build.sh => build_usrsctp.sh (97%) create mode 160000 mbedtls create mode 100644 prelude_mbedtls.nim rename prelude.nim => prelude_usrsctp.nim (100%) diff --git a/.gitmodules b/.gitmodules index b04bc21..6ba4614 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "usrsctp"] path = usrsctp url = git@github.com:sctplab/usrsctp.git +[submodule "mbedtls"] + path = mbedtls + url = git@github.com:Mbed-TLS/mbedtls.git diff --git a/build_mbedtls.sh b/build_mbedtls.sh new file mode 100755 index 0000000..29d8e44 --- /dev/null +++ b/build_mbedtls.sh @@ -0,0 +1,100 @@ +#!/bin/bash +root=$(dirname "$0") +outputDirectory="${root}/webrtc/mbedtls" +genDirectory="${root}/gen" + +mkdir -p "${outputDirectory}" "${genDirectory}" + +# install nimterop, if not already installed +if ! [ -x "$(command -v toast)" ]; then + nimble install -y nimterop@0.6.11 +fi + +# run make on usrsctp sources +cd "${root}/mbedtls" && make && cd - + +# assemble list of C files to be compiled +for file in `find ${root}/mbedtls/library -name '*.c'`; do + compile="${compile} --compile=${file}" +done + +# rm -r generatedmbedtls.h +# for inc in $(for file in ${root}/mbedtls/include/mbedtls/*.h; do gcc -H "${file}" -I mbedtls/include/ 2>&1 | grep '^\.* mbedtls/include/mbedtls'; echo "- ${file}"; done | LC_COLLATE=C sort -r | awk '{$0=$2}!seen[$0]++'); do +# cat "$inc" | sed '/^#include ".*"/d' >> generatedmbedtls.h +# echo "" >> generatedmbedtls.h +# done +# cat "${root}/prelude_mbedtls.nim" > generatedmbedtls.nim +# echo 'type tm {.importc: "struct tm", header: "".} = object' >> generatedmbedtls.nim +# toast \ +# $compile \ +# --pnim \ +# --preprocess \ +# --nocomment \ +# --replace=_pms_rsa=u_pms_rsa \ +# --replace=_pms_dhm=u_pms_dhm \ +# --replace=_pms_ecdh=u_pms_ecdh \ +# --replace=_pms_psk=u_pms_psk \ +# --replace=_pms_dhe_psk=u_pms_dhe_psk \ +# --replace=_pms_rsa_psk=u_pms_rsa_psk \ +# --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk \ +# --replace=_pms_ecjpake=u_pms_ecjpake \ +# --includeDirs="${root}/mbedtls/include" \ +# --includeDirs="${root}/mbedtls/library" \ +# generatedmbedtls.h >> generatedmbedtls.nim + +# generate nim wrapper with nimterop +errorProc=() +for inc in ${root}/mbedtls/include/mbedtls/*.h; do + bname="$(basename "${inc}" | tr -- -. __)" + outputFile="${outputDirectory}/${bname%_h}.nim" + genFile="${genDirectory}/${bname%_h}.nim" + + echo "=======> ${outputFile}" + # add prelude + cat "${root}/prelude_mbedtls.nim" > "${outputFile}" + + if [ "${bname}" = "platform_util_h" ]; then + echo 'type tm {.importc: "struct tm", header: "".} = object' >> "${outputFile}" + fi + # add include + gcc -H "${inc}" -I"${root}/mbedtls/include" 2>&1 | + grep "^\.* ${root}/mbedtls/include/mbedtls" | + sed 's/^.*\/\(.*\)\.h/import "\1"/' >> "${outputFile}" +# grep "^#include \"mbedtls/.*\.h\".*$" "${inc}" | +# sed "s/.*\"mbedtls\/\(.*\).h\".*$/import \1/" >> "${outputFile}" + + toast \ + --pnim \ + --preprocess \ + --nocomment \ + --noHeader \ + --replace=_pms_rsa=u_pms_rsa \ + --replace=_pms_dhm=u_pms_dhm \ + --replace=_pms_ecdh=u_pms_ecdh \ + --replace=_pms_psk=u_pms_psk \ + --replace=_pms_dhe_psk=u_pms_dhe_psk \ + --replace=_pms_rsa_psk=u_pms_rsa_psk \ + --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk \ + --replace=_pms_ecjpake=u_pms_ecjpake \ + --replace=private_xm1=private_xm1_1 \ + --replace=private_xm2=private_xm2_1 \ + --includeDirs="${root}/mbedtls/include" \ + --includeDirs="${root}/mbedtls/library" \ + "${inc}" > "${genFile}" + sed -i \ + -e 's/\bpassC\b/passc/g' \ + -e 's/cuchar/byte/g' \ + "${genFile}" + while read -r procLine; do + proc="$(sed 's/^proc \(.*\)\*(.*/\1/' <<< "${procLine}")" + matches="$(grep "\\<${proc}\\>" "${root}/mbedtls/tags" | sed '/library/!d')" + if [ $? -ne 0 ]; then + errorProc+=("${proc} in ${outputFile}") + continue + fi + if ! [ -z "${matches}" ]; then + echo "${matches}" | awk '{$0="{.compile: \"'"${root}"'/mbedtls/"$2"\".}"}1' + fi + done <<< "$(grep '^proc .*\*(' "${genFile}")" | sort | uniq >> "${outputFile}" + cat "${genFile}" >> "${outputFile}" +done diff --git a/build.sh b/build_usrsctp.sh similarity index 97% rename from build.sh rename to build_usrsctp.sh index c729c7e..04f1629 100755 --- a/build.sh +++ b/build_usrsctp.sh @@ -11,7 +11,7 @@ fi cd "${root}/usrsctp" && ./bootstrap && ./configure && make && cd - # add prelude -cat "${root}/prelude.nim" > "${outputFile}" +cat "${root}/prelude_usrsctp.nim" > "${outputFile}" # assemble list of C files to be compiled for file in `find ${root}/usrsctp/usrsctplib -name '*.c'`; do diff --git a/mbedtls b/mbedtls new file mode 160000 index 0000000..8e076e4 --- /dev/null +++ b/mbedtls @@ -0,0 +1 @@ +Subproject commit 8e076e4132acd81e038288e10912e144593d32cb diff --git a/prelude_mbedtls.nim b/prelude_mbedtls.nim new file mode 100644 index 0000000..b130ffa --- /dev/null +++ b/prelude_mbedtls.nim @@ -0,0 +1,13 @@ +import strformat, os + +# Socket definitions +import nativesockets + +# C include directory +const root = currentSourcePath.parentDir +const mbedtlsInclude = root/"mbedtls"/"include" +const mbedtlsLibrary = root/"mbedtls"/"library" + +{.passc: fmt"-I{mbedtlsInclude}".} +{.passc: fmt"-I{mbedtlsLibrary}".} + diff --git a/prelude.nim b/prelude_usrsctp.nim similarity index 100% rename from prelude.nim rename to prelude_usrsctp.nim diff --git a/webrtc/dtls.nim b/webrtc/dtls.nim index 8c76d8b..3e6230b 100644 --- a/webrtc/dtls.nim +++ b/webrtc/dtls.nim @@ -7,250 +7,252 @@ # This file may not be copied, modified, or distributed except according to # those terms. -import std/[openssl, os] -import posix -import chronos, chronicles -import stew/[byteutils, ptrops] +import mbedtls/ssl -export chronicles - -logScope: - topics = "webrtc dtls" - -# Missing openssl procs things -const - BIO_NOCLOSE = 0x0 - #BIO_CLOSE = 0x1 - BIO_CTRL_DGRAM_SET_CONNECTED = 32 - BIO_CTRL_DGRAM_GET_PEER = 46 - DTLS_CTRL_GET_TIMEOUT = 73 - BIO_C_SET_FD = 104 - -proc DTLS_client_method(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} -proc DTLS_server_method(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} -proc BIO_new_dgram(fd: SocketHandle, closeFlag: int): BIO {.cdecl, dynlib: DLLUtilName, importc.} -proc SSL_get_rbio(ssl: SslPtr): BIO {.cdecl, dynlib: DLLSSLName, importc.} -proc RAND_bytes(buf: pointer, length: int): int {.cdecl, dynlib: DLLSSLName, importc.} -proc DTLSv1_listen(ssl: SslPtr, peer: ptr): int {.cdecl, dynlib: DLLSSLName, importc.} -proc SSL_CTX_set_cookie_generate_cb(ctx: SslCtx, cb: proc (ssl: SslPtr, cookie: ptr byte, cookieLen: ptr int): int {.cdecl.}) {.cdecl, dynlib: DLLSSLName, importc.} -proc SSL_CTX_set_cookie_verify_cb(ctx: SslCtx, cb: proc (ssl: SslPtr, cookie: ptr byte, cookieLen: int): int {.cdecl.}) {.cdecl, dynlib: DLLSSLName, importc.} -# --- openssl - -type - DtlsSocket = ref object - udp: DatagramTransport - gotData: AsyncEvent - sslCtx: SslCtx - ctxIsView: bool - ssl: SslPtr - -proc waitForData(socket: DtlsSocket) {.async.} = - socket.gotData.clear() - var timeout: Timeval - if (SSL_ctrl(socket.ssl, DTLS_CTRL_GET_TIMEOUT, 0, addr timeout) == 1): - let - momentTimeout = seconds(clong(timeout.tv_sec)) + nanoseconds(timeout.tv_usec) - fut = socket.gotData.wait() - if not await fut.withTimeout(momentTimeout): - fut.cancel - else: - await socket.gotData.wait() - -template wrapSslCallRes(dtlsSocket, call: untyped): untyped = - block: - var err: type(call) - while true: - err = call - if err <= 0: - let openSslErr = SSL_get_error(dtlsSocket.ssl, cint(err)) - if openSslErr in [SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE]: - await dtlsSocket.waitForData() - continue - elif openSslErr == SSL_ERROR_SYSCALL: - let err = osLastError() - if cint(err) == EAGAIN: - await dtlsSocket.waitForData() - continue - raiseTransportOsError(err) - let errorMsg = ERR_error_string(culong(ERR_peek_last_error()), nil) - raise ValueError.newException("openssl error: " & $errorMsg) - break - err - -template wrapSslCall(dtlsSocket, call: untyped) = - discard wrapSslCallRes(dtlsSocket, call) - -proc fromSAddr(storeAddr: Sockaddr_storage): TransportAddress = - let size = - if int(storeAddr.ss_family) == ord(Domain.AF_INET): - sizeof(Sockaddr_in) - elif int(storeAddr.ss_family) == ord(Domain.AF_INET6): - sizeof(Sockaddr_in6) - elif int(storeAddr.ss_family) == ord(Domain.AF_UNIX): - sizeof(Sockaddr_storage) - else: -1 - fromSAddr(addr storeAddr, SockLen(size), result) - -var cookieSecret: array[32, byte] -doAssert RAND_bytes(addr cookieSecret[0], cookieSecret.len) > 0 - -proc generateSslCookie(ssl: SslPtr, cookie: ptr byte, cookieLen: ptr int): int {.cdecl.} = - var peerSockaddr: Sockaddr_storage - if BIO_ctrl(SSL_get_rbio(ssl), BIO_CTRL_DGRAM_GET_PEER, 0, cast[cstring](addr peerSockaddr)) <= 0: - return 0 - - let transportAddress = fromSAddr(peerSockaddr) - if - HMAC(EVP_sha1(), - addr cookieSecret[0], cint(cookieSecret.len), - cast[cstring](addr transportAddress), csize_t(sizeof(TransportAddress)), - cast[cstring](cookie), cast[ptr cuint](cookieLen)) == nil: - 0 - else: - 1 - -proc verifySslCookie(ssl: SslPtr, cookie: ptr byte, cookieLen: int): int {.cdecl.} = - var peerSockaddr: Sockaddr_storage - if BIO_ctrl(SSL_get_rbio(ssl), BIO_CTRL_DGRAM_GET_PEER, 0, cast[cstring](addr peerSockaddr)) <= 0: - return 0 - - let transportAddress = fromSAddr(peerSockaddr) - var - buffer: array[1024, byte] - bufferLength: cuint - if - HMAC(EVP_sha1(), - addr cookieSecret[0], cint(cookieSecret.len), - cast[cstring](addr transportAddress), csize_t(sizeof(TransportAddress)), - cast[cstring](addr buffer[0]), addr bufferLength) == nil: - return 0 - - if bufferLength != cuint(cookieLen): return 0 - if cookie.makeOpenArray(byte, cookieLen) == buffer[0 ..< bufferLength]: - 1 - else: - 0 - -proc createDtlsSocket( - localAddress = AnyAddress, - remoteAddress = AnyAddress, - flags: set[ServerFlags] = {NoAutoRead}): DtlsSocket = - - let gotData = newAsyncEvent() - proc callback(transp: DatagramTransport, remote: TransportAddress) {.async.} = discard - proc callback2(udata: pointer) = - gotData.fire() - let datagram = newDatagramTransport( - callback, - local = localAddress, - remote = remoteAddress, - flags = flags) - addReader(datagram.fd, callback2) - return DtlsSocket(udp: datagram, gotData: gotData) - - -proc createDtlsServer*(host: TransportAddress): Future[DtlsSocket] {.async.} = - result = createDtlsSocket( - localAddress = host, - flags = {NoAutoRead, ReuseAddr} - ) - - result.sslCtx = SSL_CTX_new(DTLS_server_method()) - #TODO if we close the server with connections alive, - #they have a ref to this ctx - - #TODO handle certificates - echo SSL_CTX_use_certificate_file(result.sslCtx, "certs/server-cert.pem", SSL_FILETYPE_PEM) - echo SSL_CTX_use_PrivateKey_file(result.sslCtx, "certs/server-key.pem", SSL_FILETYPE_PEM) - SSL_CTX_set_cookie_generate_cb(result.sslCtx, generateSslCookie) - SSL_CTX_set_cookie_verify_cb(result.sslCtx, verifySslCookie) - -proc accept*(sock: DtlsSocket): Future[DtlsSocket] {.async.} = - let - ctx = sock.sslCtx - ssl = SSL_new(ctx) - bio = BIO_new_dgram(SocketHandle(sock.udp.fd), BIO_NOCLOSE) - - sslSetBio(ssl, bio, bio) - - var clientSockAddr: Sockaddr_storage - doAssert isNil(sock.ssl) - sock.ssl = ssl - wrapSslCall(sock, DTLSv1_listen(ssl, addr clientSockAddr)) - sock.ssl = nil - let clientAddr = fromSAddr(clientSockAddr) - - # create new socket - result = createDtlsSocket( - localAddress = sock.udp.localAddress, - remoteAddress = clientAddr, - flags = {NoAutoRead, ReuseAddr} - ) - - let sockHandle = SocketHandle(result.udp.fd) - doAssert BIO_ctrl(bio, BIO_C_SET_FD, 0, cast[cstring](addr sockHandle)) > 0 - doAssert BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_CONNECTED, 0, cast[cstring](addr clientSockAddr)) > 0 - - result.sslCtx = ctx - result.ssl = ssl - result.ctxIsView = true - wrapSslCall(result, SSL_accept(ssl)) - -proc connect*(address: TransportAddress): Future[DtlsSocket] {.async.} = - result = createDtlsSocket( - remoteAddress = address - ) - - let - ctx = SSL_CTX_new(DTLS_client_method()) - ssl = SSL_new(ctx) - bio = BIO_new_dgram(SocketHandle(result.udp.fd), BIO_NOCLOSE) - - #TODO handle certs - echo SSL_CTX_use_certificate_file(ctx, "certs/client-cert.pem", SSL_FILETYPE_PEM) - echo SSL_CTX_use_PrivateKey_file(ctx, "certs/client-key.pem", SSL_FILETYPE_PEM) - echo SSL_CTX_check_private_key(ctx) - - result.sslCtx = ctx - result.ssl = ssl - var slen: SockLen - var remoteSaddr: Sockaddr_storage - toSAddr(address, remoteSaddr, slen) - doAssert BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_CONNECTED, 0, cast[cstring](addr remoteSaddr)) > 0 - sslSetBio(ssl, bio, bio) - wrapSslCall(result, SSL_connect(ssl)) - -proc write*(sock: DtlsSocket, data: seq[byte]) {.async.} = - wrapSslCall(sock, SSL_write(sock.ssl, cast[cstring](addr data[0]), data.len)) - -proc read*(sock: DtlsSocket): Future[seq[byte]] {.async.} = - result = newSeq[byte](1000) - let length = wrapSslCallRes(sock, SSL_read(sock.ssl, cast[cstring](addr result[0]), result.len)) - result.setLen(length) - -proc close*(sock: DtlsSocket) {.async.} = - if not isNil(sock.ssl): - let shutdownRes = SSL_shutdown(sock.ssl) - if shutdownRes == 0: - wrapSslCall(sock, SSL_shutdown(sock.ssl)) - SSL_free(sock.ssl) - if not isNil(sock.sslCtx) and not sock.ctxIsView: - SSL_CTX_free(sock.sslCtx) - sock.udp.close() - -proc main {.async.} = - let - address = initTAddress("127.0.0.1:8090") - server = await createDtlsServer(address) - client = connect(address) - - let - servConn = await server.accept() - clientConn = await client - await clientConn.write("Hello world!".toBytes()) - echo string.fromBytes(await servConn.read()) - - await allFutures(servConn.close(), clientConn.close()) - await server.close() - -waitFor(main()) +# import std/[openssl, os] +# import posix +# import chronos, chronicles +# import stew/[byteutils, ptrops] +# +# export chronicles +# +# logScope: +# topics = "webrtc dtls" +# +# # Missing openssl procs things +# const +# BIO_NOCLOSE = 0x0 +# #BIO_CLOSE = 0x1 +# BIO_CTRL_DGRAM_SET_CONNECTED = 32 +# BIO_CTRL_DGRAM_GET_PEER = 46 +# DTLS_CTRL_GET_TIMEOUT = 73 +# BIO_C_SET_FD = 104 +# +# proc DTLS_client_method(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} +# proc DTLS_server_method(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} +# proc BIO_new_dgram(fd: SocketHandle, closeFlag: int): BIO {.cdecl, dynlib: DLLUtilName, importc.} +# proc SSL_get_rbio(ssl: SslPtr): BIO {.cdecl, dynlib: DLLSSLName, importc.} +# proc RAND_bytes(buf: pointer, length: int): int {.cdecl, dynlib: DLLSSLName, importc.} +# proc DTLSv1_listen(ssl: SslPtr, peer: ptr): int {.cdecl, dynlib: DLLSSLName, importc.} +# proc SSL_CTX_set_cookie_generate_cb(ctx: SslCtx, cb: proc (ssl: SslPtr, cookie: ptr byte, cookieLen: ptr int): int {.cdecl.}) {.cdecl, dynlib: DLLSSLName, importc.} +# proc SSL_CTX_set_cookie_verify_cb(ctx: SslCtx, cb: proc (ssl: SslPtr, cookie: ptr byte, cookieLen: int): int {.cdecl.}) {.cdecl, dynlib: DLLSSLName, importc.} +# # --- openssl +# +# type +# DtlsSocket = ref object +# udp: DatagramTransport +# gotData: AsyncEvent +# sslCtx: SslCtx +# ctxIsView: bool +# ssl: SslPtr +# +# proc waitForData(socket: DtlsSocket) {.async.} = +# socket.gotData.clear() +# var timeout: Timeval +# if (SSL_ctrl(socket.ssl, DTLS_CTRL_GET_TIMEOUT, 0, addr timeout) == 1): +# let +# momentTimeout = seconds(clong(timeout.tv_sec)) + nanoseconds(timeout.tv_usec) +# fut = socket.gotData.wait() +# if not await fut.withTimeout(momentTimeout): +# fut.cancel +# else: +# await socket.gotData.wait() +# +# template wrapSslCallRes(dtlsSocket, call: untyped): untyped = +# block: +# var err: type(call) +# while true: +# err = call +# if err <= 0: +# let openSslErr = SSL_get_error(dtlsSocket.ssl, cint(err)) +# if openSslErr in [SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE]: +# await dtlsSocket.waitForData() +# continue +# elif openSslErr == SSL_ERROR_SYSCALL: +# let err = osLastError() +# if cint(err) == EAGAIN: +# await dtlsSocket.waitForData() +# continue +# raiseTransportOsError(err) +# let errorMsg = ERR_error_string(culong(ERR_peek_last_error()), nil) +# raise ValueError.newException("openssl error: " & $errorMsg) +# break +# err +# +# template wrapSslCall(dtlsSocket, call: untyped) = +# discard wrapSslCallRes(dtlsSocket, call) +# +# proc fromSAddr(storeAddr: Sockaddr_storage): TransportAddress = +# let size = +# if int(storeAddr.ss_family) == ord(Domain.AF_INET): +# sizeof(Sockaddr_in) +# elif int(storeAddr.ss_family) == ord(Domain.AF_INET6): +# sizeof(Sockaddr_in6) +# elif int(storeAddr.ss_family) == ord(Domain.AF_UNIX): +# sizeof(Sockaddr_storage) +# else: -1 +# fromSAddr(addr storeAddr, SockLen(size), result) +# +# var cookieSecret: array[32, byte] +# doAssert RAND_bytes(addr cookieSecret[0], cookieSecret.len) > 0 +# +# proc generateSslCookie(ssl: SslPtr, cookie: ptr byte, cookieLen: ptr int): int {.cdecl.} = +# var peerSockaddr: Sockaddr_storage +# if BIO_ctrl(SSL_get_rbio(ssl), BIO_CTRL_DGRAM_GET_PEER, 0, cast[cstring](addr peerSockaddr)) <= 0: +# return 0 +# +# let transportAddress = fromSAddr(peerSockaddr) +# if +# HMAC(EVP_sha1(), +# addr cookieSecret[0], cint(cookieSecret.len), +# cast[cstring](addr transportAddress), csize_t(sizeof(TransportAddress)), +# cast[cstring](cookie), cast[ptr cuint](cookieLen)) == nil: +# 0 +# else: +# 1 +# +# proc verifySslCookie(ssl: SslPtr, cookie: ptr byte, cookieLen: int): int {.cdecl.} = +# var peerSockaddr: Sockaddr_storage +# if BIO_ctrl(SSL_get_rbio(ssl), BIO_CTRL_DGRAM_GET_PEER, 0, cast[cstring](addr peerSockaddr)) <= 0: +# return 0 +# +# let transportAddress = fromSAddr(peerSockaddr) +# var +# buffer: array[1024, byte] +# bufferLength: cuint +# if +# HMAC(EVP_sha1(), +# addr cookieSecret[0], cint(cookieSecret.len), +# cast[cstring](addr transportAddress), csize_t(sizeof(TransportAddress)), +# cast[cstring](addr buffer[0]), addr bufferLength) == nil: +# return 0 +# +# if bufferLength != cuint(cookieLen): return 0 +# if cookie.makeOpenArray(byte, cookieLen) == buffer[0 ..< bufferLength]: +# 1 +# else: +# 0 +# +# proc createDtlsSocket( +# localAddress = AnyAddress, +# remoteAddress = AnyAddress, +# flags: set[ServerFlags] = {NoAutoRead}): DtlsSocket = +# +# let gotData = newAsyncEvent() +# proc callback(transp: DatagramTransport, remote: TransportAddress) {.async.} = discard +# proc callback2(udata: pointer) = +# gotData.fire() +# let datagram = newDatagramTransport( +# callback, +# local = localAddress, +# remote = remoteAddress, +# flags = flags) +# addReader(datagram.fd, callback2) +# return DtlsSocket(udp: datagram, gotData: gotData) +# +# +# proc createDtlsServer*(host: TransportAddress): Future[DtlsSocket] {.async.} = +# result = createDtlsSocket( +# localAddress = host, +# flags = {NoAutoRead, ReuseAddr} +# ) +# +# result.sslCtx = SSL_CTX_new(DTLS_server_method()) +# #TODO if we close the server with connections alive, +# #they have a ref to this ctx +# +# #TODO handle certificates +# echo SSL_CTX_use_certificate_file(result.sslCtx, "certs/server-cert.pem", SSL_FILETYPE_PEM) +# echo SSL_CTX_use_PrivateKey_file(result.sslCtx, "certs/server-key.pem", SSL_FILETYPE_PEM) +# SSL_CTX_set_cookie_generate_cb(result.sslCtx, generateSslCookie) +# SSL_CTX_set_cookie_verify_cb(result.sslCtx, verifySslCookie) +# +# proc accept*(sock: DtlsSocket): Future[DtlsSocket] {.async.} = +# let +# ctx = sock.sslCtx +# ssl = SSL_new(ctx) +# bio = BIO_new_dgram(SocketHandle(sock.udp.fd), BIO_NOCLOSE) +# +# sslSetBio(ssl, bio, bio) +# +# var clientSockAddr: Sockaddr_storage +# doAssert isNil(sock.ssl) +# sock.ssl = ssl +# wrapSslCall(sock, DTLSv1_listen(ssl, addr clientSockAddr)) +# sock.ssl = nil +# let clientAddr = fromSAddr(clientSockAddr) +# +# # create new socket +# result = createDtlsSocket( +# localAddress = sock.udp.localAddress, +# remoteAddress = clientAddr, +# flags = {NoAutoRead, ReuseAddr} +# ) +# +# let sockHandle = SocketHandle(result.udp.fd) +# doAssert BIO_ctrl(bio, BIO_C_SET_FD, 0, cast[cstring](addr sockHandle)) > 0 +# doAssert BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_CONNECTED, 0, cast[cstring](addr clientSockAddr)) > 0 +# +# result.sslCtx = ctx +# result.ssl = ssl +# result.ctxIsView = true +# wrapSslCall(result, SSL_accept(ssl)) +# +# proc connect*(address: TransportAddress): Future[DtlsSocket] {.async.} = +# result = createDtlsSocket( +# remoteAddress = address +# ) +# +# let +# ctx = SSL_CTX_new(DTLS_client_method()) +# ssl = SSL_new(ctx) +# bio = BIO_new_dgram(SocketHandle(result.udp.fd), BIO_NOCLOSE) +# +# #TODO handle certs +# echo SSL_CTX_use_certificate_file(ctx, "certs/client-cert.pem", SSL_FILETYPE_PEM) +# echo SSL_CTX_use_PrivateKey_file(ctx, "certs/client-key.pem", SSL_FILETYPE_PEM) +# echo SSL_CTX_check_private_key(ctx) +# +# result.sslCtx = ctx +# result.ssl = ssl +# var slen: SockLen +# var remoteSaddr: Sockaddr_storage +# toSAddr(address, remoteSaddr, slen) +# doAssert BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_CONNECTED, 0, cast[cstring](addr remoteSaddr)) > 0 +# sslSetBio(ssl, bio, bio) +# wrapSslCall(result, SSL_connect(ssl)) +# +# proc write*(sock: DtlsSocket, data: seq[byte]) {.async.} = +# wrapSslCall(sock, SSL_write(sock.ssl, cast[cstring](addr data[0]), data.len)) +# +# proc read*(sock: DtlsSocket): Future[seq[byte]] {.async.} = +# result = newSeq[byte](1000) +# let length = wrapSslCallRes(sock, SSL_read(sock.ssl, cast[cstring](addr result[0]), result.len)) +# result.setLen(length) +# +# proc close*(sock: DtlsSocket) {.async.} = +# if not isNil(sock.ssl): +# let shutdownRes = SSL_shutdown(sock.ssl) +# if shutdownRes == 0: +# wrapSslCall(sock, SSL_shutdown(sock.ssl)) +# SSL_free(sock.ssl) +# if not isNil(sock.sslCtx) and not sock.ctxIsView: +# SSL_CTX_free(sock.sslCtx) +# sock.udp.close() +# +# proc main {.async.} = +# let +# address = initTAddress("127.0.0.1:8090") +# server = await createDtlsServer(address) +# client = connect(address) +# +# let +# servConn = await server.accept() +# clientConn = await client +# await clientConn.write("Hello world!".toBytes()) +# echo string.fromBytes(await servConn.read()) +# +# await allFutures(servConn.close(), clientConn.close()) +# await server.close() +# +# waitFor(main()) diff --git a/webrtc/utils.nim b/webrtc/utils.nim index 0e75d4c..1e0ddf2 100644 --- a/webrtc/utils.nim +++ b/webrtc/utils.nim @@ -1,4 +1,13 @@ -import strutils, bitops +# Nim-WebRTC +# Copyright (c) 2023 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +# * MIT license ([LICENSE-MIT](LICENSE-MIT)) +# at your option. +# This file may not be copied, modified, or distributed except according to +# those terms. + +import std/sha1, sequtils, typetraits, std/md5 proc createCrc32Table(): array[0..255, uint32] = for i in 0..255: @@ -14,3 +23,24 @@ proc crc32*(s: seq[byte]): uint32 = for c in s: result = (result shr 8) xor crc32table[(result and 0xff) xor c] result = not result + +proc hmacSha1*(key: seq[byte], msg: seq[byte]): seq[byte] = + let + keyPadded = + if len(key) > 64: + @(secureHash(key.mapIt(it.chr)).distinctBase) + elif key.len() < 64: + key.concat(newSeq[byte](64 - key.len())) + else: + key + innerHash = keyPadded. + mapIt(it xor 0x36'u8). + concat(msg). + mapIt(it.chr). + secureHash() + outerHash = keyPadded. + mapIt(it xor 0x5c'u8). + concat(@(innerHash.distinctBase)). + mapIt(it.chr). + secureHash() + return @(outerHash.distinctBase) From d4aab29d746e8320a240f7f4b38d696dc82896d0 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 12 May 2023 16:50:59 +0200 Subject: [PATCH 11/66] mbedtls nearly wrapped --- webrtc/mbedtls/aes.nim | 96 ++ webrtc/mbedtls/aria.nim | 58 ++ webrtc/mbedtls/asn1.nim | 118 +++ webrtc/mbedtls/asn1write.nim | 69 ++ webrtc/mbedtls/base64.nim | 34 + webrtc/mbedtls/bignum.nim | 195 ++++ webrtc/mbedtls/build_info.nim | 27 + webrtc/mbedtls/camellia.nim | 59 ++ webrtc/mbedtls/ccm.nim | 88 ++ webrtc/mbedtls/chacha20.nim | 44 + webrtc/mbedtls/chachapoly.nim | 108 +++ webrtc/mbedtls/check_config.nim | 22 + webrtc/mbedtls/cipher.nim | 319 +++++++ webrtc/mbedtls/cmac.nim | 50 + webrtc/mbedtls/compat_2_x.nim | 42 + webrtc/mbedtls/config_psa.nim | 27 + webrtc/mbedtls/constant_time.nim | 23 + webrtc/mbedtls/ctr_drbg.nim | 92 ++ webrtc/mbedtls/debug.nim | 128 +++ webrtc/mbedtls/des.nim | 81 ++ webrtc/mbedtls/dhm.nim | 144 +++ webrtc/mbedtls/ecdh.nim | 128 +++ webrtc/mbedtls/ecdsa.nim | 97 ++ webrtc/mbedtls/ecjpake.nim | 124 +++ webrtc/mbedtls/ecp.nim | 256 +++++ webrtc/mbedtls/entropy.nim | 81 ++ webrtc/mbedtls/error.nim | 35 + webrtc/mbedtls/gcm.nim | 75 ++ webrtc/mbedtls/hash_info.nim | 3 + webrtc/mbedtls/hkdf.nim | 41 + webrtc/mbedtls/hmac_drbg.nim | 88 ++ webrtc/mbedtls/lms.nim | 114 +++ webrtc/mbedtls/mbedtls_config.nim | 26 + webrtc/mbedtls/md.nim | 140 +++ webrtc/mbedtls/md5.nim | 43 + webrtc/mbedtls/memory_buffer_alloc.nim | 39 + webrtc/mbedtls/net_sockets.nim | 101 ++ webrtc/mbedtls/nist_kw.nim | 94 ++ webrtc/mbedtls/oid.nim | 267 ++++++ webrtc/mbedtls/pem.nim | 52 + webrtc/mbedtls/pk.nim | 226 +++++ webrtc/mbedtls/pkcs12.nim | 47 + webrtc/mbedtls/pkcs5.nim | 50 + webrtc/mbedtls/pkcs7.nim | 135 +++ webrtc/mbedtls/platform.nim | 60 ++ webrtc/mbedtls/platform_time.nim | 34 + webrtc/mbedtls/platform_util.nim | 32 + webrtc/mbedtls/poly1305.nim | 45 + webrtc/mbedtls/private_access.nim | 20 + webrtc/mbedtls/psa/crypto.nim | 651 +++++++++++++ .../mbedtls/psa/crypto_builtin_composites.nim | 34 + .../mbedtls/psa/crypto_builtin_primitives.nim | 28 + webrtc/mbedtls/psa/crypto_compat.nim | 20 + webrtc/mbedtls/psa/crypto_config.nim | 83 ++ webrtc/mbedtls/psa/crypto_driver_common.nim | 71 ++ .../psa/crypto_driver_contexts_composites.nim | 27 + .../crypto_driver_contexts_key_derivation.nim | 26 + .../psa/crypto_driver_contexts_primitives.nim | 27 + webrtc/mbedtls/psa/crypto_extra.nim | 23 + webrtc/mbedtls/psa/crypto_platform.nim | 22 + webrtc/mbedtls/psa/crypto_se_driver.nim | 260 +++++ webrtc/mbedtls/psa/crypto_sizes.nim | 45 + webrtc/mbedtls/psa/crypto_struct.nim | 105 ++ webrtc/mbedtls/psa/crypto_types.nim | 347 +++++++ webrtc/mbedtls/psa/crypto_values.nim | 210 ++++ webrtc/mbedtls/psa_util.nim | 53 ++ webrtc/mbedtls/ripemd160.nim | 47 + webrtc/mbedtls/rsa.nim | 177 ++++ webrtc/mbedtls/sha1.nim | 45 + webrtc/mbedtls/sha256.nim | 48 + webrtc/mbedtls/sha512.nim | 48 + webrtc/mbedtls/ssl.nim | 893 ++++++++++++++++++ webrtc/mbedtls/ssl_cache.nim | 90 ++ webrtc/mbedtls/ssl_ciphersuites.nim | 319 +++++++ webrtc/mbedtls/ssl_cookie.nim | 72 ++ webrtc/mbedtls/ssl_ticket.nim | 86 ++ webrtc/mbedtls/threading.nim | 28 + webrtc/mbedtls/timing.nim | 42 + webrtc/mbedtls/version.nim | 30 + webrtc/mbedtls/x509.nim | 239 +++++ webrtc/mbedtls/x509_crl.nim | 72 ++ webrtc/mbedtls/x509_crt.nim | 214 +++++ webrtc/mbedtls/x509_csr.nim | 105 ++ 83 files changed, 8864 insertions(+) create mode 100644 webrtc/mbedtls/aes.nim create mode 100644 webrtc/mbedtls/aria.nim create mode 100644 webrtc/mbedtls/asn1.nim create mode 100644 webrtc/mbedtls/asn1write.nim create mode 100644 webrtc/mbedtls/base64.nim create mode 100644 webrtc/mbedtls/bignum.nim create mode 100644 webrtc/mbedtls/build_info.nim create mode 100644 webrtc/mbedtls/camellia.nim create mode 100644 webrtc/mbedtls/ccm.nim create mode 100644 webrtc/mbedtls/chacha20.nim create mode 100644 webrtc/mbedtls/chachapoly.nim create mode 100644 webrtc/mbedtls/check_config.nim create mode 100644 webrtc/mbedtls/cipher.nim create mode 100644 webrtc/mbedtls/cmac.nim create mode 100644 webrtc/mbedtls/compat_2_x.nim create mode 100644 webrtc/mbedtls/config_psa.nim create mode 100644 webrtc/mbedtls/constant_time.nim create mode 100644 webrtc/mbedtls/ctr_drbg.nim create mode 100644 webrtc/mbedtls/debug.nim create mode 100644 webrtc/mbedtls/des.nim create mode 100644 webrtc/mbedtls/dhm.nim create mode 100644 webrtc/mbedtls/ecdh.nim create mode 100644 webrtc/mbedtls/ecdsa.nim create mode 100644 webrtc/mbedtls/ecjpake.nim create mode 100644 webrtc/mbedtls/ecp.nim create mode 100644 webrtc/mbedtls/entropy.nim create mode 100644 webrtc/mbedtls/error.nim create mode 100644 webrtc/mbedtls/gcm.nim create mode 100644 webrtc/mbedtls/hash_info.nim create mode 100644 webrtc/mbedtls/hkdf.nim create mode 100644 webrtc/mbedtls/hmac_drbg.nim create mode 100644 webrtc/mbedtls/lms.nim create mode 100644 webrtc/mbedtls/mbedtls_config.nim create mode 100644 webrtc/mbedtls/md.nim create mode 100644 webrtc/mbedtls/md5.nim create mode 100644 webrtc/mbedtls/memory_buffer_alloc.nim create mode 100644 webrtc/mbedtls/net_sockets.nim create mode 100644 webrtc/mbedtls/nist_kw.nim create mode 100644 webrtc/mbedtls/oid.nim create mode 100644 webrtc/mbedtls/pem.nim create mode 100644 webrtc/mbedtls/pk.nim create mode 100644 webrtc/mbedtls/pkcs12.nim create mode 100644 webrtc/mbedtls/pkcs5.nim create mode 100644 webrtc/mbedtls/pkcs7.nim create mode 100644 webrtc/mbedtls/platform.nim create mode 100644 webrtc/mbedtls/platform_time.nim create mode 100644 webrtc/mbedtls/platform_util.nim create mode 100644 webrtc/mbedtls/poly1305.nim create mode 100644 webrtc/mbedtls/private_access.nim create mode 100644 webrtc/mbedtls/psa/crypto.nim create mode 100644 webrtc/mbedtls/psa/crypto_builtin_composites.nim create mode 100644 webrtc/mbedtls/psa/crypto_builtin_primitives.nim create mode 100644 webrtc/mbedtls/psa/crypto_compat.nim create mode 100644 webrtc/mbedtls/psa/crypto_config.nim create mode 100644 webrtc/mbedtls/psa/crypto_driver_common.nim create mode 100644 webrtc/mbedtls/psa/crypto_driver_contexts_composites.nim create mode 100644 webrtc/mbedtls/psa/crypto_driver_contexts_key_derivation.nim create mode 100644 webrtc/mbedtls/psa/crypto_driver_contexts_primitives.nim create mode 100644 webrtc/mbedtls/psa/crypto_extra.nim create mode 100644 webrtc/mbedtls/psa/crypto_platform.nim create mode 100644 webrtc/mbedtls/psa/crypto_se_driver.nim create mode 100644 webrtc/mbedtls/psa/crypto_sizes.nim create mode 100644 webrtc/mbedtls/psa/crypto_struct.nim create mode 100644 webrtc/mbedtls/psa/crypto_types.nim create mode 100644 webrtc/mbedtls/psa/crypto_values.nim create mode 100644 webrtc/mbedtls/psa_util.nim create mode 100644 webrtc/mbedtls/ripemd160.nim create mode 100644 webrtc/mbedtls/rsa.nim create mode 100644 webrtc/mbedtls/sha1.nim create mode 100644 webrtc/mbedtls/sha256.nim create mode 100644 webrtc/mbedtls/sha512.nim create mode 100644 webrtc/mbedtls/ssl.nim create mode 100644 webrtc/mbedtls/ssl_cache.nim create mode 100644 webrtc/mbedtls/ssl_ciphersuites.nim create mode 100644 webrtc/mbedtls/ssl_cookie.nim create mode 100644 webrtc/mbedtls/ssl_ticket.nim create mode 100644 webrtc/mbedtls/threading.nim create mode 100644 webrtc/mbedtls/timing.nim create mode 100644 webrtc/mbedtls/version.nim create mode 100644 webrtc/mbedtls/x509.nim create mode 100644 webrtc/mbedtls/x509_crl.nim create mode 100644 webrtc/mbedtls/x509_crt.nim create mode 100644 webrtc/mbedtls/x509_csr.nim diff --git a/webrtc/mbedtls/aes.nim b/webrtc/mbedtls/aes.nim new file mode 100644 index 0000000..73cfa32 --- /dev/null +++ b/webrtc/mbedtls/aes.nim @@ -0,0 +1,96 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} + +# Included but not used +# import "private_access" +# import "build_info" +# import "mbedtls_config" +# import "config_psa" +# import "check_config" +# import "platform_time" +import "platform_time" +{.compile: "./mbedtls/library/aes.c".} +{.compile: "./mbedtls/library/aesni.c".} +# Generated @ 2023-05-11T11:19:07+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/aes.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_AES_ENCRYPT* = 1 + MBEDTLS_AES_DECRYPT* = 0 + MBEDTLS_ERR_AES_INVALID_KEY_LENGTH* = -0x00000020 + MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH* = -0x00000022 + MBEDTLS_ERR_AES_BAD_INPUT_DATA* = -0x00000021 +type + mbedtls_aes_context* {.bycopy.} = object + private_nr*: cint + private_rk_offset*: uint + private_buf*: array[68, uint32] + + mbedtls_aes_xts_context* {.bycopy.} = object + private_crypt*: mbedtls_aes_context + private_tweak*: mbedtls_aes_context + +proc mbedtls_aes_init*(ctx: ptr mbedtls_aes_context) {.importc, cdecl.} +proc mbedtls_aes_free*(ctx: ptr mbedtls_aes_context) {.importc, cdecl.} +proc mbedtls_aes_xts_init*(ctx: ptr mbedtls_aes_xts_context) {.importc, cdecl.} +proc mbedtls_aes_xts_free*(ctx: ptr mbedtls_aes_xts_context) {.importc, cdecl.} +proc mbedtls_aes_setkey_enc*(ctx: ptr mbedtls_aes_context; key: ptr byte; + keybits: cuint): cint {.importc, cdecl.} +proc mbedtls_aes_setkey_dec*(ctx: ptr mbedtls_aes_context; key: ptr byte; + keybits: cuint): cint {.importc, cdecl.} +proc mbedtls_aes_xts_setkey_enc*(ctx: ptr mbedtls_aes_xts_context; + key: ptr byte; keybits: cuint): cint {. + importc, cdecl.} +proc mbedtls_aes_xts_setkey_dec*(ctx: ptr mbedtls_aes_xts_context; + key: ptr byte; keybits: cuint): cint {. + importc, cdecl.} +proc mbedtls_aes_crypt_ecb*(ctx: ptr mbedtls_aes_context; mode: cint; + input: array[16, byte]; output: array[16, byte]): cint {. + importc, cdecl.} +proc mbedtls_aes_crypt_cbc*(ctx: ptr mbedtls_aes_context; mode: cint; + length: uint; iv: array[16, byte]; + input: ptr byte; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_aes_crypt_xts*(ctx: ptr mbedtls_aes_xts_context; mode: cint; + length: uint; data_unit: array[16, byte]; + input: ptr byte; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_aes_crypt_cfb128*(ctx: ptr mbedtls_aes_context; mode: cint; + length: uint; iv_off: ptr uint; + iv: array[16, byte]; input: ptr byte; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_aes_crypt_cfb8*(ctx: ptr mbedtls_aes_context; mode: cint; + length: uint; iv: array[16, byte]; + input: ptr byte; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_aes_crypt_ofb*(ctx: ptr mbedtls_aes_context; length: uint; + iv_off: ptr uint; iv: array[16, byte]; + input: ptr byte; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_aes_crypt_ctr*(ctx: ptr mbedtls_aes_context; length: uint; + nc_off: ptr uint; nonce_counter: array[16, byte]; + stream_block: array[16, byte]; input: ptr byte; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_internal_aes_encrypt*(ctx: ptr mbedtls_aes_context; + input: array[16, byte]; + output: array[16, byte]): cint {.importc, + cdecl.} +proc mbedtls_internal_aes_decrypt*(ctx: ptr mbedtls_aes_context; + input: array[16, byte]; + output: array[16, byte]): cint {.importc, + cdecl.} +proc mbedtls_aes_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/aria.nim b/webrtc/mbedtls/aria.nim new file mode 100644 index 0000000..8930d13 --- /dev/null +++ b/webrtc/mbedtls/aria.nim @@ -0,0 +1,58 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "platform_time" +{.compile: "./mbedtls/library/aria.c".} +# Generated @ 2023-05-11T11:19:07+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/aria.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ARIA_ENCRYPT* = 1 + MBEDTLS_ARIA_DECRYPT* = 0 + MBEDTLS_ARIA_BLOCKSIZE* = 16 + MBEDTLS_ARIA_MAX_ROUNDS* = 16 + MBEDTLS_ARIA_MAX_KEYSIZE* = 32 + MBEDTLS_ERR_ARIA_BAD_INPUT_DATA* = -0x0000005C + MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH* = -0x0000005E +type + mbedtls_aria_context* {.bycopy.} = object + private_nr*: byte + private_rk*: array[16 + typeof(16)(1), + array[typeof(16)(16 / typeof(16)(4)), uint32]] + +proc mbedtls_aria_init*(ctx: ptr mbedtls_aria_context) {.importc, cdecl.} +proc mbedtls_aria_free*(ctx: ptr mbedtls_aria_context) {.importc, cdecl.} +proc mbedtls_aria_setkey_enc*(ctx: ptr mbedtls_aria_context; key: ptr byte; + keybits: cuint): cint {.importc, cdecl.} +proc mbedtls_aria_setkey_dec*(ctx: ptr mbedtls_aria_context; key: ptr byte; + keybits: cuint): cint {.importc, cdecl.} +proc mbedtls_aria_crypt_ecb*(ctx: ptr mbedtls_aria_context; + input: array[16, byte]; output: array[16, byte]): cint {. + importc, cdecl.} +proc mbedtls_aria_crypt_cbc*(ctx: ptr mbedtls_aria_context; mode: cint; + length: uint; iv: array[16, byte]; + input: ptr byte; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_aria_crypt_cfb128*(ctx: ptr mbedtls_aria_context; mode: cint; + length: uint; iv_off: ptr uint; + iv: array[16, byte]; input: ptr byte; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_aria_crypt_ctr*(ctx: ptr mbedtls_aria_context; length: uint; + nc_off: ptr uint; nonce_counter: array[16, byte]; + stream_block: array[16, byte]; input: ptr byte; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_aria_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/asn1.nim b/webrtc/mbedtls/asn1.nim new file mode 100644 index 0000000..6912d77 --- /dev/null +++ b/webrtc/mbedtls/asn1.nim @@ -0,0 +1,118 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "bignum" +{.compile: "./mbedtls/library/asn1parse.c".} +# Generated @ 2023-05-11T11:19:07+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/asn1.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_ASN1_OUT_OF_DATA* = -0x00000060 + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG* = -0x00000062 + MBEDTLS_ERR_ASN1_INVALID_LENGTH* = -0x00000064 + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH* = -0x00000066 + MBEDTLS_ERR_ASN1_INVALID_DATA* = -0x00000068 + MBEDTLS_ERR_ASN1_ALLOC_FAILED* = -0x0000006A + MBEDTLS_ERR_ASN1_BUF_TOO_SMALL* = -0x0000006C + MBEDTLS_ASN1_BOOLEAN* = 0x00000001 + MBEDTLS_ASN1_INTEGER* = 0x00000002 + MBEDTLS_ASN1_BIT_STRING* = 0x00000003 + MBEDTLS_ASN1_OCTET_STRING* = 0x00000004 + MBEDTLS_ASN1_NULL* = 0x00000005 + MBEDTLS_ASN1_OID* = 0x00000006 + MBEDTLS_ASN1_ENUMERATED* = 0x0000000A + MBEDTLS_ASN1_UTF8_STRING* = 0x0000000C + MBEDTLS_ASN1_SEQUENCE* = 0x00000010 + MBEDTLS_ASN1_SET* = 0x00000011 + MBEDTLS_ASN1_PRINTABLE_STRING* = 0x00000013 + MBEDTLS_ASN1_T61_STRING* = 0x00000014 + MBEDTLS_ASN1_IA5_STRING* = 0x00000016 + MBEDTLS_ASN1_UTC_TIME* = 0x00000017 + MBEDTLS_ASN1_GENERALIZED_TIME* = 0x00000018 + MBEDTLS_ASN1_UNIVERSAL_STRING* = 0x0000001C + MBEDTLS_ASN1_BMP_STRING* = 0x0000001E + MBEDTLS_ASN1_PRIMITIVE* = 0x00000000 + MBEDTLS_ASN1_CONSTRUCTED* = 0x00000020 + MBEDTLS_ASN1_CONTEXT_SPECIFIC* = 0x00000080 + MBEDTLS_ASN1_TAG_CLASS_MASK* = 0x000000C0 + MBEDTLS_ASN1_TAG_PC_MASK* = 0x00000020 + MBEDTLS_ASN1_TAG_VALUE_MASK* = 0x0000001F +type + mbedtls_asn1_buf* {.bycopy.} = object + tag*: cint + len*: uint + p*: ptr byte + + mbedtls_asn1_bitstring* {.bycopy.} = object + len*: uint + unused_bits*: byte + p*: ptr byte + + mbedtls_asn1_sequence* {.bycopy.} = object + buf*: mbedtls_asn1_buf + next*: ptr mbedtls_asn1_sequence + + mbedtls_asn1_named_data* {.bycopy.} = object + oid*: mbedtls_asn1_buf + val*: mbedtls_asn1_buf + next*: ptr mbedtls_asn1_named_data + private_next_merged*: byte + +proc mbedtls_asn1_get_len*(p: ptr ptr byte; `end`: ptr byte; len: ptr uint): cint {. + importc, cdecl.} +proc mbedtls_asn1_get_tag*(p: ptr ptr byte; `end`: ptr byte; len: ptr uint; + tag: cint): cint {.importc, cdecl.} +proc mbedtls_asn1_get_bool*(p: ptr ptr byte; `end`: ptr byte; val: ptr cint): cint {. + importc, cdecl.} +proc mbedtls_asn1_get_int*(p: ptr ptr byte; `end`: ptr byte; val: ptr cint): cint {. + importc, cdecl.} +proc mbedtls_asn1_get_enum*(p: ptr ptr byte; `end`: ptr byte; val: ptr cint): cint {. + importc, cdecl.} +proc mbedtls_asn1_get_bitstring*(p: ptr ptr byte; `end`: ptr byte; + bs: ptr mbedtls_asn1_bitstring): cint {. + importc, cdecl.} +proc mbedtls_asn1_get_bitstring_null*(p: ptr ptr byte; `end`: ptr byte; + len: ptr uint): cint {.importc, cdecl.} +proc mbedtls_asn1_get_sequence_of*(p: ptr ptr byte; `end`: ptr byte; + cur: ptr mbedtls_asn1_sequence; tag: cint): cint {. + importc, cdecl.} +proc mbedtls_asn1_sequence_free*(seq: ptr mbedtls_asn1_sequence) {.importc, + cdecl.} +proc mbedtls_asn1_traverse_sequence_of*(p: ptr ptr byte; `end`: ptr byte; + tag_must_mask: byte; + tag_must_val: byte; + tag_may_mask: byte; + tag_may_val: byte; cb: proc ( + ctx: pointer; tag: cint; start: ptr byte; len: uint): cint {.cdecl.}; + ctx: pointer): cint {.importc, cdecl.} +proc mbedtls_asn1_get_mpi*(p: ptr ptr byte; `end`: ptr byte; + X: ptr mbedtls_mpi): cint {.importc, cdecl.} +proc mbedtls_asn1_get_alg*(p: ptr ptr byte; `end`: ptr byte; + alg: ptr mbedtls_asn1_buf; + params: ptr mbedtls_asn1_buf): cint {.importc, cdecl.} +proc mbedtls_asn1_get_alg_null*(p: ptr ptr byte; `end`: ptr byte; + alg: ptr mbedtls_asn1_buf): cint {.importc, + cdecl.} +proc mbedtls_asn1_find_named_data*(list: ptr mbedtls_asn1_named_data; + oid: cstring; len: uint): ptr mbedtls_asn1_named_data {. + importc, cdecl.} +proc mbedtls_asn1_free_named_data*(entry: ptr mbedtls_asn1_named_data) {. + importc, cdecl.} +proc mbedtls_asn1_free_named_data_list*(head: ptr ptr mbedtls_asn1_named_data) {. + importc, cdecl.} +proc mbedtls_asn1_free_named_data_list_shallow*( + name: ptr mbedtls_asn1_named_data) {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/asn1write.nim b/webrtc/mbedtls/asn1write.nim new file mode 100644 index 0000000..035c9e1 --- /dev/null +++ b/webrtc/mbedtls/asn1write.nim @@ -0,0 +1,69 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "asn1" +import "platform_time" +import "bignum" +{.compile: "./mbedtls/library/asn1write.c".} +# Generated @ 2023-05-11T11:19:07+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/asn1write.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +proc mbedtls_asn1_write_len*(p: ptr ptr byte; start: ptr byte; len: uint): cint {. + importc, cdecl.} +proc mbedtls_asn1_write_tag*(p: ptr ptr byte; start: ptr byte; tag: byte): cint {. + importc, cdecl.} +proc mbedtls_asn1_write_raw_buffer*(p: ptr ptr byte; start: ptr byte; + buf: ptr byte; size: uint): cint {. + importc, cdecl.} +proc mbedtls_asn1_write_mpi*(p: ptr ptr byte; start: ptr byte; + X: ptr mbedtls_mpi): cint {.importc, cdecl.} +proc mbedtls_asn1_write_null*(p: ptr ptr byte; start: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_asn1_write_oid*(p: ptr ptr byte; start: ptr byte; oid: cstring; + oid_len: uint): cint {.importc, cdecl.} +proc mbedtls_asn1_write_algorithm_identifier*(p: ptr ptr byte; + start: ptr byte; oid: cstring; oid_len: uint; par_len: uint): cint {. + importc, cdecl.} +proc mbedtls_asn1_write_bool*(p: ptr ptr byte; start: ptr byte; + boolean: cint): cint {.importc, cdecl.} +proc mbedtls_asn1_write_int*(p: ptr ptr byte; start: ptr byte; val: cint): cint {. + importc, cdecl.} +proc mbedtls_asn1_write_enum*(p: ptr ptr byte; start: ptr byte; val: cint): cint {. + importc, cdecl.} +proc mbedtls_asn1_write_tagged_string*(p: ptr ptr byte; start: ptr byte; + tag: cint; text: cstring; text_len: uint): cint {. + importc, cdecl.} +proc mbedtls_asn1_write_printable_string*(p: ptr ptr byte; start: ptr byte; + text: cstring; text_len: uint): cint {.importc, cdecl.} +proc mbedtls_asn1_write_utf8_string*(p: ptr ptr byte; start: ptr byte; + text: cstring; text_len: uint): cint {. + importc, cdecl.} +proc mbedtls_asn1_write_ia5_string*(p: ptr ptr byte; start: ptr byte; + text: cstring; text_len: uint): cint {. + importc, cdecl.} +proc mbedtls_asn1_write_bitstring*(p: ptr ptr byte; start: ptr byte; + buf: ptr byte; bits: uint): cint {.importc, + cdecl.} +proc mbedtls_asn1_write_named_bitstring*(p: ptr ptr byte; start: ptr byte; + buf: ptr byte; bits: uint): cint {.importc, cdecl.} +proc mbedtls_asn1_write_octet_string*(p: ptr ptr byte; start: ptr byte; + buf: ptr byte; size: uint): cint {. + importc, cdecl.} +proc mbedtls_asn1_store_named_data*(list: ptr ptr mbedtls_asn1_named_data; + oid: cstring; oid_len: uint; + val: ptr byte; val_len: uint): ptr mbedtls_asn1_named_data {. + importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/base64.nim b/webrtc/mbedtls/base64.nim new file mode 100644 index 0000000..f652a61 --- /dev/null +++ b/webrtc/mbedtls/base64.nim @@ -0,0 +1,34 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +# import "build_info" +# import "mbedtls_config" +# import "config_psa" +# import "check_config" +import "constant_time" +{.compile: "./mbedtls/library/base64.c".} +# Generated @ 2023-05-11T11:19:07+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/base64.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL* = -0x0000002A + MBEDTLS_ERR_BASE64_INVALID_CHARACTER* = -0x0000002C +proc mbedtls_base64_encode*(dst: ptr byte; dlen: uint; olen: ptr uint; + src: ptr byte; slen: uint): cint {.importc, cdecl.} +proc mbedtls_base64_decode*(dst: ptr byte; dlen: uint; olen: ptr uint; + src: ptr byte; slen: uint): cint {.importc, cdecl.} +proc mbedtls_base64_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/bignum.nim b/webrtc/mbedtls/bignum.nim new file mode 100644 index 0000000..72e7eae --- /dev/null +++ b/webrtc/mbedtls/bignum.nim @@ -0,0 +1,195 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "md" +{.compile: "./mbedtls/library/bignum.c".} +{.compile: "./mbedtls/library/bignum_core.c".} +{.compile: "./mbedtls/library/constant_time.c".} +# Generated @ 2023-05-11T11:19:07+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/bignum.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(mbedtls_mpi_gen_prime_flag_t) +const + MBEDTLS_ERR_MPI_FILE_IO_ERROR* = -0x00000002 + MBEDTLS_ERR_MPI_BAD_INPUT_DATA* = -0x00000004 + MBEDTLS_ERR_MPI_INVALID_CHARACTER* = -0x00000006 + MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL* = -0x00000008 + MBEDTLS_ERR_MPI_NEGATIVE_VALUE* = -0x0000000A + MBEDTLS_ERR_MPI_DIVISION_BY_ZERO* = -0x0000000C + MBEDTLS_ERR_MPI_NOT_ACCEPTABLE* = -0x0000000E + MBEDTLS_ERR_MPI_ALLOC_FAILED* = -0x00000010 + MBEDTLS_MPI_MAX_LIMBS* = 10000 + MBEDTLS_MPI_WINDOW_SIZE* = 2 + MBEDTLS_MPI_MAX_SIZE* = 1024 + MBEDTLS_MPI_MAX_BITS* = (8 * typeof(8)(MBEDTLS_MPI_MAX_SIZE)) + MBEDTLS_MPI_MAX_BITS_SCALE100* = (100 * typeof(100)(MBEDTLS_MPI_MAX_BITS)) + MBEDTLS_LN_2_DIV_LN_10_SCALE100* = 332 + MBEDTLS_MPI_RW_BUFFER_SIZE* = ((typeof(MBEDTLS_MPI_MAX_BITS_SCALE100)((MBEDTLS_MPI_MAX_BITS_SCALE100 + + typeof(MBEDTLS_MPI_MAX_BITS_SCALE100)(MBEDTLS_LN_2_DIV_LN_10_SCALE100) - + typeof(MBEDTLS_MPI_MAX_BITS_SCALE100)(1)) / + typeof(MBEDTLS_MPI_MAX_BITS_SCALE100)(MBEDTLS_LN_2_DIV_LN_10_SCALE100))) + + typeof(MBEDTLS_MPI_MAX_BITS_SCALE100)(10) + + typeof(MBEDTLS_MPI_MAX_BITS_SCALE100)(6)) + MBEDTLS_MPI_GEN_PRIME_FLAG_DH* = (0x00000001).mbedtls_mpi_gen_prime_flag_t + MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR* = (0x00000002).mbedtls_mpi_gen_prime_flag_t +type + mbedtls_mpi_sint* = int64 + mbedtls_mpi_uint* = uint64 + mbedtls_t_udbl* = cuint + mbedtls_mpi* {.bycopy.} = object + private_s*: cint + private_n*: uint + private_p*: ptr mbedtls_mpi_uint + +proc mbedtls_mpi_init*(X: ptr mbedtls_mpi) {.importc, cdecl.} +proc mbedtls_mpi_free*(X: ptr mbedtls_mpi) {.importc, cdecl.} +proc mbedtls_mpi_grow*(X: ptr mbedtls_mpi; nblimbs: uint): cint {.importc, cdecl.} +proc mbedtls_mpi_shrink*(X: ptr mbedtls_mpi; nblimbs: uint): cint {.importc, + cdecl.} +proc mbedtls_mpi_copy*(X: ptr mbedtls_mpi; Y: ptr mbedtls_mpi): cint {.importc, + cdecl.} +proc mbedtls_mpi_swap*(X: ptr mbedtls_mpi; Y: ptr mbedtls_mpi) {.importc, cdecl.} +proc mbedtls_mpi_safe_cond_assign*(X: ptr mbedtls_mpi; Y: ptr mbedtls_mpi; + assign: byte): cint {.importc, cdecl.} +proc mbedtls_mpi_safe_cond_swap*(X: ptr mbedtls_mpi; Y: ptr mbedtls_mpi; + swap: byte): cint {.importc, cdecl.} +proc mbedtls_mpi_lset*(X: ptr mbedtls_mpi; z: mbedtls_mpi_sint): cint {.importc, + cdecl.} +proc mbedtls_mpi_get_bit*(X: ptr mbedtls_mpi; pos: uint): cint {.importc, cdecl.} +proc mbedtls_mpi_set_bit*(X: ptr mbedtls_mpi; pos: uint; val: byte): cint {. + importc, cdecl.} +proc mbedtls_mpi_lsb*(X: ptr mbedtls_mpi): uint {.importc, cdecl.} +proc mbedtls_mpi_bitlen*(X: ptr mbedtls_mpi): uint {.importc, cdecl.} +proc mbedtls_mpi_size*(X: ptr mbedtls_mpi): uint {.importc, cdecl.} +proc mbedtls_mpi_read_string*(X: ptr mbedtls_mpi; radix: cint; s: cstring): cint {. + importc, cdecl.} +proc mbedtls_mpi_write_string*(X: ptr mbedtls_mpi; radix: cint; buf: cstring; + buflen: uint; olen: ptr uint): cint {.importc, + cdecl.} +proc mbedtls_mpi_read_file*(X: ptr mbedtls_mpi; radix: cint; fin: File): cint {. + importc, cdecl.} +proc mbedtls_mpi_write_file*(p: cstring; X: ptr mbedtls_mpi; radix: cint; + fout: File): cint {.importc, cdecl.} +proc mbedtls_mpi_read_binary*(X: ptr mbedtls_mpi; buf: ptr byte; buflen: uint): cint {. + importc, cdecl.} +proc mbedtls_mpi_read_binary_le*(X: ptr mbedtls_mpi; buf: ptr byte; + buflen: uint): cint {.importc, cdecl.} +proc mbedtls_mpi_write_binary*(X: ptr mbedtls_mpi; buf: ptr byte; buflen: uint): cint {. + importc, cdecl.} +proc mbedtls_mpi_write_binary_le*(X: ptr mbedtls_mpi; buf: ptr byte; + buflen: uint): cint {.importc, cdecl.} +proc mbedtls_mpi_shift_l*(X: ptr mbedtls_mpi; count: uint): cint {.importc, + cdecl.} +proc mbedtls_mpi_shift_r*(X: ptr mbedtls_mpi; count: uint): cint {.importc, + cdecl.} +proc mbedtls_mpi_cmp_abs*(X: ptr mbedtls_mpi; Y: ptr mbedtls_mpi): cint {. + importc, cdecl.} +proc mbedtls_mpi_cmp_mpi*(X: ptr mbedtls_mpi; Y: ptr mbedtls_mpi): cint {. + importc, cdecl.} +proc mbedtls_mpi_lt_mpi_ct*(X: ptr mbedtls_mpi; Y: ptr mbedtls_mpi; + ret: ptr cuint): cint {.importc, cdecl.} +proc mbedtls_mpi_cmp_int*(X: ptr mbedtls_mpi; z: mbedtls_mpi_sint): cint {. + importc, cdecl.} +proc mbedtls_mpi_add_abs*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; + B: ptr mbedtls_mpi): cint {.importc, cdecl.} +proc mbedtls_mpi_sub_abs*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; + B: ptr mbedtls_mpi): cint {.importc, cdecl.} +proc mbedtls_mpi_add_mpi*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; + B: ptr mbedtls_mpi): cint {.importc, cdecl.} +proc mbedtls_mpi_sub_mpi*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; + B: ptr mbedtls_mpi): cint {.importc, cdecl.} +proc mbedtls_mpi_add_int*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; + b: mbedtls_mpi_sint): cint {.importc, cdecl.} +proc mbedtls_mpi_sub_int*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; + b: mbedtls_mpi_sint): cint {.importc, cdecl.} +proc mbedtls_mpi_mul_mpi*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; + B: ptr mbedtls_mpi): cint {.importc, cdecl.} +proc mbedtls_mpi_mul_int*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; + b: mbedtls_mpi_uint): cint {.importc, cdecl.} +proc mbedtls_mpi_div_mpi*(Q: ptr mbedtls_mpi; R: ptr mbedtls_mpi; + A: ptr mbedtls_mpi; B: ptr mbedtls_mpi): cint {. + importc, cdecl.} +proc mbedtls_mpi_div_int*(Q: ptr mbedtls_mpi; R: ptr mbedtls_mpi; + A: ptr mbedtls_mpi; b: mbedtls_mpi_sint): cint {. + importc, cdecl.} +proc mbedtls_mpi_mod_mpi*(R: ptr mbedtls_mpi; A: ptr mbedtls_mpi; + B: ptr mbedtls_mpi): cint {.importc, cdecl.} +proc mbedtls_mpi_mod_int*(r: ptr mbedtls_mpi_uint; A: ptr mbedtls_mpi; + b: mbedtls_mpi_sint): cint {.importc, cdecl.} +proc mbedtls_mpi_exp_mod*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; + E: ptr mbedtls_mpi; N: ptr mbedtls_mpi; + prec_RR: ptr mbedtls_mpi): cint {.importc, cdecl.} +proc mbedtls_mpi_fill_random*(X: ptr mbedtls_mpi; size: uint; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_mpi_random*(X: ptr mbedtls_mpi; min: mbedtls_mpi_sint; + N: ptr mbedtls_mpi; f_rng: proc (a1: pointer; + a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, + cdecl.} +proc mbedtls_mpi_gcd*(G: ptr mbedtls_mpi; A: ptr mbedtls_mpi; B: ptr mbedtls_mpi): cint {. + importc, cdecl.} +proc mbedtls_mpi_inv_mod*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; + N: ptr mbedtls_mpi): cint {.importc, cdecl.} +proc mbedtls_mpi_is_prime_ext*(X: ptr mbedtls_mpi; rounds: cint; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_mpi_gen_prime*(X: ptr mbedtls_mpi; nbits: uint; flags: cint; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_mpi_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/build_info.nim b/webrtc/mbedtls/build_info.nim new file mode 100644 index 0000000..1cf7e72 --- /dev/null +++ b/webrtc/mbedtls/build_info.nim @@ -0,0 +1,27 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +# Generated @ 2023-05-11T11:19:08+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/build_info.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_VERSION_MAJOR* = 3 + MBEDTLS_VERSION_MINOR* = 4 + MBEDTLS_VERSION_PATCH* = 0 + MBEDTLS_VERSION_NUMBER* = 0x03040000 + MBEDTLS_VERSION_STRING* = "3.4.0" + MBEDTLS_VERSION_STRING_FULL* = "mbed TLS 3.4.0" +{.pop.} diff --git a/webrtc/mbedtls/camellia.nim b/webrtc/mbedtls/camellia.nim new file mode 100644 index 0000000..d67bf18 --- /dev/null +++ b/webrtc/mbedtls/camellia.nim @@ -0,0 +1,59 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "platform_time" +{.compile: "./mbedtls/library/camellia.c".} +# Generated @ 2023-05-11T11:19:08+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/camellia.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_CAMELLIA_ENCRYPT* = 1 + MBEDTLS_CAMELLIA_DECRYPT* = 0 + MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA* = -0x00000024 + MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH* = -0x00000026 +type + mbedtls_camellia_context* {.bycopy.} = object + private_nr*: cint + private_rk*: array[68, uint32] + +proc mbedtls_camellia_init*(ctx: ptr mbedtls_camellia_context) {.importc, cdecl.} +proc mbedtls_camellia_free*(ctx: ptr mbedtls_camellia_context) {.importc, cdecl.} +proc mbedtls_camellia_setkey_enc*(ctx: ptr mbedtls_camellia_context; + key: ptr byte; keybits: cuint): cint {. + importc, cdecl.} +proc mbedtls_camellia_setkey_dec*(ctx: ptr mbedtls_camellia_context; + key: ptr byte; keybits: cuint): cint {. + importc, cdecl.} +proc mbedtls_camellia_crypt_ecb*(ctx: ptr mbedtls_camellia_context; mode: cint; + input: array[16, byte]; + output: array[16, byte]): cint {.importc, + cdecl.} +proc mbedtls_camellia_crypt_cbc*(ctx: ptr mbedtls_camellia_context; mode: cint; + length: uint; iv: array[16, byte]; + input: ptr byte; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_camellia_crypt_cfb128*(ctx: ptr mbedtls_camellia_context; + mode: cint; length: uint; iv_off: ptr uint; + iv: array[16, byte]; input: ptr byte; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_camellia_crypt_ctr*(ctx: ptr mbedtls_camellia_context; + length: uint; nc_off: ptr uint; + nonce_counter: array[16, byte]; + stream_block: array[16, byte]; + input: ptr byte; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_camellia_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/ccm.nim b/webrtc/mbedtls/ccm.nim new file mode 100644 index 0000000..8366a69 --- /dev/null +++ b/webrtc/mbedtls/ccm.nim @@ -0,0 +1,88 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +# import "private_access" +# import "build_info" +# import "mbedtls_config" +# import "config_psa" +# import "check_config" +import "cipher" +# import "platform_util" +import "platform_time" +# Generated @ 2023-05-11T11:19:08+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ccm.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_CCM_DECRYPT* = 0 + MBEDTLS_CCM_ENCRYPT* = 1 + MBEDTLS_CCM_STAR_DECRYPT* = 2 + MBEDTLS_CCM_STAR_ENCRYPT* = 3 + MBEDTLS_ERR_CCM_BAD_INPUT* = -0x0000000D + MBEDTLS_ERR_CCM_AUTH_FAILED* = -0x0000000F +type + mbedtls_ccm_context* {.bycopy.} = object + private_y*: array[16, byte] + private_ctr*: array[16, byte] + private_cipher_ctx*: mbedtls_cipher_context_t + private_plaintext_len*: uint + private_add_len*: uint + private_tag_len*: uint + private_processed*: uint + private_q*: byte + private_mode*: byte + private_state*: cint + +proc mbedtls_ccm_init*(ctx: ptr mbedtls_ccm_context) {.importc, cdecl.} +proc mbedtls_ccm_setkey*(ctx: ptr mbedtls_ccm_context; + cipher: mbedtls_cipher_id_t; key: ptr byte; + keybits: cuint): cint {.importc, cdecl.} +proc mbedtls_ccm_free*(ctx: ptr mbedtls_ccm_context) {.importc, cdecl.} +proc mbedtls_ccm_encrypt_and_tag*(ctx: ptr mbedtls_ccm_context; length: uint; + iv: ptr byte; iv_len: uint; ad: ptr byte; + ad_len: uint; input: ptr byte; + output: ptr byte; tag: ptr byte; + tag_len: uint): cint {.importc, cdecl.} +proc mbedtls_ccm_star_encrypt_and_tag*(ctx: ptr mbedtls_ccm_context; + length: uint; iv: ptr byte; + iv_len: uint; ad: ptr byte; + ad_len: uint; input: ptr byte; + output: ptr byte; tag: ptr byte; + tag_len: uint): cint {.importc, cdecl.} +proc mbedtls_ccm_auth_decrypt*(ctx: ptr mbedtls_ccm_context; length: uint; + iv: ptr byte; iv_len: uint; ad: ptr byte; + ad_len: uint; input: ptr byte; + output: ptr byte; tag: ptr byte; + tag_len: uint): cint {.importc, cdecl.} +proc mbedtls_ccm_star_auth_decrypt*(ctx: ptr mbedtls_ccm_context; length: uint; + iv: ptr byte; iv_len: uint; + ad: ptr byte; ad_len: uint; + input: ptr byte; output: ptr byte; + tag: ptr byte; tag_len: uint): cint {. + importc, cdecl.} +proc mbedtls_ccm_starts*(ctx: ptr mbedtls_ccm_context; mode: cint; + iv: ptr byte; iv_len: uint): cint {.importc, cdecl.} +proc mbedtls_ccm_set_lengths*(ctx: ptr mbedtls_ccm_context; total_ad_len: uint; + plaintext_len: uint; tag_len: uint): cint {. + importc, cdecl.} +proc mbedtls_ccm_update_ad*(ctx: ptr mbedtls_ccm_context; ad: ptr byte; + ad_len: uint): cint {.importc, cdecl.} +proc mbedtls_ccm_update*(ctx: ptr mbedtls_ccm_context; input: ptr byte; + input_len: uint; output: ptr byte; output_size: uint; + output_len: ptr uint): cint {.importc, cdecl.} +proc mbedtls_ccm_finish*(ctx: ptr mbedtls_ccm_context; tag: ptr byte; + tag_len: uint): cint {.importc, cdecl.} +proc mbedtls_ccm_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/chacha20.nim b/webrtc/mbedtls/chacha20.nim new file mode 100644 index 0000000..d9c5806 --- /dev/null +++ b/webrtc/mbedtls/chacha20.nim @@ -0,0 +1,44 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "platform_time" +{.compile: "./mbedtls/library/chacha20.c".} +# Generated @ 2023-05-11T11:19:08+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/chacha20.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA* = -0x00000051 +type + mbedtls_chacha20_context* {.bycopy.} = object + private_state*: array[16, uint32] + private_keystream8*: array[64, uint8] + private_keystream_bytes_used*: uint + +proc mbedtls_chacha20_init*(ctx: ptr mbedtls_chacha20_context) {.importc, cdecl.} +proc mbedtls_chacha20_free*(ctx: ptr mbedtls_chacha20_context) {.importc, cdecl.} +proc mbedtls_chacha20_setkey*(ctx: ptr mbedtls_chacha20_context; + key: array[32, byte]): cint {.importc, cdecl.} +proc mbedtls_chacha20_starts*(ctx: ptr mbedtls_chacha20_context; + nonce: array[12, byte]; counter: uint32): cint {. + importc, cdecl.} +proc mbedtls_chacha20_update*(ctx: ptr mbedtls_chacha20_context; size: uint; + input: ptr byte; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_chacha20_crypt*(key: array[32, byte]; nonce: array[12, byte]; + counter: uint32; size: uint; input: ptr byte; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_chacha20_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/chachapoly.nim b/webrtc/mbedtls/chachapoly.nim new file mode 100644 index 0000000..9cb4046 --- /dev/null +++ b/webrtc/mbedtls/chachapoly.nim @@ -0,0 +1,108 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "poly1305" +import "chacha20" +{.compile: "./mbedtls/library/chachapoly.c".} +# Generated @ 2023-05-11T11:19:08+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/chachapoly.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(mbedtls_chachapoly_mode_t) +const + MBEDTLS_ERR_CHACHAPOLY_BAD_STATE* = -0x00000054 + MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED* = -0x00000056 + MBEDTLS_CHACHAPOLY_ENCRYPT* = (0).mbedtls_chachapoly_mode_t + MBEDTLS_CHACHAPOLY_DECRYPT* = (MBEDTLS_CHACHAPOLY_ENCRYPT + 1).mbedtls_chachapoly_mode_t +type + mbedtls_chachapoly_context* {.bycopy.} = object + private_chacha20_ctx*: mbedtls_chacha20_context + private_poly1305_ctx*: mbedtls_poly1305_context + private_aad_len*: uint64 + private_ciphertext_len*: uint64 + private_state*: cint + private_mode*: mbedtls_chachapoly_mode_t + +proc mbedtls_chachapoly_init*(ctx: ptr mbedtls_chachapoly_context) {.importc, + cdecl.} +proc mbedtls_chachapoly_free*(ctx: ptr mbedtls_chachapoly_context) {.importc, + cdecl.} +proc mbedtls_chachapoly_setkey*(ctx: ptr mbedtls_chachapoly_context; + key: array[32, byte]): cint {.importc, cdecl.} +proc mbedtls_chachapoly_starts*(ctx: ptr mbedtls_chachapoly_context; + nonce: array[12, byte]; + mode: mbedtls_chachapoly_mode_t): cint {. + importc, cdecl.} +proc mbedtls_chachapoly_update_aad*(ctx: ptr mbedtls_chachapoly_context; + aad: ptr byte; aad_len: uint): cint {. + importc, cdecl.} +proc mbedtls_chachapoly_update*(ctx: ptr mbedtls_chachapoly_context; len: uint; + input: ptr byte; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_chachapoly_finish*(ctx: ptr mbedtls_chachapoly_context; + mac: array[16, byte]): cint {.importc, cdecl.} +proc mbedtls_chachapoly_encrypt_and_tag*(ctx: ptr mbedtls_chachapoly_context; + length: uint; nonce: array[12, byte]; aad: ptr byte; aad_len: uint; + input: ptr byte; output: ptr byte; tag: array[16, byte]): cint {. + importc, cdecl.} +proc mbedtls_chachapoly_auth_decrypt*(ctx: ptr mbedtls_chachapoly_context; + length: uint; nonce: array[12, byte]; + aad: ptr byte; aad_len: uint; + tag: array[16, byte]; input: ptr byte; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_chachapoly_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/check_config.nim b/webrtc/mbedtls/check_config.nim new file mode 100644 index 0000000..4e4b8f8 --- /dev/null +++ b/webrtc/mbedtls/check_config.nim @@ -0,0 +1,22 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +# Generated @ 2023-05-11T11:19:08+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/check_config.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +type + mbedtls_iso_c_forbids_empty_translation_units* = cint +{.pop.} diff --git a/webrtc/mbedtls/cipher.nim b/webrtc/mbedtls/cipher.nim new file mode 100644 index 0000000..4715188 --- /dev/null +++ b/webrtc/mbedtls/cipher.nim @@ -0,0 +1,319 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "aes" +import "aria" +import "camellia" +import "chachapoly" +import "des" +import "constant_time" +import "platform_time" +{.compile: "./mbedtls/library/ccm.c".} +{.compile: "./mbedtls/library/gcm.c".} +{.compile: "./mbedtls/library/nist_kw.c".} +{.compile: "./mbedtls/library/cipher_wrap.c".} +{.compile: "./mbedtls/library/cipher.c".} +# Generated @ 2023-05-11T11:19:08+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/cipher.h + +# proc 'mbedtls_cipher_info_get_type' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_cipher_info_get_mode' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_cipher_info_get_key_bitlen' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_cipher_info_get_name' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_cipher_info_get_iv_size' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_cipher_info_get_block_size' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_cipher_info_has_variable_key_bitlen' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_cipher_info_has_variable_iv_size' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_cipher_get_block_size' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_cipher_get_cipher_mode' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_cipher_get_iv_size' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_cipher_get_type' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_cipher_get_name' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_cipher_get_key_bitlen' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_cipher_get_operation' skipped - static inline procs cannot work with '--noHeader | -H' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(mbedtls_cipher_id_t) +defineEnum(mbedtls_cipher_type_t) +defineEnum(mbedtls_cipher_mode_t) +defineEnum(mbedtls_cipher_padding_t) +defineEnum(mbedtls_operation_t) +defineEnum(Enum_cipherh1) +const + MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE* = -0x00006080 + MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA* = -0x00006100 + MBEDTLS_ERR_CIPHER_ALLOC_FAILED* = -0x00006180 + MBEDTLS_ERR_CIPHER_INVALID_PADDING* = -0x00006200 + MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED* = -0x00006280 + MBEDTLS_ERR_CIPHER_AUTH_FAILED* = -0x00006300 + MBEDTLS_ERR_CIPHER_INVALID_CONTEXT* = -0x00006380 + MBEDTLS_CIPHER_VARIABLE_IV_LEN* = 0x00000001 + MBEDTLS_CIPHER_VARIABLE_KEY_LEN* = 0x00000002 + MBEDTLS_CIPHER_ID_NONE* = (0).mbedtls_cipher_id_t + MBEDTLS_CIPHER_ID_NULL* = (MBEDTLS_CIPHER_ID_NONE + 1).mbedtls_cipher_id_t + MBEDTLS_CIPHER_ID_AES* = (MBEDTLS_CIPHER_ID_NULL + 1).mbedtls_cipher_id_t + MBEDTLS_CIPHER_ID_DES* = (MBEDTLS_CIPHER_ID_AES + 1).mbedtls_cipher_id_t + MBEDTLS_CIPHER_ID_3DES* = (MBEDTLS_CIPHER_ID_DES + 1).mbedtls_cipher_id_t + MBEDTLS_CIPHER_ID_CAMELLIA* = (MBEDTLS_CIPHER_ID_3DES + 1).mbedtls_cipher_id_t + MBEDTLS_CIPHER_ID_ARIA* = (MBEDTLS_CIPHER_ID_CAMELLIA + 1).mbedtls_cipher_id_t + MBEDTLS_CIPHER_ID_CHACHA20* = (MBEDTLS_CIPHER_ID_ARIA + 1).mbedtls_cipher_id_t + MBEDTLS_CIPHER_NONE* = (0).mbedtls_cipher_type_t + MBEDTLS_CIPHER_NULL* = (MBEDTLS_CIPHER_NONE + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_128_ECB* = (MBEDTLS_CIPHER_NULL + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_192_ECB* = (MBEDTLS_CIPHER_AES_128_ECB + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_256_ECB* = (MBEDTLS_CIPHER_AES_192_ECB + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_128_CBC* = (MBEDTLS_CIPHER_AES_256_ECB + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_192_CBC* = (MBEDTLS_CIPHER_AES_128_CBC + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_256_CBC* = (MBEDTLS_CIPHER_AES_192_CBC + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_128_CFB128* = (MBEDTLS_CIPHER_AES_256_CBC + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_192_CFB128* = (MBEDTLS_CIPHER_AES_128_CFB128 + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_256_CFB128* = (MBEDTLS_CIPHER_AES_192_CFB128 + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_128_CTR* = (MBEDTLS_CIPHER_AES_256_CFB128 + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_192_CTR* = (MBEDTLS_CIPHER_AES_128_CTR + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_256_CTR* = (MBEDTLS_CIPHER_AES_192_CTR + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_128_GCM* = (MBEDTLS_CIPHER_AES_256_CTR + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_192_GCM* = (MBEDTLS_CIPHER_AES_128_GCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_256_GCM* = (MBEDTLS_CIPHER_AES_192_GCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_128_ECB* = (MBEDTLS_CIPHER_AES_256_GCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_192_ECB* = (MBEDTLS_CIPHER_CAMELLIA_128_ECB + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_256_ECB* = (MBEDTLS_CIPHER_CAMELLIA_192_ECB + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_128_CBC* = (MBEDTLS_CIPHER_CAMELLIA_256_ECB + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_192_CBC* = (MBEDTLS_CIPHER_CAMELLIA_128_CBC + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_256_CBC* = (MBEDTLS_CIPHER_CAMELLIA_192_CBC + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_128_CFB128* = (MBEDTLS_CIPHER_CAMELLIA_256_CBC + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_192_CFB128* = (MBEDTLS_CIPHER_CAMELLIA_128_CFB128 + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_256_CFB128* = (MBEDTLS_CIPHER_CAMELLIA_192_CFB128 + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_128_CTR* = (MBEDTLS_CIPHER_CAMELLIA_256_CFB128 + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_192_CTR* = (MBEDTLS_CIPHER_CAMELLIA_128_CTR + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_256_CTR* = (MBEDTLS_CIPHER_CAMELLIA_192_CTR + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_128_GCM* = (MBEDTLS_CIPHER_CAMELLIA_256_CTR + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_192_GCM* = (MBEDTLS_CIPHER_CAMELLIA_128_GCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_256_GCM* = (MBEDTLS_CIPHER_CAMELLIA_192_GCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_DES_ECB* = (MBEDTLS_CIPHER_CAMELLIA_256_GCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_DES_CBC* = (MBEDTLS_CIPHER_DES_ECB + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_DES_EDE_ECB* = (MBEDTLS_CIPHER_DES_CBC + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_DES_EDE_CBC* = (MBEDTLS_CIPHER_DES_EDE_ECB + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_DES_EDE3_ECB* = (MBEDTLS_CIPHER_DES_EDE_CBC + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_DES_EDE3_CBC* = (MBEDTLS_CIPHER_DES_EDE3_ECB + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_128_CCM* = (MBEDTLS_CIPHER_DES_EDE3_CBC + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_192_CCM* = (MBEDTLS_CIPHER_AES_128_CCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_256_CCM* = (MBEDTLS_CIPHER_AES_192_CCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG* = (MBEDTLS_CIPHER_AES_256_CCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG* = ( + MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG* = ( + MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_128_CCM* = (MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_192_CCM* = (MBEDTLS_CIPHER_CAMELLIA_128_CCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_256_CCM* = (MBEDTLS_CIPHER_CAMELLIA_192_CCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG* = ( + MBEDTLS_CIPHER_CAMELLIA_256_CCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG* = ( + MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG* = ( + MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_128_ECB* = (MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG + + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_192_ECB* = (MBEDTLS_CIPHER_ARIA_128_ECB + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_256_ECB* = (MBEDTLS_CIPHER_ARIA_192_ECB + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_128_CBC* = (MBEDTLS_CIPHER_ARIA_256_ECB + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_192_CBC* = (MBEDTLS_CIPHER_ARIA_128_CBC + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_256_CBC* = (MBEDTLS_CIPHER_ARIA_192_CBC + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_128_CFB128* = (MBEDTLS_CIPHER_ARIA_256_CBC + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_192_CFB128* = (MBEDTLS_CIPHER_ARIA_128_CFB128 + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_256_CFB128* = (MBEDTLS_CIPHER_ARIA_192_CFB128 + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_128_CTR* = (MBEDTLS_CIPHER_ARIA_256_CFB128 + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_192_CTR* = (MBEDTLS_CIPHER_ARIA_128_CTR + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_256_CTR* = (MBEDTLS_CIPHER_ARIA_192_CTR + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_128_GCM* = (MBEDTLS_CIPHER_ARIA_256_CTR + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_192_GCM* = (MBEDTLS_CIPHER_ARIA_128_GCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_256_GCM* = (MBEDTLS_CIPHER_ARIA_192_GCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_128_CCM* = (MBEDTLS_CIPHER_ARIA_256_GCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_192_CCM* = (MBEDTLS_CIPHER_ARIA_128_CCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_256_CCM* = (MBEDTLS_CIPHER_ARIA_192_CCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG* = (MBEDTLS_CIPHER_ARIA_256_CCM + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG* = ( + MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG* = ( + MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_128_OFB* = (MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_192_OFB* = (MBEDTLS_CIPHER_AES_128_OFB + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_256_OFB* = (MBEDTLS_CIPHER_AES_192_OFB + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_128_XTS* = (MBEDTLS_CIPHER_AES_256_OFB + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_256_XTS* = (MBEDTLS_CIPHER_AES_128_XTS + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CHACHA20* = (MBEDTLS_CIPHER_AES_256_XTS + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_CHACHA20_POLY1305* = (MBEDTLS_CIPHER_CHACHA20 + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_128_KW* = (MBEDTLS_CIPHER_CHACHA20_POLY1305 + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_192_KW* = (MBEDTLS_CIPHER_AES_128_KW + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_256_KW* = (MBEDTLS_CIPHER_AES_192_KW + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_128_KWP* = (MBEDTLS_CIPHER_AES_256_KW + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_192_KWP* = (MBEDTLS_CIPHER_AES_128_KWP + 1).mbedtls_cipher_type_t + MBEDTLS_CIPHER_AES_256_KWP* = (MBEDTLS_CIPHER_AES_192_KWP + 1).mbedtls_cipher_type_t + MBEDTLS_MODE_NONE* = (0).mbedtls_cipher_mode_t + MBEDTLS_MODE_ECB* = (MBEDTLS_MODE_NONE + 1).mbedtls_cipher_mode_t + MBEDTLS_MODE_CBC* = (MBEDTLS_MODE_ECB + 1).mbedtls_cipher_mode_t + MBEDTLS_MODE_CFB* = (MBEDTLS_MODE_CBC + 1).mbedtls_cipher_mode_t + MBEDTLS_MODE_OFB* = (MBEDTLS_MODE_CFB + 1).mbedtls_cipher_mode_t + MBEDTLS_MODE_CTR* = (MBEDTLS_MODE_OFB + 1).mbedtls_cipher_mode_t + MBEDTLS_MODE_GCM* = (MBEDTLS_MODE_CTR + 1).mbedtls_cipher_mode_t + MBEDTLS_MODE_STREAM* = (MBEDTLS_MODE_GCM + 1).mbedtls_cipher_mode_t + MBEDTLS_MODE_CCM* = (MBEDTLS_MODE_STREAM + 1).mbedtls_cipher_mode_t + MBEDTLS_MODE_CCM_STAR_NO_TAG* = (MBEDTLS_MODE_CCM + 1).mbedtls_cipher_mode_t + MBEDTLS_MODE_XTS* = (MBEDTLS_MODE_CCM_STAR_NO_TAG + 1).mbedtls_cipher_mode_t + MBEDTLS_MODE_CHACHAPOLY* = (MBEDTLS_MODE_XTS + 1).mbedtls_cipher_mode_t + MBEDTLS_MODE_KW* = (MBEDTLS_MODE_CHACHAPOLY + 1).mbedtls_cipher_mode_t + MBEDTLS_MODE_KWP* = (MBEDTLS_MODE_KW + 1).mbedtls_cipher_mode_t + MBEDTLS_PADDING_PKCS7* = (0).mbedtls_cipher_padding_t + MBEDTLS_PADDING_ONE_AND_ZEROS* = (MBEDTLS_PADDING_PKCS7 + 1).mbedtls_cipher_padding_t + MBEDTLS_PADDING_ZEROS_AND_LEN* = (MBEDTLS_PADDING_ONE_AND_ZEROS + 1).mbedtls_cipher_padding_t + MBEDTLS_PADDING_ZEROS* = (MBEDTLS_PADDING_ZEROS_AND_LEN + 1).mbedtls_cipher_padding_t + MBEDTLS_PADDING_NONE* = (MBEDTLS_PADDING_ZEROS + 1).mbedtls_cipher_padding_t + MBEDTLS_OPERATION_NONE* = (-1).mbedtls_operation_t + MBEDTLS_DECRYPT* = (0).mbedtls_operation_t + MBEDTLS_ENCRYPT* = (MBEDTLS_DECRYPT + 1).mbedtls_operation_t + MBEDTLS_KEY_LENGTH_NONE* = (0).cint + MBEDTLS_KEY_LENGTH_DES* = (64).cint + MBEDTLS_KEY_LENGTH_DES_EDE* = (128).cint + MBEDTLS_KEY_LENGTH_DES_EDE3* = (192).cint + MBEDTLS_MAX_IV_LENGTH* = 16 + MBEDTLS_MAX_BLOCK_LENGTH* = 16 + MBEDTLS_MAX_KEY_LENGTH* = 64 +type + mbedtls_cipher_base_t* {.incompleteStruct.} = object + mbedtls_cmac_context_t* {.incompleteStruct.} = object + mbedtls_cipher_info_t* {.bycopy.} = object + private_type*: mbedtls_cipher_type_t + private_mode*: mbedtls_cipher_mode_t + private_key_bitlen*: cuint + private_name*: cstring + private_iv_size*: cuint + private_flags*: cint + private_block_size*: cuint + private_base*: ptr mbedtls_cipher_base_t + + mbedtls_cipher_context_t* {.bycopy.} = object + private_cipher_info*: ptr mbedtls_cipher_info_t + private_key_bitlen*: cint + private_operation*: mbedtls_operation_t + private_add_padding*: proc (output: ptr byte; olen: uint; data_len: uint) {. + cdecl.} + private_get_padding*: proc (input: ptr byte; ilen: uint; + data_len: ptr uint): cint {.cdecl.} + private_unprocessed_data*: array[16, byte] + private_unprocessed_len*: uint + private_iv*: array[16, byte] + private_iv_size*: uint + private_cipher_ctx*: pointer + private_cmac_ctx*: ptr mbedtls_cmac_context_t + +proc mbedtls_cipher_list*(): ptr cint {.importc, cdecl.} +proc mbedtls_cipher_info_from_string*(cipher_name: cstring): ptr mbedtls_cipher_info_t {. + importc, cdecl.} +proc mbedtls_cipher_info_from_type*(cipher_type: mbedtls_cipher_type_t): ptr mbedtls_cipher_info_t {. + importc, cdecl.} +proc mbedtls_cipher_info_from_values*(cipher_id: mbedtls_cipher_id_t; + key_bitlen: cint; + mode: mbedtls_cipher_mode_t): ptr mbedtls_cipher_info_t {. + importc, cdecl.} +proc mbedtls_cipher_init*(ctx: ptr mbedtls_cipher_context_t) {.importc, cdecl.} +proc mbedtls_cipher_free*(ctx: ptr mbedtls_cipher_context_t) {.importc, cdecl.} +proc mbedtls_cipher_setup*(ctx: ptr mbedtls_cipher_context_t; + cipher_info: ptr mbedtls_cipher_info_t): cint {. + importc, cdecl.} +proc mbedtls_cipher_setkey*(ctx: ptr mbedtls_cipher_context_t; key: ptr byte; + key_bitlen: cint; operation: mbedtls_operation_t): cint {. + importc, cdecl.} +proc mbedtls_cipher_set_padding_mode*(ctx: ptr mbedtls_cipher_context_t; + mode: mbedtls_cipher_padding_t): cint {. + importc, cdecl.} +proc mbedtls_cipher_set_iv*(ctx: ptr mbedtls_cipher_context_t; iv: ptr byte; + iv_len: uint): cint {.importc, cdecl.} +proc mbedtls_cipher_reset*(ctx: ptr mbedtls_cipher_context_t): cint {.importc, + cdecl.} +proc mbedtls_cipher_update_ad*(ctx: ptr mbedtls_cipher_context_t; + ad: ptr byte; ad_len: uint): cint {.importc, + cdecl.} +proc mbedtls_cipher_update*(ctx: ptr mbedtls_cipher_context_t; + input: ptr byte; ilen: uint; output: ptr byte; + olen: ptr uint): cint {.importc, cdecl.} +proc mbedtls_cipher_finish*(ctx: ptr mbedtls_cipher_context_t; + output: ptr byte; olen: ptr uint): cint {.importc, + cdecl.} +proc mbedtls_cipher_write_tag*(ctx: ptr mbedtls_cipher_context_t; + tag: ptr byte; tag_len: uint): cint {.importc, + cdecl.} +proc mbedtls_cipher_check_tag*(ctx: ptr mbedtls_cipher_context_t; + tag: ptr byte; tag_len: uint): cint {.importc, + cdecl.} +proc mbedtls_cipher_crypt*(ctx: ptr mbedtls_cipher_context_t; iv: ptr byte; + iv_len: uint; input: ptr byte; ilen: uint; + output: ptr byte; olen: ptr uint): cint {.importc, + cdecl.} +proc mbedtls_cipher_auth_encrypt_ext*(ctx: ptr mbedtls_cipher_context_t; + iv: ptr byte; iv_len: uint; + ad: ptr byte; ad_len: uint; + input: ptr byte; ilen: uint; + output: ptr byte; output_len: uint; + olen: ptr uint; tag_len: uint): cint {. + importc, cdecl.} +proc mbedtls_cipher_auth_decrypt_ext*(ctx: ptr mbedtls_cipher_context_t; + iv: ptr byte; iv_len: uint; + ad: ptr byte; ad_len: uint; + input: ptr byte; ilen: uint; + output: ptr byte; output_len: uint; + olen: ptr uint; tag_len: uint): cint {. + importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/cmac.nim b/webrtc/mbedtls/cmac.nim new file mode 100644 index 0000000..3fa8e08 --- /dev/null +++ b/webrtc/mbedtls/cmac.nim @@ -0,0 +1,50 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "cipher" +import "platform_time" +{.compile: "./mbedtls/library/cmac.c".} +# Generated @ 2023-05-11T11:19:09+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/cmac.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_AES_BLOCK_SIZE* = 16 + MBEDTLS_DES3_BLOCK_SIZE* = 8 + MBEDTLS_CIPHER_BLKSIZE_MAX* = 16 +type + mbedtls_cmac_context_t* {.bycopy.} = object + private_state*: array[16, byte] + private_unprocessed_block*: array[16, byte] + private_unprocessed_len*: uint + +proc mbedtls_cipher_cmac_starts*(ctx: ptr mbedtls_cipher_context_t; + key: ptr byte; keybits: uint): cint {. + importc, cdecl.} +proc mbedtls_cipher_cmac_update*(ctx: ptr mbedtls_cipher_context_t; + input: ptr byte; ilen: uint): cint {.importc, + cdecl.} +proc mbedtls_cipher_cmac_finish*(ctx: ptr mbedtls_cipher_context_t; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_cipher_cmac_reset*(ctx: ptr mbedtls_cipher_context_t): cint {. + importc, cdecl.} +proc mbedtls_cipher_cmac*(cipher_info: ptr mbedtls_cipher_info_t; + key: ptr byte; keylen: uint; input: ptr byte; + ilen: uint; output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_aes_cmac_prf_128*(key: ptr byte; key_len: uint; + input: ptr byte; in_len: uint; + output: array[16, byte]): cint {.importc, cdecl.} +proc mbedtls_cmac_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/compat_2_x.nim b/webrtc/mbedtls/compat_2_x.nim new file mode 100644 index 0000000..94a6779 --- /dev/null +++ b/webrtc/mbedtls/compat_2_x.nim @@ -0,0 +1,42 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +# Generated @ 2023-05-11T11:19:09+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/compat-2.x.h + +# const 'mbedtls_ctr_drbg_update_ret' has unsupported value 'mbedtls_ctr_drbg_update' +# const 'mbedtls_hmac_drbg_update_ret' has unsupported value 'mbedtls_hmac_drbg_update' +# const 'mbedtls_md5_starts_ret' has unsupported value 'mbedtls_md5_starts' +# const 'mbedtls_md5_update_ret' has unsupported value 'mbedtls_md5_update' +# const 'mbedtls_md5_finish_ret' has unsupported value 'mbedtls_md5_finish' +# const 'mbedtls_md5_ret' has unsupported value 'mbedtls_md5' +# const 'mbedtls_ripemd160_starts_ret' has unsupported value 'mbedtls_ripemd160_starts' +# const 'mbedtls_ripemd160_update_ret' has unsupported value 'mbedtls_ripemd160_update' +# const 'mbedtls_ripemd160_finish_ret' has unsupported value 'mbedtls_ripemd160_finish' +# const 'mbedtls_ripemd160_ret' has unsupported value 'mbedtls_ripemd160' +# const 'mbedtls_sha1_starts_ret' has unsupported value 'mbedtls_sha1_starts' +# const 'mbedtls_sha1_update_ret' has unsupported value 'mbedtls_sha1_update' +# const 'mbedtls_sha1_finish_ret' has unsupported value 'mbedtls_sha1_finish' +# const 'mbedtls_sha1_ret' has unsupported value 'mbedtls_sha1' +# const 'mbedtls_sha256_starts_ret' has unsupported value 'mbedtls_sha256_starts' +# const 'mbedtls_sha256_update_ret' has unsupported value 'mbedtls_sha256_update' +# const 'mbedtls_sha256_finish_ret' has unsupported value 'mbedtls_sha256_finish' +# const 'mbedtls_sha256_ret' has unsupported value 'mbedtls_sha256' +# const 'mbedtls_sha512_starts_ret' has unsupported value 'mbedtls_sha512_starts' +# const 'mbedtls_sha512_update_ret' has unsupported value 'mbedtls_sha512_update' +# const 'mbedtls_sha512_finish_ret' has unsupported value 'mbedtls_sha512_finish' +# const 'mbedtls_sha512_ret' has unsupported value 'mbedtls_sha512' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +{.pop.} diff --git a/webrtc/mbedtls/config_psa.nim b/webrtc/mbedtls/config_psa.nim new file mode 100644 index 0000000..3e22681 --- /dev/null +++ b/webrtc/mbedtls/config_psa.nim @@ -0,0 +1,27 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +# Generated @ 2023-05-11T11:19:09+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/config_psa.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_PSA_BUILTIN_ALG_HMAC* = 1 + PSA_WANT_ALG_HMAC* = 1 + PSA_WANT_KEY_TYPE_DERIVE* = 1 + PSA_WANT_KEY_TYPE_PASSWORD* = 1 + PSA_WANT_KEY_TYPE_PASSWORD_HASH* = 1 + PSA_WANT_KEY_TYPE_RAW_DATA* = 1 +{.pop.} diff --git a/webrtc/mbedtls/constant_time.nim b/webrtc/mbedtls/constant_time.nim new file mode 100644 index 0000000..a39047a --- /dev/null +++ b/webrtc/mbedtls/constant_time.nim @@ -0,0 +1,23 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "bignum" +# {.compile: "./mbedtls/library/constant_time.c".} +# Generated @ 2023-05-11T11:19:09+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/constant_time.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +proc mbedtls_ct_memcmp*(a: pointer; b: pointer; n: uint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/ctr_drbg.nim b/webrtc/mbedtls/ctr_drbg.nim new file mode 100644 index 0000000..de4498b --- /dev/null +++ b/webrtc/mbedtls/ctr_drbg.nim @@ -0,0 +1,92 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "aes" +import "platform_util" +import "platform_time" +import "entropy" +import "md" +{.compile: "./mbedtls/library/ctr_drbg.c".} +# Generated @ 2023-05-11T11:19:09+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ctr_drbg.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED* = -0x00000034 + MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG* = -0x00000036 + MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG* = -0x00000038 + MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR* = -0x0000003A + MBEDTLS_CTR_DRBG_BLOCKSIZE* = 16 + MBEDTLS_CTR_DRBG_KEYSIZE* = 32 + MBEDTLS_CTR_DRBG_KEYBITS* = ( + MBEDTLS_CTR_DRBG_KEYSIZE * typeof(MBEDTLS_CTR_DRBG_KEYSIZE)(8)) + MBEDTLS_CTR_DRBG_SEEDLEN* = (MBEDTLS_CTR_DRBG_KEYSIZE + + typeof(MBEDTLS_CTR_DRBG_KEYSIZE)(MBEDTLS_CTR_DRBG_BLOCKSIZE)) + MBEDTLS_CTR_DRBG_ENTROPY_LEN* = 48 + MBEDTLS_CTR_DRBG_RESEED_INTERVAL* = 10000 + MBEDTLS_CTR_DRBG_MAX_INPUT* = 256 + MBEDTLS_CTR_DRBG_MAX_REQUEST* = 1024 + MBEDTLS_CTR_DRBG_MAX_SEED_INPUT* = 384 + MBEDTLS_CTR_DRBG_PR_OFF* = 0 + MBEDTLS_CTR_DRBG_PR_ON* = 1 + MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN* = 0 +type + mbedtls_ctr_drbg_context* {.bycopy.} = object + private_counter*: array[16, byte] + private_reseed_counter*: cint + private_prediction_resistance*: cint + private_entropy_len*: uint + private_reseed_interval*: cint + private_aes_ctx*: mbedtls_aes_context + private_f_entropy*: proc (a1: pointer; a2: ptr byte; a3: uint): cint {. + cdecl.} + private_p_entropy*: pointer + +proc mbedtls_ctr_drbg_init*(ctx: ptr mbedtls_ctr_drbg_context) {.importc, cdecl.} +proc mbedtls_ctr_drbg_seed*(ctx: ptr mbedtls_ctr_drbg_context; f_entropy: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_entropy: pointer; + custom: ptr byte; len: uint): cint {.importc, + cdecl.} +proc mbedtls_ctr_drbg_free*(ctx: ptr mbedtls_ctr_drbg_context) {.importc, cdecl.} +proc mbedtls_ctr_drbg_set_prediction_resistance*( + ctx: ptr mbedtls_ctr_drbg_context; resistance: cint) {.importc, cdecl.} +proc mbedtls_ctr_drbg_set_entropy_len*(ctx: ptr mbedtls_ctr_drbg_context; + len: uint) {.importc, cdecl.} +proc mbedtls_ctr_drbg_set_nonce_len*(ctx: ptr mbedtls_ctr_drbg_context; + len: uint): cint {.importc, cdecl.} +proc mbedtls_ctr_drbg_set_reseed_interval*(ctx: ptr mbedtls_ctr_drbg_context; + interval: cint) {.importc, cdecl.} +proc mbedtls_ctr_drbg_reseed*(ctx: ptr mbedtls_ctr_drbg_context; + additional: ptr byte; len: uint): cint {. + importc, cdecl.} +proc mbedtls_ctr_drbg_update*(ctx: ptr mbedtls_ctr_drbg_context; + additional: ptr byte; add_len: uint): cint {. + importc, cdecl.} +proc mbedtls_ctr_drbg_random_with_add*(p_rng: pointer; output: ptr byte; + output_len: uint; additional: ptr byte; + add_len: uint): cint {.importc, cdecl.} +proc mbedtls_ctr_drbg_random*(p_rng: pointer; output: ptr byte; + output_len: uint): cint {.importc, cdecl.} +proc mbedtls_ctr_drbg_write_seed_file*(ctx: ptr mbedtls_ctr_drbg_context; + path: cstring): cint {.importc, cdecl.} +proc mbedtls_ctr_drbg_update_seed_file*(ctx: ptr mbedtls_ctr_drbg_context; + path: cstring): cint {.importc, cdecl.} +proc mbedtls_ctr_drbg_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/debug.nim b/webrtc/mbedtls/debug.nim new file mode 100644 index 0000000..2a25f66 --- /dev/null +++ b/webrtc/mbedtls/debug.nim @@ -0,0 +1,128 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "ssl" +import "platform_util" +import "platform_time" +import "private_access" +import "bignum" +import "ecp" +import "ssl_ciphersuites" +import "pk" +import "md" +import "rsa" +import "ecdsa" +import "cipher" +import "x509_crt" +import "x509" +import "asn1" +import "x509_crl" +import "dhm" +import "ecdh" +import "md5" +import "ripemd160" +import "sha1" +import "sha256" +import "sha512" +import "cmac" +import "gcm" +import "ccm" +import "chachapoly" +import "poly1305" +import "chacha20" +import "ecjpake" +{.compile: "./mbedtls/library/debug.c".} +# Generated @ 2023-05-11T11:19:09+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/debug.h + +# const 'MBEDTLS_PRINTF_MS_TIME' has unsupported value 'PRId64' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(mbedtls_debug_ecdh_attr) +const + MBEDTLS_PRINTF_SIZET* = "zu" + MBEDTLS_PRINTF_LONGLONG* = "lld" + MBEDTLS_DEBUG_ECDH_Q* = (0).mbedtls_debug_ecdh_attr + MBEDTLS_DEBUG_ECDH_QP* = (MBEDTLS_DEBUG_ECDH_Q + 1).mbedtls_debug_ecdh_attr + MBEDTLS_DEBUG_ECDH_Z* = (MBEDTLS_DEBUG_ECDH_QP + 1).mbedtls_debug_ecdh_attr +proc mbedtls_debug_set_threshold*(threshold: cint) {.importc, cdecl.} +proc mbedtls_debug_print_msg*(ssl: ptr mbedtls_ssl_context; level: cint; + file: cstring; line: cint; format: cstring) {. + importc, cdecl, varargs.} +proc mbedtls_debug_print_ret*(ssl: ptr mbedtls_ssl_context; level: cint; + file: cstring; line: cint; text: cstring; + ret: cint) {.importc, cdecl.} +proc mbedtls_debug_print_buf*(ssl: ptr mbedtls_ssl_context; level: cint; + file: cstring; line: cint; text: cstring; + buf: ptr byte; len: uint) {.importc, cdecl.} +proc mbedtls_debug_print_mpi*(ssl: ptr mbedtls_ssl_context; level: cint; + file: cstring; line: cint; text: cstring; + X: ptr mbedtls_mpi) {.importc, cdecl.} +proc mbedtls_debug_print_ecp*(ssl: ptr mbedtls_ssl_context; level: cint; + file: cstring; line: cint; text: cstring; + X: ptr mbedtls_ecp_point) {.importc, cdecl.} +proc mbedtls_debug_print_crt*(ssl: ptr mbedtls_ssl_context; level: cint; + file: cstring; line: cint; text: cstring; + crt: ptr mbedtls_x509_crt) {.importc, cdecl.} +proc mbedtls_debug_printf_ecdh*(ssl: ptr mbedtls_ssl_context; level: cint; + file: cstring; line: cint; + ecdh: ptr mbedtls_ecdh_context; + attr: mbedtls_debug_ecdh_attr) {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/des.nim b/webrtc/mbedtls/des.nim new file mode 100644 index 0000000..d1e4196 --- /dev/null +++ b/webrtc/mbedtls/des.nim @@ -0,0 +1,81 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "platform_util" +import "platform_time" +{.compile: "./mbedtls/library/des.c".} +# Generated @ 2023-05-11T11:19:09+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/des.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_DES_ENCRYPT* = 1 + MBEDTLS_DES_DECRYPT* = 0 + MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH* = -0x00000032 + MBEDTLS_DES_KEY_SIZE* = 8 +type + mbedtls_des_context* {.bycopy.} = object + private_sk*: array[32, uint32] + + mbedtls_des3_context* {.bycopy.} = object + private_sk*: array[96, uint32] + +proc mbedtls_des_init*(ctx: ptr mbedtls_des_context) {.importc, cdecl.} +proc mbedtls_des_free*(ctx: ptr mbedtls_des_context) {.importc, cdecl.} +proc mbedtls_des3_init*(ctx: ptr mbedtls_des3_context) {.importc, cdecl.} +proc mbedtls_des3_free*(ctx: ptr mbedtls_des3_context) {.importc, cdecl.} +proc mbedtls_des_key_set_parity*(key: array[8, byte]) {.importc, cdecl.} +proc mbedtls_des_key_check_key_parity*(key: array[8, byte]): cint {.importc, + cdecl.} +proc mbedtls_des_key_check_weak*(key: array[8, byte]): cint {.importc, cdecl.} +proc mbedtls_des_setkey_enc*(ctx: ptr mbedtls_des_context; key: array[8, byte]): cint {. + importc, cdecl.} +proc mbedtls_des_setkey_dec*(ctx: ptr mbedtls_des_context; key: array[8, byte]): cint {. + importc, cdecl.} +proc mbedtls_des3_set2key_enc*(ctx: ptr mbedtls_des3_context; + key: array[8 * typeof(8)(2), byte]): cint {. + importc, cdecl.} +proc mbedtls_des3_set2key_dec*(ctx: ptr mbedtls_des3_context; + key: array[8 * typeof(8)(2), byte]): cint {. + importc, cdecl.} +proc mbedtls_des3_set3key_enc*(ctx: ptr mbedtls_des3_context; + key: array[8 * typeof(8)(3), byte]): cint {. + importc, cdecl.} +proc mbedtls_des3_set3key_dec*(ctx: ptr mbedtls_des3_context; + key: array[8 * typeof(8)(3), byte]): cint {. + importc, cdecl.} +proc mbedtls_des_crypt_ecb*(ctx: ptr mbedtls_des_context; + input: array[8, byte]; output: array[8, byte]): cint {. + importc, cdecl.} +proc mbedtls_des_crypt_cbc*(ctx: ptr mbedtls_des_context; mode: cint; + length: uint; iv: array[8, byte]; + input: ptr byte; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_des3_crypt_ecb*(ctx: ptr mbedtls_des3_context; + input: array[8, byte]; output: array[8, byte]): cint {. + importc, cdecl.} +proc mbedtls_des3_crypt_cbc*(ctx: ptr mbedtls_des3_context; mode: cint; + length: uint; iv: array[8, byte]; + input: ptr byte; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_des_setkey*(SK: array[32, uint32]; key: array[8, byte]) {. + importc, cdecl.} +proc mbedtls_des_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/dhm.nim b/webrtc/mbedtls/dhm.nim new file mode 100644 index 0000000..f839722 --- /dev/null +++ b/webrtc/mbedtls/dhm.nim @@ -0,0 +1,144 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "asn1" +import "pem" +import "bignum" +{.compile: "./mbedtls/library/dhm.c".} +# Generated @ 2023-05-11T11:19:09+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/dhm.h + +# const 'MBEDTLS_DHM_RFC3526_MODP_2048_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' +# const 'MBEDTLS_DHM_RFC3526_MODP_2048_G_BIN' has unsupported value '{ 0x02 }' +# const 'MBEDTLS_DHM_RFC3526_MODP_3072_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33, 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7, 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, 0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C, 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2, 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x3A, 0xD2, 0xCA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' +# const 'MBEDTLS_DHM_RFC3526_MODP_3072_G_BIN' has unsupported value '{ 0x02 }' +# const 'MBEDTLS_DHM_RFC3526_MODP_4096_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33, 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7, 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, 0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C, 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2, 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x21, 0x08, 0x01, 0x1A, 0x72, 0x3C, 0x12, 0xA7, 0x87, 0xE6, 0xD7, 0x88, 0x71, 0x9A, 0x10, 0xBD, 0xBA, 0x5B, 0x26, 0x99, 0xC3, 0x27, 0x18, 0x6A, 0xF4, 0xE2, 0x3C, 0x1A, 0x94, 0x68, 0x34, 0xB6, 0x15, 0x0B, 0xDA, 0x25, 0x83, 0xE9, 0xCA, 0x2A, 0xD4, 0x4C, 0xE8, 0xDB, 0xBB, 0xC2, 0xDB, 0x04, 0xDE, 0x8E, 0xF9, 0x2E, 0x8E, 0xFC, 0x14, 0x1F, 0xBE, 0xCA, 0xA6, 0x28, 0x7C, 0x59, 0x47, 0x4E, 0x6B, 0xC0, 0x5D, 0x99, 0xB2, 0x96, 0x4F, 0xA0, 0x90, 0xC3, 0xA2, 0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, 0xED, 0x1F, 0x61, 0x29, 0x70, 0xCE, 0xE2, 0xD7, 0xAF, 0xB8, 0x1B, 0xDD, 0x76, 0x21, 0x70, 0x48, 0x1C, 0xD0, 0x06, 0x91, 0x27, 0xD5, 0xB0, 0x5A, 0xA9, 0x93, 0xB4, 0xEA, 0x98, 0x8D, 0x8F, 0xDD, 0xC1, 0x86, 0xFF, 0xB7, 0xDC, 0x90, 0xA6, 0xC0, 0x8F, 0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x06, 0x31, 0x99, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' +# const 'MBEDTLS_DHM_RFC3526_MODP_4096_G_BIN' has unsupported value '{ 0x02 }' +# const 'MBEDTLS_DHM_RFC7919_FFDHE2048_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x28, 0x5C, 0x97, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }' +# const 'MBEDTLS_DHM_RFC7919_FFDHE2048_G_BIN' has unsupported value '{ 0x02 }' +# const 'MBEDTLS_DHM_RFC7919_FFDHE3072_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0xC6, 0x2E, 0x37, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' +# const 'MBEDTLS_DHM_RFC7919_FFDHE3072_G_BIN' has unsupported value '{ 0x02 }' +# const 'MBEDTLS_DHM_RFC7919_FFDHE4096_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x65, 0x5F, 0x6A, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' +# const 'MBEDTLS_DHM_RFC7919_FFDHE4096_G_BIN' has unsupported value '{ 0x02 }' +# const 'MBEDTLS_DHM_RFC7919_FFDHE6144_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02, 0x0B, 0xFD, 0x64, 0xB6, 0x45, 0x03, 0x6C, 0x7A, 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A, 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6, 0x3B, 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8, 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C, 0xB3, 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, 0x3A, 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71, 0x9B, 0x1F, 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F, 0x38, 0x81, 0x47, 0xFB, 0x4C, 0xFD, 0xB4, 0x77, 0xA5, 0x24, 0x71, 0xF7, 0xA9, 0xA9, 0x69, 0x10, 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8, 0xA0, 0x0E, 0xF0, 0x92, 0x35, 0x05, 0x11, 0xE3, 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E, 0x7F, 0xB2, 0x9F, 0x8C, 0x18, 0x30, 0x23, 0xC3, 0x58, 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4, 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, 0xBB, 0xC1, 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, 0x92, 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, 0xF6, 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82, 0x0A, 0xE8, 0xDB, 0x58, 0x47, 0xA6, 0x7C, 0xBE, 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C, 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E, 0x62, 0x29, 0x2C, 0x31, 0x15, 0x62, 0xA8, 0x46, 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A, 0xE4, 0x9F, 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17, 0x8C, 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03, 0xEC, 0x9D, 0x18, 0x10, 0xC6, 0x27, 0x2B, 0x04, 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, 0xD6, 0x3F, 0xDD, 0x4A, 0x8E, 0x9A, 0xDB, 0x1E, 0x69, 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1, 0xA4, 0x1D, 0x57, 0x0D, 0x79, 0x38, 0xDA, 0xD4, 0xA4, 0x0E, 0x32, 0x9C, 0xD0, 0xE4, 0x0E, 0x65, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' +# const 'MBEDTLS_DHM_RFC7919_FFDHE6144_G_BIN' has unsupported value '{ 0x02 }' +# const 'MBEDTLS_DHM_RFC7919_FFDHE8192_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02, 0x0B, 0xFD, 0x64, 0xB6, 0x45, 0x03, 0x6C, 0x7A, 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A, 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6, 0x3B, 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8, 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C, 0xB3, 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, 0x3A, 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71, 0x9B, 0x1F, 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F, 0x38, 0x81, 0x47, 0xFB, 0x4C, 0xFD, 0xB4, 0x77, 0xA5, 0x24, 0x71, 0xF7, 0xA9, 0xA9, 0x69, 0x10, 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8, 0xA0, 0x0E, 0xF0, 0x92, 0x35, 0x05, 0x11, 0xE3, 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E, 0x7F, 0xB2, 0x9F, 0x8C, 0x18, 0x30, 0x23, 0xC3, 0x58, 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4, 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, 0xBB, 0xC1, 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, 0x92, 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, 0xF6, 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82, 0x0A, 0xE8, 0xDB, 0x58, 0x47, 0xA6, 0x7C, 0xBE, 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C, 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E, 0x62, 0x29, 0x2C, 0x31, 0x15, 0x62, 0xA8, 0x46, 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A, 0xE4, 0x9F, 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17, 0x8C, 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03, 0xEC, 0x9D, 0x18, 0x10, 0xC6, 0x27, 0x2B, 0x04, 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, 0xD6, 0x3F, 0xDD, 0x4A, 0x8E, 0x9A, 0xDB, 0x1E, 0x69, 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1, 0xA4, 0x1D, 0x57, 0x0D, 0x79, 0x38, 0xDA, 0xD4, 0xA4, 0x0E, 0x32, 0x9C, 0xCF, 0xF4, 0x6A, 0xAA, 0x36, 0xAD, 0x00, 0x4C, 0xF6, 0x00, 0xC8, 0x38, 0x1E, 0x42, 0x5A, 0x31, 0xD9, 0x51, 0xAE, 0x64, 0xFD, 0xB2, 0x3F, 0xCE, 0xC9, 0x50, 0x9D, 0x43, 0x68, 0x7F, 0xEB, 0x69, 0xED, 0xD1, 0xCC, 0x5E, 0x0B, 0x8C, 0xC3, 0xBD, 0xF6, 0x4B, 0x10, 0xEF, 0x86, 0xB6, 0x31, 0x42, 0xA3, 0xAB, 0x88, 0x29, 0x55, 0x5B, 0x2F, 0x74, 0x7C, 0x93, 0x26, 0x65, 0xCB, 0x2C, 0x0F, 0x1C, 0xC0, 0x1B, 0xD7, 0x02, 0x29, 0x38, 0x88, 0x39, 0xD2, 0xAF, 0x05, 0xE4, 0x54, 0x50, 0x4A, 0xC7, 0x8B, 0x75, 0x82, 0x82, 0x28, 0x46, 0xC0, 0xBA, 0x35, 0xC3, 0x5F, 0x5C, 0x59, 0x16, 0x0C, 0xC0, 0x46, 0xFD, 0x82, 0x51, 0x54, 0x1F, 0xC6, 0x8C, 0x9C, 0x86, 0xB0, 0x22, 0xBB, 0x70, 0x99, 0x87, 0x6A, 0x46, 0x0E, 0x74, 0x51, 0xA8, 0xA9, 0x31, 0x09, 0x70, 0x3F, 0xEE, 0x1C, 0x21, 0x7E, 0x6C, 0x38, 0x26, 0xE5, 0x2C, 0x51, 0xAA, 0x69, 0x1E, 0x0E, 0x42, 0x3C, 0xFC, 0x99, 0xE9, 0xE3, 0x16, 0x50, 0xC1, 0x21, 0x7B, 0x62, 0x48, 0x16, 0xCD, 0xAD, 0x9A, 0x95, 0xF9, 0xD5, 0xB8, 0x01, 0x94, 0x88, 0xD9, 0xC0, 0xA0, 0xA1, 0xFE, 0x30, 0x75, 0xA5, 0x77, 0xE2, 0x31, 0x83, 0xF8, 0x1D, 0x4A, 0x3F, 0x2F, 0xA4, 0x57, 0x1E, 0xFC, 0x8C, 0xE0, 0xBA, 0x8A, 0x4F, 0xE8, 0xB6, 0x85, 0x5D, 0xFE, 0x72, 0xB0, 0xA6, 0x6E, 0xDE, 0xD2, 0xFB, 0xAB, 0xFB, 0xE5, 0x8A, 0x30, 0xFA, 0xFA, 0xBE, 0x1C, 0x5D, 0x71, 0xA8, 0x7E, 0x2F, 0x74, 0x1E, 0xF8, 0xC1, 0xFE, 0x86, 0xFE, 0xA6, 0xBB, 0xFD, 0xE5, 0x30, 0x67, 0x7F, 0x0D, 0x97, 0xD1, 0x1D, 0x49, 0xF7, 0xA8, 0x44, 0x3D, 0x08, 0x22, 0xE5, 0x06, 0xA9, 0xF4, 0x61, 0x4E, 0x01, 0x1E, 0x2A, 0x94, 0x83, 0x8F, 0xF8, 0x8C, 0xD6, 0x8C, 0x8B, 0xB7, 0xC5, 0xC6, 0x42, 0x4C, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' +# const 'MBEDTLS_DHM_RFC7919_FFDHE8192_G_BIN' has unsupported value '{ 0x02 }' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(mbedtls_dhm_parameter) +const + MBEDTLS_ERR_DHM_BAD_INPUT_DATA* = -0x00003080 + MBEDTLS_ERR_DHM_READ_PARAMS_FAILED* = -0x00003100 + MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED* = -0x00003180 + MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED* = -0x00003200 + MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED* = -0x00003280 + MBEDTLS_ERR_DHM_CALC_SECRET_FAILED* = -0x00003300 + MBEDTLS_ERR_DHM_INVALID_FORMAT* = -0x00003380 + MBEDTLS_ERR_DHM_ALLOC_FAILED* = -0x00003400 + MBEDTLS_ERR_DHM_FILE_IO_ERROR* = -0x00003480 + MBEDTLS_ERR_DHM_SET_GROUP_FAILED* = -0x00003580 + MBEDTLS_DHM_PARAM_P* = (0).mbedtls_dhm_parameter + MBEDTLS_DHM_PARAM_G* = (MBEDTLS_DHM_PARAM_P + 1).mbedtls_dhm_parameter + MBEDTLS_DHM_PARAM_X* = (MBEDTLS_DHM_PARAM_G + 1).mbedtls_dhm_parameter + MBEDTLS_DHM_PARAM_GX* = (MBEDTLS_DHM_PARAM_X + 1).mbedtls_dhm_parameter + MBEDTLS_DHM_PARAM_GY* = (MBEDTLS_DHM_PARAM_GX + 1).mbedtls_dhm_parameter + MBEDTLS_DHM_PARAM_K* = (MBEDTLS_DHM_PARAM_GY + 1).mbedtls_dhm_parameter +type + mbedtls_dhm_context* {.bycopy.} = object + private_P*: mbedtls_mpi + private_G*: mbedtls_mpi + private_X*: mbedtls_mpi + private_GX*: mbedtls_mpi + private_GY*: mbedtls_mpi + private_K*: mbedtls_mpi + private_RP*: mbedtls_mpi + private_Vi*: mbedtls_mpi + private_Vf*: mbedtls_mpi + private_pX*: mbedtls_mpi + +proc mbedtls_dhm_init*(ctx: ptr mbedtls_dhm_context) {.importc, cdecl.} +proc mbedtls_dhm_read_params*(ctx: ptr mbedtls_dhm_context; p: ptr ptr byte; + `end`: ptr byte): cint {.importc, cdecl.} +proc mbedtls_dhm_make_params*(ctx: ptr mbedtls_dhm_context; x_size: cint; + output: ptr byte; olen: ptr uint; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_dhm_set_group*(ctx: ptr mbedtls_dhm_context; P: ptr mbedtls_mpi; + G: ptr mbedtls_mpi): cint {.importc, cdecl.} +proc mbedtls_dhm_read_public*(ctx: ptr mbedtls_dhm_context; input: ptr byte; + ilen: uint): cint {.importc, cdecl.} +proc mbedtls_dhm_make_public*(ctx: ptr mbedtls_dhm_context; x_size: cint; + output: ptr byte; olen: uint; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_dhm_calc_secret*(ctx: ptr mbedtls_dhm_context; output: ptr byte; + output_size: uint; olen: ptr uint; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_dhm_get_bitlen*(ctx: ptr mbedtls_dhm_context): uint {.importc, + cdecl.} +proc mbedtls_dhm_get_len*(ctx: ptr mbedtls_dhm_context): uint {.importc, cdecl.} +proc mbedtls_dhm_get_value*(ctx: ptr mbedtls_dhm_context; + param: mbedtls_dhm_parameter; dest: ptr mbedtls_mpi): cint {. + importc, cdecl.} +proc mbedtls_dhm_free*(ctx: ptr mbedtls_dhm_context) {.importc, cdecl.} +proc mbedtls_dhm_parse_dhm*(dhm: ptr mbedtls_dhm_context; dhmin: ptr byte; + dhminlen: uint): cint {.importc, cdecl.} +proc mbedtls_dhm_parse_dhmfile*(dhm: ptr mbedtls_dhm_context; path: cstring): cint {. + importc, cdecl.} +proc mbedtls_dhm_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/ecdh.nim b/webrtc/mbedtls/ecdh.nim new file mode 100644 index 0000000..18148b9 --- /dev/null +++ b/webrtc/mbedtls/ecdh.nim @@ -0,0 +1,128 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "ecp" +import "bignum" +{.compile: "./mbedtls/library/ecdh.c".} +# Generated @ 2023-05-11T11:19:09+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ecdh.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(mbedtls_ecdh_side) +defineEnum(mbedtls_ecdh_variant) +const + MBEDTLS_ECDH_OURS* = (0).mbedtls_ecdh_side + MBEDTLS_ECDH_THEIRS* = (MBEDTLS_ECDH_OURS + 1).mbedtls_ecdh_side + MBEDTLS_ECDH_VARIANT_NONE* = (0).mbedtls_ecdh_variant + MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0* = (MBEDTLS_ECDH_VARIANT_NONE + 1).mbedtls_ecdh_variant +type + mbedtls_ecdh_context_mbed* {.bycopy.} = object + private_grp*: mbedtls_ecp_group + private_d*: mbedtls_mpi + private_Q*: mbedtls_ecp_point + private_Qp*: mbedtls_ecp_point + private_z*: mbedtls_mpi + + Union_ecdhh1* {.union, bycopy.} = object + private_mbed_ecdh*: mbedtls_ecdh_context_mbed + + mbedtls_ecdh_context* {.bycopy.} = object + private_point_format*: uint8 + private_grp_id*: mbedtls_ecp_group_id + private_var*: mbedtls_ecdh_variant + private_ctx*: Union_ecdhh1 + +proc mbedtls_ecdh_can_do*(gid: mbedtls_ecp_group_id): cint {.importc, cdecl.} +proc mbedtls_ecdh_gen_public*(grp: ptr mbedtls_ecp_group; d: ptr mbedtls_mpi; + Q: ptr mbedtls_ecp_point; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_ecdh_compute_shared*(grp: ptr mbedtls_ecp_group; + z: ptr mbedtls_mpi; Q: ptr mbedtls_ecp_point; + d: ptr mbedtls_mpi; f_rng: proc (a1: pointer; + a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, + cdecl.} +proc mbedtls_ecdh_init*(ctx: ptr mbedtls_ecdh_context) {.importc, cdecl.} +proc mbedtls_ecdh_setup*(ctx: ptr mbedtls_ecdh_context; + grp_id: mbedtls_ecp_group_id): cint {.importc, cdecl.} +proc mbedtls_ecdh_free*(ctx: ptr mbedtls_ecdh_context) {.importc, cdecl.} +proc mbedtls_ecdh_make_params*(ctx: ptr mbedtls_ecdh_context; olen: ptr uint; + buf: ptr byte; blen: uint; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_ecdh_read_params*(ctx: ptr mbedtls_ecdh_context; + buf: ptr ptr byte; `end`: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_ecdh_get_params*(ctx: ptr mbedtls_ecdh_context; + key: ptr mbedtls_ecp_keypair; + side: mbedtls_ecdh_side): cint {.importc, cdecl.} +proc mbedtls_ecdh_make_public*(ctx: ptr mbedtls_ecdh_context; olen: ptr uint; + buf: ptr byte; blen: uint; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_ecdh_read_public*(ctx: ptr mbedtls_ecdh_context; buf: ptr byte; + blen: uint): cint {.importc, cdecl.} +proc mbedtls_ecdh_calc_secret*(ctx: ptr mbedtls_ecdh_context; olen: ptr uint; + buf: ptr byte; blen: uint; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/ecdsa.nim b/webrtc/mbedtls/ecdsa.nim new file mode 100644 index 0000000..90edde1 --- /dev/null +++ b/webrtc/mbedtls/ecdsa.nim @@ -0,0 +1,97 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "ecp" +import "bignum" +import "md" +import "platform_time" +import "hmac_drbg" +import "asn1" +import "asn1write" +{.compile: "./mbedtls/library/ecdsa.c".} +# Generated @ 2023-05-11T11:19:10+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ecdsa.h + +# const 'MBEDTLS_ECDSA_MAX_LEN' has unsupported value 'MBEDTLS_ECDSA_MAX_SIG_LEN(MBEDTLS_ECP_MAX_BITS)' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +type + mbedtls_ecdsa_context* = mbedtls_ecp_keypair + mbedtls_ecdsa_restart_ctx* = object +proc mbedtls_ecdsa_can_do*(gid: mbedtls_ecp_group_id): cint {.importc, cdecl.} +proc mbedtls_ecdsa_sign*(grp: ptr mbedtls_ecp_group; r: ptr mbedtls_mpi; + s: ptr mbedtls_mpi; d: ptr mbedtls_mpi; + buf: ptr byte; blen: uint; f_rng: proc (a1: pointer; + a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, + cdecl.} +proc mbedtls_ecdsa_sign_det_ext*(grp: ptr mbedtls_ecp_group; r: ptr mbedtls_mpi; + s: ptr mbedtls_mpi; d: ptr mbedtls_mpi; + buf: ptr byte; blen: uint; + md_alg: mbedtls_md_type_t; f_rng_blind: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng_blind: pointer): cint {. + importc, cdecl.} +proc mbedtls_ecdsa_sign_restartable*(grp: ptr mbedtls_ecp_group; + r: ptr mbedtls_mpi; s: ptr mbedtls_mpi; + d: ptr mbedtls_mpi; buf: ptr byte; + blen: uint; f_rng: proc (a1: pointer; + a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; f_rng_blind: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; + p_rng_blind: pointer; + rs_ctx: ptr mbedtls_ecdsa_restart_ctx): cint {. + importc, cdecl.} +proc mbedtls_ecdsa_sign_det_restartable*(grp: ptr mbedtls_ecp_group; + r: ptr mbedtls_mpi; s: ptr mbedtls_mpi; d: ptr mbedtls_mpi; buf: ptr byte; + blen: uint; md_alg: mbedtls_md_type_t; + f_rng_blind: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; + p_rng_blind: pointer; rs_ctx: ptr mbedtls_ecdsa_restart_ctx): cint {. + importc, cdecl.} +proc mbedtls_ecdsa_verify*(grp: ptr mbedtls_ecp_group; buf: ptr byte; + blen: uint; Q: ptr mbedtls_ecp_point; + r: ptr mbedtls_mpi; s: ptr mbedtls_mpi): cint {. + importc, cdecl.} +proc mbedtls_ecdsa_verify_restartable*(grp: ptr mbedtls_ecp_group; + buf: ptr byte; blen: uint; + Q: ptr mbedtls_ecp_point; + r: ptr mbedtls_mpi; s: ptr mbedtls_mpi; + rs_ctx: ptr mbedtls_ecdsa_restart_ctx): cint {. + importc, cdecl.} +proc mbedtls_ecdsa_write_signature*(ctx: ptr mbedtls_ecdsa_context; + md_alg: mbedtls_md_type_t; hash: ptr byte; + hlen: uint; sig: ptr byte; sig_size: uint; + slen: ptr uint; f_rng: proc (a1: pointer; + a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, + cdecl.} +proc mbedtls_ecdsa_write_signature_restartable*(ctx: ptr mbedtls_ecdsa_context; + md_alg: mbedtls_md_type_t; hash: ptr byte; hlen: uint; sig: ptr byte; + sig_size: uint; slen: ptr uint; + f_rng: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; + p_rng: pointer; rs_ctx: ptr mbedtls_ecdsa_restart_ctx): cint {.importc, + cdecl.} +proc mbedtls_ecdsa_read_signature*(ctx: ptr mbedtls_ecdsa_context; + hash: ptr byte; hlen: uint; + sig: ptr byte; slen: uint): cint {.importc, + cdecl.} +proc mbedtls_ecdsa_read_signature_restartable*(ctx: ptr mbedtls_ecdsa_context; + hash: ptr byte; hlen: uint; sig: ptr byte; slen: uint; + rs_ctx: ptr mbedtls_ecdsa_restart_ctx): cint {.importc, cdecl.} +proc mbedtls_ecdsa_genkey*(ctx: ptr mbedtls_ecdsa_context; + gid: mbedtls_ecp_group_id; f_rng: proc (a1: pointer; + a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, + cdecl.} +proc mbedtls_ecdsa_from_keypair*(ctx: ptr mbedtls_ecdsa_context; + key: ptr mbedtls_ecp_keypair): cint {.importc, + cdecl.} +proc mbedtls_ecdsa_init*(ctx: ptr mbedtls_ecdsa_context) {.importc, cdecl.} +proc mbedtls_ecdsa_free*(ctx: ptr mbedtls_ecdsa_context) {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/ecjpake.nim b/webrtc/mbedtls/ecjpake.nim new file mode 100644 index 0000000..aff083e --- /dev/null +++ b/webrtc/mbedtls/ecjpake.nim @@ -0,0 +1,124 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "ecp" +import "bignum" +import "md" +import "hash_info" +import "platform_time" +{.compile: "./mbedtls/library/ecjpake.c".} +# Generated @ 2023-05-11T11:19:10+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ecjpake.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(mbedtls_ecjpake_role) +const + MBEDTLS_ECJPAKE_CLIENT* = (0).mbedtls_ecjpake_role + MBEDTLS_ECJPAKE_SERVER* = (MBEDTLS_ECJPAKE_CLIENT + 1).mbedtls_ecjpake_role +type + mbedtls_ecjpake_context* {.bycopy.} = object + private_md_type*: mbedtls_md_type_t + private_grp*: mbedtls_ecp_group + private_role*: mbedtls_ecjpake_role + private_point_format*: cint + private_Xm1*: mbedtls_ecp_point + private_Xm2*: mbedtls_ecp_point + private_Xp1*: mbedtls_ecp_point + private_Xp2*: mbedtls_ecp_point + private_Xp*: mbedtls_ecp_point + private_xm1_1*: mbedtls_mpi + private_xm2_1*: mbedtls_mpi + private_s*: mbedtls_mpi + +proc mbedtls_ecjpake_init*(ctx: ptr mbedtls_ecjpake_context) {.importc, cdecl.} +proc mbedtls_ecjpake_setup*(ctx: ptr mbedtls_ecjpake_context; + role: mbedtls_ecjpake_role; hash: mbedtls_md_type_t; + curve: mbedtls_ecp_group_id; secret: ptr byte; + len: uint): cint {.importc, cdecl.} +proc mbedtls_ecjpake_set_point_format*(ctx: ptr mbedtls_ecjpake_context; + point_format: cint): cint {.importc, + cdecl.} +proc mbedtls_ecjpake_check*(ctx: ptr mbedtls_ecjpake_context): cint {.importc, + cdecl.} +proc mbedtls_ecjpake_write_round_one*(ctx: ptr mbedtls_ecjpake_context; + buf: ptr byte; len: uint; + olen: ptr uint; f_rng: proc (a1: pointer; + a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, + cdecl.} +proc mbedtls_ecjpake_read_round_one*(ctx: ptr mbedtls_ecjpake_context; + buf: ptr byte; len: uint): cint {. + importc, cdecl.} +proc mbedtls_ecjpake_write_round_two*(ctx: ptr mbedtls_ecjpake_context; + buf: ptr byte; len: uint; + olen: ptr uint; f_rng: proc (a1: pointer; + a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, + cdecl.} +proc mbedtls_ecjpake_read_round_two*(ctx: ptr mbedtls_ecjpake_context; + buf: ptr byte; len: uint): cint {. + importc, cdecl.} +proc mbedtls_ecjpake_derive_secret*(ctx: ptr mbedtls_ecjpake_context; + buf: ptr byte; len: uint; olen: ptr uint; + f_rng: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; + p_rng: pointer): cint {.importc, cdecl.} +proc mbedtls_ecjpake_write_shared_key*(ctx: ptr mbedtls_ecjpake_context; + buf: ptr byte; len: uint; + olen: ptr uint; f_rng: proc (a1: pointer; + a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, + cdecl.} +proc mbedtls_ecjpake_free*(ctx: ptr mbedtls_ecjpake_context) {.importc, cdecl.} +proc mbedtls_ecjpake_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/ecp.nim b/webrtc/mbedtls/ecp.nim new file mode 100644 index 0000000..beb0884 --- /dev/null +++ b/webrtc/mbedtls/ecp.nim @@ -0,0 +1,256 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "bignum" +{.compile: "./mbedtls/library/ecp.c".} +{.compile: "./mbedtls/library/ecp_curves.c".} +# Generated @ 2023-05-11T11:19:10+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ecp.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(mbedtls_ecp_group_id) +defineEnum(mbedtls_ecp_curve_type) +defineEnum(mbedtls_ecp_modulus_type) +const + MBEDTLS_ERR_ECP_BAD_INPUT_DATA* = -0x00004F80 + MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL* = -0x00004F00 + MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE* = -0x00004E80 + MBEDTLS_ERR_ECP_VERIFY_FAILED* = -0x00004E00 + MBEDTLS_ERR_ECP_ALLOC_FAILED* = -0x00004D80 + MBEDTLS_ERR_ECP_RANDOM_FAILED* = -0x00004D00 + MBEDTLS_ERR_ECP_INVALID_KEY* = -0x00004C80 + MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH* = -0x00004C00 + MBEDTLS_ERR_ECP_IN_PROGRESS* = -0x00004B00 + MBEDTLS_ECP_DP_NONE* = (0).mbedtls_ecp_group_id + MBEDTLS_ECP_DP_SECP192R1* = (MBEDTLS_ECP_DP_NONE + 1).mbedtls_ecp_group_id + MBEDTLS_ECP_DP_SECP224R1* = (MBEDTLS_ECP_DP_SECP192R1 + 1).mbedtls_ecp_group_id + MBEDTLS_ECP_DP_SECP256R1* = (MBEDTLS_ECP_DP_SECP224R1 + 1).mbedtls_ecp_group_id + MBEDTLS_ECP_DP_SECP384R1* = (MBEDTLS_ECP_DP_SECP256R1 + 1).mbedtls_ecp_group_id + MBEDTLS_ECP_DP_SECP521R1* = (MBEDTLS_ECP_DP_SECP384R1 + 1).mbedtls_ecp_group_id + MBEDTLS_ECP_DP_BP256R1* = (MBEDTLS_ECP_DP_SECP521R1 + 1).mbedtls_ecp_group_id + MBEDTLS_ECP_DP_BP384R1* = (MBEDTLS_ECP_DP_BP256R1 + 1).mbedtls_ecp_group_id + MBEDTLS_ECP_DP_BP512R1* = (MBEDTLS_ECP_DP_BP384R1 + 1).mbedtls_ecp_group_id + MBEDTLS_ECP_DP_CURVE25519* = (MBEDTLS_ECP_DP_BP512R1 + 1).mbedtls_ecp_group_id + MBEDTLS_ECP_DP_SECP192K1* = (MBEDTLS_ECP_DP_CURVE25519 + 1).mbedtls_ecp_group_id + MBEDTLS_ECP_DP_SECP224K1* = (MBEDTLS_ECP_DP_SECP192K1 + 1).mbedtls_ecp_group_id + MBEDTLS_ECP_DP_SECP256K1* = (MBEDTLS_ECP_DP_SECP224K1 + 1).mbedtls_ecp_group_id + MBEDTLS_ECP_DP_CURVE448* = (MBEDTLS_ECP_DP_SECP256K1 + 1).mbedtls_ecp_group_id + MBEDTLS_ECP_DP_MAX* = 14 + MBEDTLS_ECP_TYPE_NONE* = (0).mbedtls_ecp_curve_type + MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS* = (MBEDTLS_ECP_TYPE_NONE + 1).mbedtls_ecp_curve_type + MBEDTLS_ECP_TYPE_MONTGOMERY* = (MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS + 1).mbedtls_ecp_curve_type + MBEDTLS_ECP_MOD_NONE* = (0).mbedtls_ecp_modulus_type + MBEDTLS_ECP_MOD_COORDINATE* = (MBEDTLS_ECP_MOD_NONE + 1).mbedtls_ecp_modulus_type + MBEDTLS_ECP_MOD_SCALAR* = (MBEDTLS_ECP_MOD_COORDINATE + 1).mbedtls_ecp_modulus_type + MBEDTLS_ECP_WINDOW_SIZE* = 4 + MBEDTLS_ECP_FIXED_POINT_OPTIM* = 1 + MBEDTLS_ECP_MAX_BITS* = 521 + MBEDTLS_ECP_MAX_BYTES* = (typeof(MBEDTLS_ECP_MAX_BITS)(( + MBEDTLS_ECP_MAX_BITS + typeof(MBEDTLS_ECP_MAX_BITS)(7)) / + typeof(MBEDTLS_ECP_MAX_BITS)(8))) + MBEDTLS_ECP_MAX_PT_LEN* = (2 * typeof(2)(MBEDTLS_ECP_MAX_BYTES) + typeof(2)(1)) + MBEDTLS_ECP_PF_UNCOMPRESSED* = 0 + MBEDTLS_ECP_PF_COMPRESSED* = 1 + MBEDTLS_ECP_TLS_NAMED_CURVE* = 3 +type + mbedtls_ecp_curve_info* {.bycopy.} = object + grp_id*: mbedtls_ecp_group_id + tls_id*: uint16 + bit_size*: uint16 + name*: cstring + + mbedtls_ecp_point* {.bycopy.} = object + private_X*: mbedtls_mpi + private_Y*: mbedtls_mpi + private_Z*: mbedtls_mpi + + mbedtls_ecp_group* {.bycopy.} = object + id*: mbedtls_ecp_group_id + P*: mbedtls_mpi + A*: mbedtls_mpi + B*: mbedtls_mpi + G*: mbedtls_ecp_point + N*: mbedtls_mpi + pbits*: uint + nbits*: uint + private_h*: cuint + private_modp*: proc (a1: ptr mbedtls_mpi): cint {.cdecl.} + private_t_pre*: proc (a1: ptr mbedtls_ecp_point; a2: pointer): cint {.cdecl.} + private_t_post*: proc (a1: ptr mbedtls_ecp_point; a2: pointer): cint {.cdecl.} + private_t_data*: pointer + private_T*: ptr mbedtls_ecp_point + private_T_size*: uint + + mbedtls_ecp_restart_ctx* = object + mbedtls_ecp_keypair* {.bycopy.} = object + private_grp*: mbedtls_ecp_group + private_d*: mbedtls_mpi + private_Q*: mbedtls_ecp_point + +proc mbedtls_ecp_get_type*(grp: ptr mbedtls_ecp_group): mbedtls_ecp_curve_type {. + importc, cdecl.} +proc mbedtls_ecp_curve_list*(): ptr mbedtls_ecp_curve_info {.importc, cdecl.} +proc mbedtls_ecp_grp_id_list*(): ptr mbedtls_ecp_group_id {.importc, cdecl.} +proc mbedtls_ecp_curve_info_from_grp_id*(grp_id: mbedtls_ecp_group_id): ptr mbedtls_ecp_curve_info {. + importc, cdecl.} +proc mbedtls_ecp_curve_info_from_tls_id*(tls_id: uint16): ptr mbedtls_ecp_curve_info {. + importc, cdecl.} +proc mbedtls_ecp_curve_info_from_name*(name: cstring): ptr mbedtls_ecp_curve_info {. + importc, cdecl.} +proc mbedtls_ecp_point_init*(pt: ptr mbedtls_ecp_point) {.importc, cdecl.} +proc mbedtls_ecp_group_init*(grp: ptr mbedtls_ecp_group) {.importc, cdecl.} +proc mbedtls_ecp_keypair_init*(key: ptr mbedtls_ecp_keypair) {.importc, cdecl.} +proc mbedtls_ecp_point_free*(pt: ptr mbedtls_ecp_point) {.importc, cdecl.} +proc mbedtls_ecp_group_free*(grp: ptr mbedtls_ecp_group) {.importc, cdecl.} +proc mbedtls_ecp_keypair_free*(key: ptr mbedtls_ecp_keypair) {.importc, cdecl.} +proc mbedtls_ecp_copy*(P: ptr mbedtls_ecp_point; Q: ptr mbedtls_ecp_point): cint {. + importc, cdecl.} +proc mbedtls_ecp_group_copy*(dst: ptr mbedtls_ecp_group; + src: ptr mbedtls_ecp_group): cint {.importc, cdecl.} +proc mbedtls_ecp_set_zero*(pt: ptr mbedtls_ecp_point): cint {.importc, cdecl.} +proc mbedtls_ecp_is_zero*(pt: ptr mbedtls_ecp_point): cint {.importc, cdecl.} +proc mbedtls_ecp_point_cmp*(P: ptr mbedtls_ecp_point; Q: ptr mbedtls_ecp_point): cint {. + importc, cdecl.} +proc mbedtls_ecp_point_read_string*(P: ptr mbedtls_ecp_point; radix: cint; + x: cstring; y: cstring): cint {.importc, + cdecl.} +proc mbedtls_ecp_point_write_binary*(grp: ptr mbedtls_ecp_group; + P: ptr mbedtls_ecp_point; format: cint; + olen: ptr uint; buf: ptr byte; + buflen: uint): cint {.importc, cdecl.} +proc mbedtls_ecp_point_read_binary*(grp: ptr mbedtls_ecp_group; + P: ptr mbedtls_ecp_point; buf: ptr byte; + ilen: uint): cint {.importc, cdecl.} +proc mbedtls_ecp_tls_read_point*(grp: ptr mbedtls_ecp_group; + pt: ptr mbedtls_ecp_point; buf: ptr ptr byte; + len: uint): cint {.importc, cdecl.} +proc mbedtls_ecp_tls_write_point*(grp: ptr mbedtls_ecp_group; + pt: ptr mbedtls_ecp_point; format: cint; + olen: ptr uint; buf: ptr byte; blen: uint): cint {. + importc, cdecl.} +proc mbedtls_ecp_group_load*(grp: ptr mbedtls_ecp_group; + id: mbedtls_ecp_group_id): cint {.importc, cdecl.} +proc mbedtls_ecp_tls_read_group*(grp: ptr mbedtls_ecp_group; + buf: ptr ptr byte; len: uint): cint {. + importc, cdecl.} +proc mbedtls_ecp_tls_read_group_id*(grp: ptr mbedtls_ecp_group_id; + buf: ptr ptr byte; len: uint): cint {. + importc, cdecl.} +proc mbedtls_ecp_tls_write_group*(grp: ptr mbedtls_ecp_group; olen: ptr uint; + buf: ptr byte; blen: uint): cint {.importc, + cdecl.} +proc mbedtls_ecp_mul*(grp: ptr mbedtls_ecp_group; R: ptr mbedtls_ecp_point; + m: ptr mbedtls_mpi; P: ptr mbedtls_ecp_point; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_ecp_mul_restartable*(grp: ptr mbedtls_ecp_group; + R: ptr mbedtls_ecp_point; m: ptr mbedtls_mpi; + P: ptr mbedtls_ecp_point; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; + rs_ctx: ptr mbedtls_ecp_restart_ctx): cint {. + importc, cdecl.} +proc mbedtls_ecp_muladd*(grp: ptr mbedtls_ecp_group; R: ptr mbedtls_ecp_point; + m: ptr mbedtls_mpi; P: ptr mbedtls_ecp_point; + n: ptr mbedtls_mpi; Q: ptr mbedtls_ecp_point): cint {. + importc, cdecl.} +proc mbedtls_ecp_muladd_restartable*(grp: ptr mbedtls_ecp_group; + R: ptr mbedtls_ecp_point; + m: ptr mbedtls_mpi; + P: ptr mbedtls_ecp_point; + n: ptr mbedtls_mpi; + Q: ptr mbedtls_ecp_point; + rs_ctx: ptr mbedtls_ecp_restart_ctx): cint {. + importc, cdecl.} +proc mbedtls_ecp_check_pubkey*(grp: ptr mbedtls_ecp_group; + pt: ptr mbedtls_ecp_point): cint {.importc, cdecl.} +proc mbedtls_ecp_check_privkey*(grp: ptr mbedtls_ecp_group; d: ptr mbedtls_mpi): cint {. + importc, cdecl.} +proc mbedtls_ecp_gen_privkey*(grp: ptr mbedtls_ecp_group; d: ptr mbedtls_mpi; + f_rng: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; + p_rng: pointer): cint {.importc, cdecl.} +proc mbedtls_ecp_gen_keypair_base*(grp: ptr mbedtls_ecp_group; + G: ptr mbedtls_ecp_point; d: ptr mbedtls_mpi; + Q: ptr mbedtls_ecp_point; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_ecp_gen_keypair*(grp: ptr mbedtls_ecp_group; d: ptr mbedtls_mpi; + Q: ptr mbedtls_ecp_point; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_ecp_gen_key*(grp_id: mbedtls_ecp_group_id; + key: ptr mbedtls_ecp_keypair; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_ecp_read_key*(grp_id: mbedtls_ecp_group_id; + key: ptr mbedtls_ecp_keypair; buf: ptr byte; + buflen: uint): cint {.importc, cdecl.} +proc mbedtls_ecp_write_key*(key: ptr mbedtls_ecp_keypair; buf: ptr byte; + buflen: uint): cint {.importc, cdecl.} +proc mbedtls_ecp_check_pub_priv*(pub: ptr mbedtls_ecp_keypair; + prv: ptr mbedtls_ecp_keypair; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_ecp_export*(key: ptr mbedtls_ecp_keypair; + grp: ptr mbedtls_ecp_group; d: ptr mbedtls_mpi; + Q: ptr mbedtls_ecp_point): cint {.importc, cdecl.} +proc mbedtls_ecp_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/entropy.nim b/webrtc/mbedtls/entropy.nim new file mode 100644 index 0000000..db307a2 --- /dev/null +++ b/webrtc/mbedtls/entropy.nim @@ -0,0 +1,81 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "md" +import "platform_util" +import "platform_time" +{.compile: "./mbedtls/library/entropy.c".} +{.compile: "./mbedtls/library/entropy_poll.c".} +# Generated @ 2023-05-11T11:19:10+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/entropy.h + +# const 'MBEDTLS_ENTROPY_MD' has unsupported value 'MBEDTLS_MD_SHA512' +# const 'MBEDTLS_ENTROPY_SOURCE_MANUAL' has unsupported value 'MBEDTLS_ENTROPY_MAX_SOURCES' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ENTROPY_BLOCK_SIZE* = 64 + MBEDTLS_ERR_ENTROPY_SOURCE_FAILED* = -0x0000003C + MBEDTLS_ERR_ENTROPY_MAX_SOURCES* = -0x0000003E + MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED* = -0x00000040 + MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE* = -0x0000003D + MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR* = -0x0000003F + MBEDTLS_ENTROPY_MAX_SOURCES* = 20 + MBEDTLS_ENTROPY_MAX_GATHER* = 128 + MBEDTLS_ENTROPY_MAX_SEED_SIZE* = 1024 + MBEDTLS_ENTROPY_SOURCE_STRONG* = 1 + MBEDTLS_ENTROPY_SOURCE_WEAK* = 0 +type + mbedtls_entropy_f_source_ptr* = proc (data: pointer; output: ptr byte; + len: uint; olen: ptr uint): cint {.cdecl.} + mbedtls_entropy_source_state* {.bycopy.} = object + private_f_source*: mbedtls_entropy_f_source_ptr + private_p_source*: pointer + private_size*: uint + private_threshold*: uint + private_strong*: cint + + mbedtls_entropy_context* {.bycopy.} = object + private_accumulator_started*: cint + private_accumulator*: mbedtls_md_context_t + private_source_count*: cint + private_source*: array[20, mbedtls_entropy_source_state] + +proc mbedtls_platform_entropy_poll*(data: pointer; output: ptr byte; + len: uint; olen: ptr uint): cint {.importc, + cdecl.} +proc mbedtls_entropy_init*(ctx: ptr mbedtls_entropy_context) {.importc, cdecl.} +proc mbedtls_entropy_free*(ctx: ptr mbedtls_entropy_context) {.importc, cdecl.} +proc mbedtls_entropy_add_source*(ctx: ptr mbedtls_entropy_context; + f_source: mbedtls_entropy_f_source_ptr; + p_source: pointer; threshold: uint; + strong: cint): cint {.importc, cdecl.} +proc mbedtls_entropy_gather*(ctx: ptr mbedtls_entropy_context): cint {.importc, + cdecl.} +proc mbedtls_entropy_func*(data: pointer; output: ptr byte; len: uint): cint {. + importc, cdecl.} +proc mbedtls_entropy_update_manual*(ctx: ptr mbedtls_entropy_context; + data: ptr byte; len: uint): cint {. + importc, cdecl.} +proc mbedtls_entropy_write_seed_file*(ctx: ptr mbedtls_entropy_context; + path: cstring): cint {.importc, cdecl.} +proc mbedtls_entropy_update_seed_file*(ctx: ptr mbedtls_entropy_context; + path: cstring): cint {.importc, cdecl.} +proc mbedtls_entropy_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/error.nim b/webrtc/mbedtls/error.nim new file mode 100644 index 0000000..cf0242e --- /dev/null +++ b/webrtc/mbedtls/error.nim @@ -0,0 +1,35 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +{.compile: "./mbedtls/library/error.c".} +# Generated @ 2023-05-11T11:19:10+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/error.h + +# proc 'mbedtls_error_add' skipped - static inline procs cannot work with '--noHeader | -H' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_ERROR_GENERIC_ERROR* = -0x00000001 + MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED* = -0x0000006E + MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED* = -0x00000070 + MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED* = -0x00000072 +proc mbedtls_strerror*(errnum: cint; buffer: cstring; buflen: uint) {.importc, + cdecl.} +proc mbedtls_high_level_strerr*(error_code: cint): cstring {.importc, cdecl.} +proc mbedtls_low_level_strerr*(error_code: cint): cstring {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/gcm.nim b/webrtc/mbedtls/gcm.nim new file mode 100644 index 0000000..0e3b790 --- /dev/null +++ b/webrtc/mbedtls/gcm.nim @@ -0,0 +1,75 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "cipher" +import "platform_util" +import "platform_time" +#{.compile: "./mbedtls/library/gcm.c".} +# Generated @ 2023-05-11T11:19:10+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/gcm.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_GCM_ENCRYPT* = 1 + MBEDTLS_GCM_DECRYPT* = 0 + MBEDTLS_ERR_GCM_AUTH_FAILED* = -0x00000012 + MBEDTLS_ERR_GCM_BAD_INPUT* = -0x00000014 + MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL* = -0x00000016 +type + mbedtls_gcm_context* {.bycopy.} = object + private_cipher_ctx*: mbedtls_cipher_context_t + private_HL*: array[16, uint64] + private_HH*: array[16, uint64] + private_len*: uint64 + private_add_len*: uint64 + private_base_ectr*: array[16, byte] + private_y*: array[16, byte] + private_buf*: array[16, byte] + private_mode*: cint + +proc mbedtls_gcm_init*(ctx: ptr mbedtls_gcm_context) {.importc, cdecl.} +proc mbedtls_gcm_setkey*(ctx: ptr mbedtls_gcm_context; + cipher: mbedtls_cipher_id_t; key: ptr byte; + keybits: cuint): cint {.importc, cdecl.} +proc mbedtls_gcm_crypt_and_tag*(ctx: ptr mbedtls_gcm_context; mode: cint; + length: uint; iv: ptr byte; iv_len: uint; + add: ptr byte; add_len: uint; + input: ptr byte; output: ptr byte; + tag_len: uint; tag: ptr byte): cint {.importc, + cdecl.} +proc mbedtls_gcm_auth_decrypt*(ctx: ptr mbedtls_gcm_context; length: uint; + iv: ptr byte; iv_len: uint; add: ptr byte; + add_len: uint; tag: ptr byte; tag_len: uint; + input: ptr byte; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_gcm_starts*(ctx: ptr mbedtls_gcm_context; mode: cint; + iv: ptr byte; iv_len: uint): cint {.importc, cdecl.} +proc mbedtls_gcm_update_ad*(ctx: ptr mbedtls_gcm_context; add: ptr byte; + add_len: uint): cint {.importc, cdecl.} +proc mbedtls_gcm_update*(ctx: ptr mbedtls_gcm_context; input: ptr byte; + input_length: uint; output: ptr byte; + output_size: uint; output_length: ptr uint): cint {. + importc, cdecl.} +proc mbedtls_gcm_finish*(ctx: ptr mbedtls_gcm_context; output: ptr byte; + output_size: uint; output_length: ptr uint; + tag: ptr byte; tag_len: uint): cint {.importc, cdecl.} +proc mbedtls_gcm_free*(ctx: ptr mbedtls_gcm_context) {.importc, cdecl.} +proc mbedtls_gcm_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/hash_info.nim b/webrtc/mbedtls/hash_info.nim new file mode 100644 index 0000000..202cd21 --- /dev/null +++ b/webrtc/mbedtls/hash_info.nim @@ -0,0 +1,3 @@ +{.compile: "./mbedtls/library/hash_info.c".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} diff --git a/webrtc/mbedtls/hkdf.nim b/webrtc/mbedtls/hkdf.nim new file mode 100644 index 0000000..c3c685b --- /dev/null +++ b/webrtc/mbedtls/hkdf.nim @@ -0,0 +1,41 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "md" +import "private_access" +import "platform_util" +import "platform_time" +{.compile: "./mbedtls/library/hkdf.c".} +# Generated @ 2023-05-11T11:19:10+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/hkdf.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_HKDF_BAD_INPUT_DATA* = -0x00005F80 +proc mbedtls_hkdf*(md: ptr mbedtls_md_info_t; salt: ptr byte; salt_len: uint; + ikm: ptr byte; ikm_len: uint; info: ptr byte; + info_len: uint; okm: ptr byte; okm_len: uint): cint {. + importc, cdecl.} +proc mbedtls_hkdf_extract*(md: ptr mbedtls_md_info_t; salt: ptr byte; + salt_len: uint; ikm: ptr byte; ikm_len: uint; + prk: ptr byte): cint {.importc, cdecl.} +proc mbedtls_hkdf_expand*(md: ptr mbedtls_md_info_t; prk: ptr byte; + prk_len: uint; info: ptr byte; info_len: uint; + okm: ptr byte; okm_len: uint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/hmac_drbg.nim b/webrtc/mbedtls/hmac_drbg.nim new file mode 100644 index 0000000..b456271 --- /dev/null +++ b/webrtc/mbedtls/hmac_drbg.nim @@ -0,0 +1,88 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "md" +import "platform_util" +import "platform_time" +{.compile: "./mbedtls/library/hmac_drbg.c".} +# Generated @ 2023-05-11T11:19:11+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/hmac_drbg.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG* = -0x00000003 + MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG* = -0x00000005 + MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR* = -0x00000007 + MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED* = -0x00000009 + MBEDTLS_HMAC_DRBG_RESEED_INTERVAL* = 10000 + MBEDTLS_HMAC_DRBG_MAX_INPUT* = 256 + MBEDTLS_HMAC_DRBG_MAX_REQUEST* = 1024 + MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT* = 384 + MBEDTLS_HMAC_DRBG_PR_OFF* = 0 + MBEDTLS_HMAC_DRBG_PR_ON* = 1 +type + mbedtls_hmac_drbg_context* {.bycopy.} = object + private_md_ctx*: mbedtls_md_context_t + private_V*: array[64, byte] + private_reseed_counter*: cint + private_entropy_len*: uint + private_prediction_resistance*: cint + private_reseed_interval*: cint + private_f_entropy*: proc (a1: pointer; a2: ptr byte; a3: uint): cint {. + cdecl.} + private_p_entropy*: pointer + +proc mbedtls_hmac_drbg_init*(ctx: ptr mbedtls_hmac_drbg_context) {.importc, + cdecl.} +proc mbedtls_hmac_drbg_seed*(ctx: ptr mbedtls_hmac_drbg_context; + md_info: ptr mbedtls_md_info_t; f_entropy: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_entropy: pointer; + custom: ptr byte; len: uint): cint {.importc, + cdecl.} +proc mbedtls_hmac_drbg_seed_buf*(ctx: ptr mbedtls_hmac_drbg_context; + md_info: ptr mbedtls_md_info_t; + data: ptr byte; data_len: uint): cint {. + importc, cdecl.} +proc mbedtls_hmac_drbg_set_prediction_resistance*( + ctx: ptr mbedtls_hmac_drbg_context; resistance: cint) {.importc, cdecl.} +proc mbedtls_hmac_drbg_set_entropy_len*(ctx: ptr mbedtls_hmac_drbg_context; + len: uint) {.importc, cdecl.} +proc mbedtls_hmac_drbg_set_reseed_interval*(ctx: ptr mbedtls_hmac_drbg_context; + interval: cint) {.importc, cdecl.} +proc mbedtls_hmac_drbg_update*(ctx: ptr mbedtls_hmac_drbg_context; + additional: ptr byte; add_len: uint): cint {. + importc, cdecl.} +proc mbedtls_hmac_drbg_reseed*(ctx: ptr mbedtls_hmac_drbg_context; + additional: ptr byte; len: uint): cint {. + importc, cdecl.} +proc mbedtls_hmac_drbg_random_with_add*(p_rng: pointer; output: ptr byte; + output_len: uint; + additional: ptr byte; add_len: uint): cint {. + importc, cdecl.} +proc mbedtls_hmac_drbg_random*(p_rng: pointer; output: ptr byte; out_len: uint): cint {. + importc, cdecl.} +proc mbedtls_hmac_drbg_free*(ctx: ptr mbedtls_hmac_drbg_context) {.importc, + cdecl.} +proc mbedtls_hmac_drbg_write_seed_file*(ctx: ptr mbedtls_hmac_drbg_context; + path: cstring): cint {.importc, cdecl.} +proc mbedtls_hmac_drbg_update_seed_file*(ctx: ptr mbedtls_hmac_drbg_context; + path: cstring): cint {.importc, cdecl.} +proc mbedtls_hmac_drbg_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/lms.nim b/webrtc/mbedtls/lms.nim new file mode 100644 index 0000000..8eacfda --- /dev/null +++ b/webrtc/mbedtls/lms.nim @@ -0,0 +1,114 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "psa/crypto" +{.compile: "./mbedtls/library/lms.c".} +{.compile: "./mbedtls/library/lmots.c".} +# Generated @ 2023-05-11T11:19:11+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/lms.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(mbedtls_lms_algorithm_type_t) +defineEnum(mbedtls_lmots_algorithm_type_t) +const + MBEDTLS_ERR_LMS_BAD_INPUT_DATA* = -0x00000011 + MBEDTLS_ERR_LMS_OUT_OF_PRIVATE_KEYS* = -0x00000013 + MBEDTLS_ERR_LMS_VERIFY_FAILED* = -0x00000015 + MBEDTLS_ERR_LMS_ALLOC_FAILED* = -0x00000017 + MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL* = -0x00000019 + MBEDTLS_LMOTS_N_HASH_LEN_MAX* = (32'u) + MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT_MAX* = (34'u) + MBEDTLS_LMOTS_I_KEY_ID_LEN* = (16'u) + MBEDTLS_LMOTS_Q_LEAF_ID_LEN* = (4'u) + MBEDTLS_LMOTS_TYPE_LEN* = (4'u) + MBEDTLS_LMS_TYPE_LEN* = (4) + MBEDTLS_LMS_M_NODE_BYTES_MAX* = 32 + MBEDTLS_LMS_SHA256_M32_H10* = (0x00000006).mbedtls_lms_algorithm_type_t + MBEDTLS_LMOTS_SHA256_N32_W8* = (4).mbedtls_lmots_algorithm_type_t +type + mbedtls_lmots_parameters_t* {.bycopy.} = object + private_I_key_identifier*: array[(16'u), byte] + private_q_leaf_identifier*: array[(4'u), byte] + private_type*: mbedtls_lmots_algorithm_type_t + + mbedtls_lmots_public_t* {.bycopy.} = object + private_params*: mbedtls_lmots_parameters_t + private_public_key*: array[(32'u), byte] + private_have_public_key*: byte + + mbedtls_lms_parameters_t* {.bycopy.} = object + private_I_key_identifier*: array[(16'u), byte] + private_otstype*: mbedtls_lmots_algorithm_type_t + private_type*: mbedtls_lms_algorithm_type_t + + mbedtls_lms_public_t* {.bycopy.} = object + private_params*: mbedtls_lms_parameters_t + private_T_1_pub_key*: array[32, byte] + private_have_public_key*: byte + +proc mbedtls_lms_public_init*(ctx: ptr mbedtls_lms_public_t) {.importc, cdecl.} +proc mbedtls_lms_public_free*(ctx: ptr mbedtls_lms_public_t) {.importc, cdecl.} +proc mbedtls_lms_import_public_key*(ctx: ptr mbedtls_lms_public_t; + key: ptr byte; key_size: uint): cint {. + importc, cdecl.} +proc mbedtls_lms_export_public_key*(ctx: ptr mbedtls_lms_public_t; + key: ptr byte; key_size: uint; + key_len: ptr uint): cint {.importc, cdecl.} +proc mbedtls_lms_verify*(ctx: ptr mbedtls_lms_public_t; msg: ptr byte; + msg_size: uint; sig: ptr byte; sig_size: uint): cint {. + importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/mbedtls_config.nim b/webrtc/mbedtls/mbedtls_config.nim new file mode 100644 index 0000000..b5c38ca --- /dev/null +++ b/webrtc/mbedtls/mbedtls_config.nim @@ -0,0 +1,26 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +# Generated @ 2023-05-11T11:19:11+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/mbedtls_config.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT* = 0 + MBEDTLS_SSL_MAX_EARLY_DATA_SIZE* = 1024 + MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE* = 6000 + MBEDTLS_SSL_TLS1_3_TICKET_NONCE_LENGTH* = 32 + MBEDTLS_SSL_TLS1_3_DEFAULT_NEW_SESSION_TICKETS* = 1 +{.pop.} diff --git a/webrtc/mbedtls/md.nim b/webrtc/mbedtls/md.nim new file mode 100644 index 0000000..f1fb65e --- /dev/null +++ b/webrtc/mbedtls/md.nim @@ -0,0 +1,140 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "platform_time" +import "ripemd160" +import "sha1" +import "sha256" +import "sha512" +import "md5" +# {.compile: "./mbedtls/library/ripemd160.c".} +# {.compile: "./mbedtls/library/sha1.c".} +# {.compile: "./mbedtls/library/sha256.c".} +# {.compile: "./mbedtls/library/sha512.c".} +# {.compile: "./mbedtls/library/md5.c".} +{.compile: "./mbedtls/library/md.c".} +# Generated @ 2023-05-11T11:19:11+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/md.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(mbedtls_md_type_t) +defineEnum(mbedtls_md_engine_t) +const + MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE* = -0x00005080 + MBEDTLS_ERR_MD_BAD_INPUT_DATA* = -0x00005100 + MBEDTLS_ERR_MD_ALLOC_FAILED* = -0x00005180 + MBEDTLS_ERR_MD_FILE_IO_ERROR* = -0x00005200 + MBEDTLS_MD_NONE* = (0).mbedtls_md_type_t + MBEDTLS_MD_MD5* = (MBEDTLS_MD_NONE + 1).mbedtls_md_type_t + MBEDTLS_MD_SHA1* = (MBEDTLS_MD_MD5 + 1).mbedtls_md_type_t + MBEDTLS_MD_SHA224* = (MBEDTLS_MD_SHA1 + 1).mbedtls_md_type_t + MBEDTLS_MD_SHA256* = (MBEDTLS_MD_SHA224 + 1).mbedtls_md_type_t + MBEDTLS_MD_SHA384* = (MBEDTLS_MD_SHA256 + 1).mbedtls_md_type_t + MBEDTLS_MD_SHA512* = (MBEDTLS_MD_SHA384 + 1).mbedtls_md_type_t + MBEDTLS_MD_RIPEMD160* = (MBEDTLS_MD_SHA512 + 1).mbedtls_md_type_t + MBEDTLS_MD_MAX_SIZE* = 64 + MBEDTLS_MD_MAX_BLOCK_SIZE* = 128 + MBEDTLS_MD_ENGINE_LEGACY* = (0).mbedtls_md_engine_t + MBEDTLS_MD_ENGINE_PSA* = (MBEDTLS_MD_ENGINE_LEGACY + 1).mbedtls_md_engine_t +type + mbedtls_md_info_t* {.incompleteStruct.} = object + mbedtls_md_context_t* {.bycopy.} = object + private_md_info*: ptr mbedtls_md_info_t + private_md_ctx*: pointer + private_hmac_ctx*: pointer + +proc mbedtls_md_info_from_type*(md_type: mbedtls_md_type_t): ptr mbedtls_md_info_t {. + importc, cdecl.} +proc mbedtls_md_init*(ctx: ptr mbedtls_md_context_t) {.importc, cdecl.} +proc mbedtls_md_free*(ctx: ptr mbedtls_md_context_t) {.importc, cdecl.} +proc mbedtls_md_setup*(ctx: ptr mbedtls_md_context_t; + md_info: ptr mbedtls_md_info_t; hmac: cint): cint {. + importc, cdecl.} +proc mbedtls_md_clone*(dst: ptr mbedtls_md_context_t; + src: ptr mbedtls_md_context_t): cint {.importc, cdecl.} +proc mbedtls_md_get_size*(md_info: ptr mbedtls_md_info_t): byte {.importc, + cdecl.} +proc mbedtls_md_get_type*(md_info: ptr mbedtls_md_info_t): mbedtls_md_type_t {. + importc, cdecl.} +proc mbedtls_md_starts*(ctx: ptr mbedtls_md_context_t): cint {.importc, cdecl.} +proc mbedtls_md_update*(ctx: ptr mbedtls_md_context_t; input: ptr byte; + ilen: uint): cint {.importc, cdecl.} +proc mbedtls_md_finish*(ctx: ptr mbedtls_md_context_t; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_md*(md_info: ptr mbedtls_md_info_t; input: ptr byte; ilen: uint; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_md_list*(): ptr cint {.importc, cdecl.} +proc mbedtls_md_info_from_string*(md_name: cstring): ptr mbedtls_md_info_t {. + importc, cdecl.} +proc mbedtls_md_get_name*(md_info: ptr mbedtls_md_info_t): cstring {.importc, + cdecl.} +proc mbedtls_md_info_from_ctx*(ctx: ptr mbedtls_md_context_t): ptr mbedtls_md_info_t {. + importc, cdecl.} +proc mbedtls_md_file*(md_info: ptr mbedtls_md_info_t; path: cstring; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_md_hmac_starts*(ctx: ptr mbedtls_md_context_t; key: ptr byte; + keylen: uint): cint {.importc, cdecl.} +proc mbedtls_md_hmac_update*(ctx: ptr mbedtls_md_context_t; input: ptr byte; + ilen: uint): cint {.importc, cdecl.} +proc mbedtls_md_hmac_finish*(ctx: ptr mbedtls_md_context_t; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_md_hmac_reset*(ctx: ptr mbedtls_md_context_t): cint {.importc, + cdecl.} +proc mbedtls_md_hmac*(md_info: ptr mbedtls_md_info_t; key: ptr byte; + keylen: uint; input: ptr byte; ilen: uint; + output: ptr byte): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/md5.nim b/webrtc/mbedtls/md5.nim new file mode 100644 index 0000000..3e1c747 --- /dev/null +++ b/webrtc/mbedtls/md5.nim @@ -0,0 +1,43 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "platform_time" +{.compile: "./mbedtls/library/md5.c".} +# Generated @ 2023-05-11T11:19:11+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/md5.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +type + mbedtls_md5_context* {.bycopy.} = object + private_total*: array[2, uint32] + private_state*: array[4, uint32] + private_buffer*: array[64, byte] + +proc mbedtls_md5_init*(ctx: ptr mbedtls_md5_context) {.importc, cdecl.} +proc mbedtls_md5_free*(ctx: ptr mbedtls_md5_context) {.importc, cdecl.} +proc mbedtls_md5_clone*(dst: ptr mbedtls_md5_context; + src: ptr mbedtls_md5_context) {.importc, cdecl.} +proc mbedtls_md5_starts*(ctx: ptr mbedtls_md5_context): cint {.importc, cdecl.} +proc mbedtls_md5_update*(ctx: ptr mbedtls_md5_context; input: ptr byte; + ilen: uint): cint {.importc, cdecl.} +proc mbedtls_md5_finish*(ctx: ptr mbedtls_md5_context; output: array[16, byte]): cint {. + importc, cdecl.} +proc mbedtls_internal_md5_process*(ctx: ptr mbedtls_md5_context; + data: array[64, byte]): cint {.importc, + cdecl.} +proc mbedtls_md5*(input: ptr byte; ilen: uint; output: array[16, byte]): cint {. + importc, cdecl.} +proc mbedtls_md5_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/memory_buffer_alloc.nim b/webrtc/mbedtls/memory_buffer_alloc.nim new file mode 100644 index 0000000..b1ca866 --- /dev/null +++ b/webrtc/mbedtls/memory_buffer_alloc.nim @@ -0,0 +1,39 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +{.compile: "./mbedtls/library/memory_buffer_alloc.c".} +# Generated @ 2023-05-11T11:19:11+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/memory_buffer_alloc.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_MEMORY_ALIGN_MULTIPLE* = 4 + MBEDTLS_MEMORY_VERIFY_NONE* = 0 + MBEDTLS_MEMORY_VERIFY_ALLOC* = (1 shl typeof(1)(0)) + MBEDTLS_MEMORY_VERIFY_FREE* = (1 shl typeof(1)(1)) + MBEDTLS_MEMORY_VERIFY_ALWAYS* = (MBEDTLS_MEMORY_VERIFY_ALLOC or + typeof(MBEDTLS_MEMORY_VERIFY_ALLOC)(MBEDTLS_MEMORY_VERIFY_FREE)) +proc mbedtls_memory_buffer_alloc_init*(buf: ptr byte; len: uint) {.importc, + cdecl.} +proc mbedtls_memory_buffer_alloc_free*() {.importc, cdecl.} +proc mbedtls_memory_buffer_set_verify*(verify: cint) {.importc, cdecl.} +proc mbedtls_memory_buffer_alloc_verify*(): cint {.importc, cdecl.} +proc mbedtls_memory_buffer_alloc_self_test*(verbose: cint): cint {.importc, + cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/net_sockets.nim b/webrtc/mbedtls/net_sockets.nim new file mode 100644 index 0000000..588e55c --- /dev/null +++ b/webrtc/mbedtls/net_sockets.nim @@ -0,0 +1,101 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "ssl" +import "platform_util" +import "platform_time" +import "bignum" +import "ecp" +import "ssl_ciphersuites" +import "pk" +import "md" +import "rsa" +import "ecdsa" +import "cipher" +import "x509_crt" +import "x509" +import "asn1" +import "x509_crl" +import "dhm" +import "ecdh" +import "md5" +import "ripemd160" +import "sha1" +import "sha256" +import "sha512" +import "cmac" +import "gcm" +import "ccm" +import "chachapoly" +import "poly1305" +import "chacha20" +import "ecjpake" +{.compile: "./mbedtls/library/net_sockets.c".} +# Generated @ 2023-05-11T11:19:11+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/net_sockets.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_NET_SOCKET_FAILED* = -0x00000042 + MBEDTLS_ERR_NET_CONNECT_FAILED* = -0x00000044 + MBEDTLS_ERR_NET_BIND_FAILED* = -0x00000046 + MBEDTLS_ERR_NET_LISTEN_FAILED* = -0x00000048 + MBEDTLS_ERR_NET_ACCEPT_FAILED* = -0x0000004A + MBEDTLS_ERR_NET_RECV_FAILED* = -0x0000004C + MBEDTLS_ERR_NET_SEND_FAILED* = -0x0000004E + MBEDTLS_ERR_NET_CONN_RESET* = -0x00000050 + MBEDTLS_ERR_NET_UNKNOWN_HOST* = -0x00000052 + MBEDTLS_ERR_NET_BUFFER_TOO_SMALL* = -0x00000043 + MBEDTLS_ERR_NET_INVALID_CONTEXT* = -0x00000045 + MBEDTLS_ERR_NET_POLL_FAILED* = -0x00000047 + MBEDTLS_ERR_NET_BAD_INPUT_DATA* = -0x00000049 + MBEDTLS_NET_LISTEN_BACKLOG* = 10 + MBEDTLS_NET_PROTO_TCP* = 0 + MBEDTLS_NET_PROTO_UDP* = 1 + MBEDTLS_NET_POLL_READ* = 1 + MBEDTLS_NET_POLL_WRITE* = 2 +type + mbedtls_net_context* {.bycopy.} = object + fd*: cint + +proc mbedtls_net_init*(ctx: ptr mbedtls_net_context) {.importc, cdecl.} +proc mbedtls_net_connect*(ctx: ptr mbedtls_net_context; host: cstring; + port: cstring; proto: cint): cint {.importc, cdecl.} +proc mbedtls_net_bind*(ctx: ptr mbedtls_net_context; bind_ip: cstring; + port: cstring; proto: cint): cint {.importc, cdecl.} +proc mbedtls_net_accept*(bind_ctx: ptr mbedtls_net_context; + client_ctx: ptr mbedtls_net_context; + client_ip: pointer; buf_size: uint; ip_len: ptr uint): cint {. + importc, cdecl.} +proc mbedtls_net_poll*(ctx: ptr mbedtls_net_context; rw: uint32; timeout: uint32): cint {. + importc, cdecl.} +proc mbedtls_net_set_block*(ctx: ptr mbedtls_net_context): cint {.importc, cdecl.} +proc mbedtls_net_set_nonblock*(ctx: ptr mbedtls_net_context): cint {.importc, + cdecl.} +proc mbedtls_net_usleep*(usec: culong) {.importc, cdecl.} +proc mbedtls_net_recv*(ctx: pointer; buf: ptr byte; len: uint): cint {. + importc, cdecl.} +proc mbedtls_net_send*(ctx: pointer; buf: ptr byte; len: uint): cint {. + importc, cdecl.} +proc mbedtls_net_recv_timeout*(ctx: pointer; buf: ptr byte; len: uint; + timeout: uint32): cint {.importc, cdecl.} +proc mbedtls_net_close*(ctx: ptr mbedtls_net_context) {.importc, cdecl.} +proc mbedtls_net_free*(ctx: ptr mbedtls_net_context) {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/nist_kw.nim b/webrtc/mbedtls/nist_kw.nim new file mode 100644 index 0000000..f610f92 --- /dev/null +++ b/webrtc/mbedtls/nist_kw.nim @@ -0,0 +1,94 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "cipher" +import "platform_util" +import "platform_time" +# Generated @ 2023-05-11T11:19:11+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/nist_kw.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(mbedtls_nist_kw_mode_t) +const + MBEDTLS_KW_MODE_KW* = (0).mbedtls_nist_kw_mode_t + MBEDTLS_KW_MODE_KWP* = (1).mbedtls_nist_kw_mode_t +type + mbedtls_nist_kw_context* {.bycopy.} = object + private_cipher_ctx*: mbedtls_cipher_context_t + +proc mbedtls_nist_kw_init*(ctx: ptr mbedtls_nist_kw_context) {.importc, cdecl.} +proc mbedtls_nist_kw_setkey*(ctx: ptr mbedtls_nist_kw_context; + cipher: mbedtls_cipher_id_t; key: ptr byte; + keybits: cuint; is_wrap: cint): cint {.importc, + cdecl.} +proc mbedtls_nist_kw_free*(ctx: ptr mbedtls_nist_kw_context) {.importc, cdecl.} +proc mbedtls_nist_kw_wrap*(ctx: ptr mbedtls_nist_kw_context; + mode: mbedtls_nist_kw_mode_t; input: ptr byte; + in_len: uint; output: ptr byte; out_len: ptr uint; + out_size: uint): cint {.importc, cdecl.} +proc mbedtls_nist_kw_unwrap*(ctx: ptr mbedtls_nist_kw_context; + mode: mbedtls_nist_kw_mode_t; input: ptr byte; + in_len: uint; output: ptr byte; + out_len: ptr uint; out_size: uint): cint {.importc, + cdecl.} +proc mbedtls_nist_kw_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/oid.nim b/webrtc/mbedtls/oid.nim new file mode 100644 index 0000000..de7cc44 --- /dev/null +++ b/webrtc/mbedtls/oid.nim @@ -0,0 +1,267 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "asn1" +import "pk" +import "md" +import "ecp" +import "cipher" +# Generated @ 2023-05-11T11:19:12+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/oid.h + +# const 'MBEDTLS_OID_RSA_COMPANY' has unsupported value 'MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US MBEDTLS_OID_ORG_RSA_DATA_SECURITY' +# const 'MBEDTLS_OID_ANSI_X9_62' has unsupported value 'MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US MBEDTLS_OID_ORG_ANSI_X9_62' +# const 'MBEDTLS_OID_OIW_SECSIG' has unsupported value 'MBEDTLS_OID_ORG_OIW "\x03"' +# const 'MBEDTLS_OID_OIW_SECSIG_ALG' has unsupported value 'MBEDTLS_OID_OIW_SECSIG "\x02"' +# const 'MBEDTLS_OID_OIW_SECSIG_SHA1' has unsupported value 'MBEDTLS_OID_OIW_SECSIG_ALG "\x1a"' +# const 'MBEDTLS_OID_CERTICOM' has unsupported value 'MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_CERTICOM' +# const 'MBEDTLS_OID_TELETRUST' has unsupported value 'MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_TELETRUST' +# const 'MBEDTLS_OID_ISO_ITU_US_ORG' has unsupported value 'MBEDTLS_OID_ISO_ITU_COUNTRY MBEDTLS_OID_COUNTRY_US MBEDTLS_OID_ORGANIZATION' +# const 'MBEDTLS_OID_GOV' has unsupported value 'MBEDTLS_OID_ISO_ITU_US_ORG MBEDTLS_OID_ORG_GOV' +# const 'MBEDTLS_OID_NETSCAPE' has unsupported value 'MBEDTLS_OID_ISO_ITU_US_ORG MBEDTLS_OID_ORG_NETSCAPE' +# const 'MBEDTLS_OID_ID_CE' has unsupported value 'MBEDTLS_OID_ISO_CCITT_DS "\x1D"' +# const 'MBEDTLS_OID_NIST_ALG' has unsupported value 'MBEDTLS_OID_GOV "\x03\x04"' +# const 'MBEDTLS_OID_INTERNET' has unsupported value 'MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_DOD "\x01"' +# const 'MBEDTLS_OID_PKIX' has unsupported value 'MBEDTLS_OID_INTERNET "\x05\x05\x07"' +# const 'MBEDTLS_OID_AT' has unsupported value 'MBEDTLS_OID_ISO_CCITT_DS "\x04"' +# const 'MBEDTLS_OID_AT_CN' has unsupported value 'MBEDTLS_OID_AT "\x03"' +# const 'MBEDTLS_OID_AT_SUR_NAME' has unsupported value 'MBEDTLS_OID_AT "\x04"' +# const 'MBEDTLS_OID_AT_SERIAL_NUMBER' has unsupported value 'MBEDTLS_OID_AT "\x05"' +# const 'MBEDTLS_OID_AT_COUNTRY' has unsupported value 'MBEDTLS_OID_AT "\x06"' +# const 'MBEDTLS_OID_AT_LOCALITY' has unsupported value 'MBEDTLS_OID_AT "\x07"' +# const 'MBEDTLS_OID_AT_STATE' has unsupported value 'MBEDTLS_OID_AT "\x08"' +# const 'MBEDTLS_OID_AT_ORGANIZATION' has unsupported value 'MBEDTLS_OID_AT "\x0A"' +# const 'MBEDTLS_OID_AT_ORG_UNIT' has unsupported value 'MBEDTLS_OID_AT "\x0B"' +# const 'MBEDTLS_OID_AT_TITLE' has unsupported value 'MBEDTLS_OID_AT "\x0C"' +# const 'MBEDTLS_OID_AT_POSTAL_ADDRESS' has unsupported value 'MBEDTLS_OID_AT "\x10"' +# const 'MBEDTLS_OID_AT_POSTAL_CODE' has unsupported value 'MBEDTLS_OID_AT "\x11"' +# const 'MBEDTLS_OID_AT_GIVEN_NAME' has unsupported value 'MBEDTLS_OID_AT "\x2A"' +# const 'MBEDTLS_OID_AT_INITIALS' has unsupported value 'MBEDTLS_OID_AT "\x2B"' +# const 'MBEDTLS_OID_AT_GENERATION_QUALIFIER' has unsupported value 'MBEDTLS_OID_AT "\x2C"' +# const 'MBEDTLS_OID_AT_UNIQUE_IDENTIFIER' has unsupported value 'MBEDTLS_OID_AT "\x2D"' +# const 'MBEDTLS_OID_AT_DN_QUALIFIER' has unsupported value 'MBEDTLS_OID_AT "\x2E"' +# const 'MBEDTLS_OID_AT_PSEUDONYM' has unsupported value 'MBEDTLS_OID_AT "\x41"' +# const 'MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER' has unsupported value 'MBEDTLS_OID_ID_CE "\x23"' +# const 'MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER' has unsupported value 'MBEDTLS_OID_ID_CE "\x0E"' +# const 'MBEDTLS_OID_KEY_USAGE' has unsupported value 'MBEDTLS_OID_ID_CE "\x0F"' +# const 'MBEDTLS_OID_CERTIFICATE_POLICIES' has unsupported value 'MBEDTLS_OID_ID_CE "\x20"' +# const 'MBEDTLS_OID_POLICY_MAPPINGS' has unsupported value 'MBEDTLS_OID_ID_CE "\x21"' +# const 'MBEDTLS_OID_SUBJECT_ALT_NAME' has unsupported value 'MBEDTLS_OID_ID_CE "\x11"' +# const 'MBEDTLS_OID_ISSUER_ALT_NAME' has unsupported value 'MBEDTLS_OID_ID_CE "\x12"' +# const 'MBEDTLS_OID_SUBJECT_DIRECTORY_ATTRS' has unsupported value 'MBEDTLS_OID_ID_CE "\x09"' +# const 'MBEDTLS_OID_BASIC_CONSTRAINTS' has unsupported value 'MBEDTLS_OID_ID_CE "\x13"' +# const 'MBEDTLS_OID_NAME_CONSTRAINTS' has unsupported value 'MBEDTLS_OID_ID_CE "\x1E"' +# const 'MBEDTLS_OID_POLICY_CONSTRAINTS' has unsupported value 'MBEDTLS_OID_ID_CE "\x24"' +# const 'MBEDTLS_OID_EXTENDED_KEY_USAGE' has unsupported value 'MBEDTLS_OID_ID_CE "\x25"' +# const 'MBEDTLS_OID_CRL_DISTRIBUTION_POINTS' has unsupported value 'MBEDTLS_OID_ID_CE "\x1F"' +# const 'MBEDTLS_OID_INIHIBIT_ANYPOLICY' has unsupported value 'MBEDTLS_OID_ID_CE "\x36"' +# const 'MBEDTLS_OID_FRESHEST_CRL' has unsupported value 'MBEDTLS_OID_ID_CE "\x2E"' +# const 'MBEDTLS_OID_ANY_POLICY' has unsupported value 'MBEDTLS_OID_CERTIFICATE_POLICIES "\x00"' +# const 'MBEDTLS_OID_NS_CERT' has unsupported value 'MBEDTLS_OID_NETSCAPE "\x01"' +# const 'MBEDTLS_OID_NS_CERT_TYPE' has unsupported value 'MBEDTLS_OID_NS_CERT "\x01"' +# const 'MBEDTLS_OID_NS_BASE_URL' has unsupported value 'MBEDTLS_OID_NS_CERT "\x02"' +# const 'MBEDTLS_OID_NS_REVOCATION_URL' has unsupported value 'MBEDTLS_OID_NS_CERT "\x03"' +# const 'MBEDTLS_OID_NS_CA_REVOCATION_URL' has unsupported value 'MBEDTLS_OID_NS_CERT "\x04"' +# const 'MBEDTLS_OID_NS_RENEWAL_URL' has unsupported value 'MBEDTLS_OID_NS_CERT "\x07"' +# const 'MBEDTLS_OID_NS_CA_POLICY_URL' has unsupported value 'MBEDTLS_OID_NS_CERT "\x08"' +# const 'MBEDTLS_OID_NS_SSL_SERVER_NAME' has unsupported value 'MBEDTLS_OID_NS_CERT "\x0C"' +# const 'MBEDTLS_OID_NS_COMMENT' has unsupported value 'MBEDTLS_OID_NS_CERT "\x0D"' +# const 'MBEDTLS_OID_NS_DATA_TYPE' has unsupported value 'MBEDTLS_OID_NETSCAPE "\x02"' +# const 'MBEDTLS_OID_NS_CERT_SEQUENCE' has unsupported value 'MBEDTLS_OID_NS_DATA_TYPE "\x05"' +# const 'MBEDTLS_OID_PRIVATE_KEY_USAGE_PERIOD' has unsupported value 'MBEDTLS_OID_ID_CE "\x10"' +# const 'MBEDTLS_OID_CRL_NUMBER' has unsupported value 'MBEDTLS_OID_ID_CE "\x14"' +# const 'MBEDTLS_OID_ANY_EXTENDED_KEY_USAGE' has unsupported value 'MBEDTLS_OID_EXTENDED_KEY_USAGE "\x00"' +# const 'MBEDTLS_OID_KP' has unsupported value 'MBEDTLS_OID_PKIX "\x03"' +# const 'MBEDTLS_OID_SERVER_AUTH' has unsupported value 'MBEDTLS_OID_KP "\x01"' +# const 'MBEDTLS_OID_CLIENT_AUTH' has unsupported value 'MBEDTLS_OID_KP "\x02"' +# const 'MBEDTLS_OID_CODE_SIGNING' has unsupported value 'MBEDTLS_OID_KP "\x03"' +# const 'MBEDTLS_OID_EMAIL_PROTECTION' has unsupported value 'MBEDTLS_OID_KP "\x04"' +# const 'MBEDTLS_OID_TIME_STAMPING' has unsupported value 'MBEDTLS_OID_KP "\x08"' +# const 'MBEDTLS_OID_OCSP_SIGNING' has unsupported value 'MBEDTLS_OID_KP "\x09"' +# const 'MBEDTLS_OID_WISUN_FAN' has unsupported value 'MBEDTLS_OID_INTERNET "\x04\x01\x82\xe4\x25\x01"' +# const 'MBEDTLS_OID_ON' has unsupported value 'MBEDTLS_OID_PKIX "\x08"' +# const 'MBEDTLS_OID_ON_HW_MODULE_NAME' has unsupported value 'MBEDTLS_OID_ON "\x04"' +# const 'MBEDTLS_OID_PKCS' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x01"' +# const 'MBEDTLS_OID_PKCS1' has unsupported value 'MBEDTLS_OID_PKCS "\x01"' +# const 'MBEDTLS_OID_PKCS5' has unsupported value 'MBEDTLS_OID_PKCS "\x05"' +# const 'MBEDTLS_OID_PKCS7' has unsupported value 'MBEDTLS_OID_PKCS "\x07"' +# const 'MBEDTLS_OID_PKCS9' has unsupported value 'MBEDTLS_OID_PKCS "\x09"' +# const 'MBEDTLS_OID_PKCS12' has unsupported value 'MBEDTLS_OID_PKCS "\x0c"' +# const 'MBEDTLS_OID_PKCS1_RSA' has unsupported value 'MBEDTLS_OID_PKCS1 "\x01"' +# const 'MBEDTLS_OID_PKCS1_MD5' has unsupported value 'MBEDTLS_OID_PKCS1 "\x04"' +# const 'MBEDTLS_OID_PKCS1_SHA1' has unsupported value 'MBEDTLS_OID_PKCS1 "\x05"' +# const 'MBEDTLS_OID_PKCS1_SHA224' has unsupported value 'MBEDTLS_OID_PKCS1 "\x0e"' +# const 'MBEDTLS_OID_PKCS1_SHA256' has unsupported value 'MBEDTLS_OID_PKCS1 "\x0b"' +# const 'MBEDTLS_OID_PKCS1_SHA384' has unsupported value 'MBEDTLS_OID_PKCS1 "\x0c"' +# const 'MBEDTLS_OID_PKCS1_SHA512' has unsupported value 'MBEDTLS_OID_PKCS1 "\x0d"' +# const 'MBEDTLS_OID_PKCS9_EMAIL' has unsupported value 'MBEDTLS_OID_PKCS9 "\x01"' +# const 'MBEDTLS_OID_RSASSA_PSS' has unsupported value 'MBEDTLS_OID_PKCS1 "\x0a"' +# const 'MBEDTLS_OID_MGF1' has unsupported value 'MBEDTLS_OID_PKCS1 "\x08"' +# const 'MBEDTLS_OID_DIGEST_ALG_MD5' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x02\x05"' +# const 'MBEDTLS_OID_DIGEST_ALG_SHA1' has unsupported value 'MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_OIW_SECSIG_SHA1' +# const 'MBEDTLS_OID_DIGEST_ALG_SHA224' has unsupported value 'MBEDTLS_OID_NIST_ALG "\x02\x04"' +# const 'MBEDTLS_OID_DIGEST_ALG_SHA256' has unsupported value 'MBEDTLS_OID_NIST_ALG "\x02\x01"' +# const 'MBEDTLS_OID_DIGEST_ALG_SHA384' has unsupported value 'MBEDTLS_OID_NIST_ALG "\x02\x02"' +# const 'MBEDTLS_OID_DIGEST_ALG_SHA512' has unsupported value 'MBEDTLS_OID_NIST_ALG "\x02\x03"' +# const 'MBEDTLS_OID_DIGEST_ALG_RIPEMD160' has unsupported value 'MBEDTLS_OID_TELETRUST "\x03\x02\x01"' +# const 'MBEDTLS_OID_HMAC_SHA1' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x02\x07"' +# const 'MBEDTLS_OID_HMAC_SHA224' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x02\x08"' +# const 'MBEDTLS_OID_HMAC_SHA256' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x02\x09"' +# const 'MBEDTLS_OID_HMAC_SHA384' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x02\x0A"' +# const 'MBEDTLS_OID_HMAC_SHA512' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x02\x0B"' +# const 'MBEDTLS_OID_DES_CBC' has unsupported value 'MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_OIW_SECSIG_ALG "\x07"' +# const 'MBEDTLS_OID_DES_EDE3_CBC' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x03\x07"' +# const 'MBEDTLS_OID_AES' has unsupported value 'MBEDTLS_OID_NIST_ALG "\x01"' +# const 'MBEDTLS_OID_AES128_KW' has unsupported value 'MBEDTLS_OID_AES "\x05"' +# const 'MBEDTLS_OID_AES128_KWP' has unsupported value 'MBEDTLS_OID_AES "\x08"' +# const 'MBEDTLS_OID_AES192_KW' has unsupported value 'MBEDTLS_OID_AES "\x19"' +# const 'MBEDTLS_OID_AES192_KWP' has unsupported value 'MBEDTLS_OID_AES "\x1c"' +# const 'MBEDTLS_OID_AES256_KW' has unsupported value 'MBEDTLS_OID_AES "\x2d"' +# const 'MBEDTLS_OID_AES256_KWP' has unsupported value 'MBEDTLS_OID_AES "\x30"' +# const 'MBEDTLS_OID_PKCS5_PBKDF2' has unsupported value 'MBEDTLS_OID_PKCS5 "\x0c"' +# const 'MBEDTLS_OID_PKCS5_PBES2' has unsupported value 'MBEDTLS_OID_PKCS5 "\x0d"' +# const 'MBEDTLS_OID_PKCS5_PBMAC1' has unsupported value 'MBEDTLS_OID_PKCS5 "\x0e"' +# const 'MBEDTLS_OID_PKCS5_PBE_MD5_DES_CBC' has unsupported value 'MBEDTLS_OID_PKCS5 "\x03"' +# const 'MBEDTLS_OID_PKCS5_PBE_MD5_RC2_CBC' has unsupported value 'MBEDTLS_OID_PKCS5 "\x06"' +# const 'MBEDTLS_OID_PKCS5_PBE_SHA1_DES_CBC' has unsupported value 'MBEDTLS_OID_PKCS5 "\x0a"' +# const 'MBEDTLS_OID_PKCS5_PBE_SHA1_RC2_CBC' has unsupported value 'MBEDTLS_OID_PKCS5 "\x0b"' +# const 'MBEDTLS_OID_PKCS7_DATA' has unsupported value 'MBEDTLS_OID_PKCS7 "\x01"' +# const 'MBEDTLS_OID_PKCS7_SIGNED_DATA' has unsupported value 'MBEDTLS_OID_PKCS7 "\x02"' +# const 'MBEDTLS_OID_PKCS7_ENVELOPED_DATA' has unsupported value 'MBEDTLS_OID_PKCS7 "\x03"' +# const 'MBEDTLS_OID_PKCS7_SIGNED_AND_ENVELOPED_DATA' has unsupported value 'MBEDTLS_OID_PKCS7 "\x04"' +# const 'MBEDTLS_OID_PKCS7_DIGESTED_DATA' has unsupported value 'MBEDTLS_OID_PKCS7 "\x05"' +# const 'MBEDTLS_OID_PKCS7_ENCRYPTED_DATA' has unsupported value 'MBEDTLS_OID_PKCS7 "\x06"' +# const 'MBEDTLS_OID_PKCS9_CSR_EXT_REQ' has unsupported value 'MBEDTLS_OID_PKCS9 "\x0e"' +# const 'MBEDTLS_OID_PKCS12_PBE' has unsupported value 'MBEDTLS_OID_PKCS12 "\x01"' +# const 'MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC' has unsupported value 'MBEDTLS_OID_PKCS12_PBE "\x03"' +# const 'MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC' has unsupported value 'MBEDTLS_OID_PKCS12_PBE "\x04"' +# const 'MBEDTLS_OID_PKCS12_PBE_SHA1_RC2_128_CBC' has unsupported value 'MBEDTLS_OID_PKCS12_PBE "\x05"' +# const 'MBEDTLS_OID_PKCS12_PBE_SHA1_RC2_40_CBC' has unsupported value 'MBEDTLS_OID_PKCS12_PBE "\x06"' +# const 'MBEDTLS_OID_EC_ALG_UNRESTRICTED' has unsupported value 'MBEDTLS_OID_ANSI_X9_62 "\x02\01"' +# const 'MBEDTLS_OID_EC_ALG_ECDH' has unsupported value 'MBEDTLS_OID_CERTICOM "\x01\x0c"' +# const 'MBEDTLS_OID_EC_GRP_SECP192R1' has unsupported value 'MBEDTLS_OID_ANSI_X9_62 "\x03\x01\x01"' +# const 'MBEDTLS_OID_EC_GRP_SECP224R1' has unsupported value 'MBEDTLS_OID_CERTICOM "\x00\x21"' +# const 'MBEDTLS_OID_EC_GRP_SECP256R1' has unsupported value 'MBEDTLS_OID_ANSI_X9_62 "\x03\x01\x07"' +# const 'MBEDTLS_OID_EC_GRP_SECP384R1' has unsupported value 'MBEDTLS_OID_CERTICOM "\x00\x22"' +# const 'MBEDTLS_OID_EC_GRP_SECP521R1' has unsupported value 'MBEDTLS_OID_CERTICOM "\x00\x23"' +# const 'MBEDTLS_OID_EC_GRP_SECP192K1' has unsupported value 'MBEDTLS_OID_CERTICOM "\x00\x1f"' +# const 'MBEDTLS_OID_EC_GRP_SECP224K1' has unsupported value 'MBEDTLS_OID_CERTICOM "\x00\x20"' +# const 'MBEDTLS_OID_EC_GRP_SECP256K1' has unsupported value 'MBEDTLS_OID_CERTICOM "\x00\x0a"' +# const 'MBEDTLS_OID_EC_BRAINPOOL_V1' has unsupported value 'MBEDTLS_OID_TELETRUST "\x03\x03\x02\x08\x01\x01"' +# const 'MBEDTLS_OID_EC_GRP_BP256R1' has unsupported value 'MBEDTLS_OID_EC_BRAINPOOL_V1 "\x07"' +# const 'MBEDTLS_OID_EC_GRP_BP384R1' has unsupported value 'MBEDTLS_OID_EC_BRAINPOOL_V1 "\x0B"' +# const 'MBEDTLS_OID_EC_GRP_BP512R1' has unsupported value 'MBEDTLS_OID_EC_BRAINPOOL_V1 "\x0D"' +# const 'MBEDTLS_OID_ANSI_X9_62_FIELD_TYPE' has unsupported value 'MBEDTLS_OID_ANSI_X9_62 "\x01"' +# const 'MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_FIELD_TYPE "\x01"' +# const 'MBEDTLS_OID_ANSI_X9_62_SIG' has unsupported value 'MBEDTLS_OID_ANSI_X9_62 "\x04"' +# const 'MBEDTLS_OID_ANSI_X9_62_SIG_SHA2' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_SIG "\x03"' +# const 'MBEDTLS_OID_ECDSA_SHA1' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_SIG "\x01"' +# const 'MBEDTLS_OID_ECDSA_SHA224' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x01"' +# const 'MBEDTLS_OID_ECDSA_SHA256' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x02"' +# const 'MBEDTLS_OID_ECDSA_SHA384' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x03"' +# const 'MBEDTLS_OID_ECDSA_SHA512' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x04"' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_OID_NOT_FOUND* = -0x0000002E + MBEDTLS_ERR_OID_BUF_TOO_SMALL* = -0x0000000B + MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER* = (1 shl typeof(1)(0)) + MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER* = (1 shl typeof(1)(1)) + MBEDTLS_OID_X509_EXT_KEY_USAGE* = (1 shl typeof(1)(2)) + MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES* = (1 shl typeof(1)(3)) + MBEDTLS_OID_X509_EXT_POLICY_MAPPINGS* = (1 shl typeof(1)(4)) + MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME* = (1 shl typeof(1)(5)) + MBEDTLS_OID_X509_EXT_ISSUER_ALT_NAME* = (1 shl typeof(1)(6)) + MBEDTLS_OID_X509_EXT_SUBJECT_DIRECTORY_ATTRS* = (1 shl typeof(1)(7)) + MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS* = (1 shl typeof(1)(8)) + MBEDTLS_OID_X509_EXT_NAME_CONSTRAINTS* = (1 shl typeof(1)(9)) + MBEDTLS_OID_X509_EXT_POLICY_CONSTRAINTS* = (1 shl typeof(1)(10)) + MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE* = (1 shl typeof(1)(11)) + MBEDTLS_OID_X509_EXT_CRL_DISTRIBUTION_POINTS* = (1 shl typeof(1)(12)) + MBEDTLS_OID_X509_EXT_INIHIBIT_ANYPOLICY* = (1 shl typeof(1)(13)) + MBEDTLS_OID_X509_EXT_FRESHEST_CRL* = (1 shl typeof(1)(14)) + MBEDTLS_OID_X509_EXT_NS_CERT_TYPE* = (1 shl typeof(1)(16)) + MBEDTLS_OID_ISO_MEMBER_BODIES* = "*" + MBEDTLS_OID_ISO_IDENTIFIED_ORG* = "+" + MBEDTLS_OID_ISO_CCITT_DS* = "U" + MBEDTLS_OID_ISO_ITU_COUNTRY* = "`" + MBEDTLS_OID_COUNTRY_US* = "†H" + MBEDTLS_OID_ORG_RSA_DATA_SECURITY* = "†÷\r" + MBEDTLS_OID_ORG_ANSI_X9_62* = "Î=" + MBEDTLS_OID_ORG_DOD* = "\x06" + MBEDTLS_OID_ORG_OIW* = "\x0E" + MBEDTLS_OID_ORG_CERTICOM* = "\x04" + MBEDTLS_OID_ORG_TELETRUST* = "$" + MBEDTLS_OID_ORGANIZATION* = "\x01" + MBEDTLS_OID_ORG_GOV* = "e" + MBEDTLS_OID_ORG_NETSCAPE* = "†øB" + MBEDTLS_OID_UID* = "\t’&‰“ò,d\x01\x01" + MBEDTLS_OID_DOMAIN_COMPONENT* = "\t’&‰“ò,d\x01\x19" + MBEDTLS_OID_RSA_SHA_OBS* = "+\x0E\x03\x02\x1D" +type + mbedtls_oid_descriptor_t* {.bycopy.} = object + private_asn1*: cstring + private_asn1_len*: uint + private_name*: cstring + private_description*: cstring + +proc mbedtls_oid_get_numeric_string*(buf: cstring; size: uint; + oid: ptr mbedtls_asn1_buf): cint {.importc, + cdecl.} +proc mbedtls_oid_get_x509_ext_type*(oid: ptr mbedtls_asn1_buf; + ext_type: ptr cint): cint {.importc, cdecl.} +proc mbedtls_oid_get_attr_short_name*(oid: ptr mbedtls_asn1_buf; + short_name: ptr cstring): cint {.importc, + cdecl.} +proc mbedtls_oid_get_pk_alg*(oid: ptr mbedtls_asn1_buf; + pk_alg: ptr mbedtls_pk_type_t): cint {.importc, + cdecl.} +proc mbedtls_oid_get_oid_by_pk_alg*(pk_alg: mbedtls_pk_type_t; oid: ptr cstring; + olen: ptr uint): cint {.importc, cdecl.} +proc mbedtls_oid_get_ec_grp*(oid: ptr mbedtls_asn1_buf; + grp_id: ptr mbedtls_ecp_group_id): cint {.importc, + cdecl.} +proc mbedtls_oid_get_oid_by_ec_grp*(grp_id: mbedtls_ecp_group_id; + oid: ptr cstring; olen: ptr uint): cint {. + importc, cdecl.} +proc mbedtls_oid_get_sig_alg*(oid: ptr mbedtls_asn1_buf; + md_alg: ptr mbedtls_md_type_t; + pk_alg: ptr mbedtls_pk_type_t): cint {.importc, + cdecl.} +proc mbedtls_oid_get_sig_alg_desc*(oid: ptr mbedtls_asn1_buf; desc: ptr cstring): cint {. + importc, cdecl.} +proc mbedtls_oid_get_oid_by_sig_alg*(pk_alg: mbedtls_pk_type_t; + md_alg: mbedtls_md_type_t; + oid: ptr cstring; olen: ptr uint): cint {. + importc, cdecl.} +proc mbedtls_oid_get_md_hmac*(oid: ptr mbedtls_asn1_buf; + md_hmac: ptr mbedtls_md_type_t): cint {.importc, + cdecl.} +proc mbedtls_oid_get_md_alg*(oid: ptr mbedtls_asn1_buf; + md_alg: ptr mbedtls_md_type_t): cint {.importc, + cdecl.} +proc mbedtls_oid_get_extended_key_usage*(oid: ptr mbedtls_asn1_buf; + desc: ptr cstring): cint {.importc, cdecl.} +proc mbedtls_oid_get_certificate_policies*(oid: ptr mbedtls_asn1_buf; + desc: ptr cstring): cint {.importc, cdecl.} +proc mbedtls_oid_get_oid_by_md*(md_alg: mbedtls_md_type_t; oid: ptr cstring; + olen: ptr uint): cint {.importc, cdecl.} +proc mbedtls_oid_get_cipher_alg*(oid: ptr mbedtls_asn1_buf; + cipher_alg: ptr mbedtls_cipher_type_t): cint {. + importc, cdecl.} +proc mbedtls_oid_get_pkcs12_pbe_alg*(oid: ptr mbedtls_asn1_buf; + md_alg: ptr mbedtls_md_type_t; + cipher_alg: ptr mbedtls_cipher_type_t): cint {. + importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/pem.nim b/webrtc/mbedtls/pem.nim new file mode 100644 index 0000000..f927b76 --- /dev/null +++ b/webrtc/mbedtls/pem.nim @@ -0,0 +1,52 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "aes" +import "base64" +import "des" +import "constant_time" +{.compile: "./mbedtls/library/pem.c".} +# Generated @ 2023-05-11T11:19:12+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/pem.h + +# proc 'mbedtls_pem_get_buffer' skipped - static inline procs cannot work with '--noHeader | -H' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT* = -0x00001080 + MBEDTLS_ERR_PEM_INVALID_DATA* = -0x00001100 + MBEDTLS_ERR_PEM_ALLOC_FAILED* = -0x00001180 + MBEDTLS_ERR_PEM_INVALID_ENC_IV* = -0x00001200 + MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG* = -0x00001280 + MBEDTLS_ERR_PEM_PASSWORD_REQUIRED* = -0x00001300 + MBEDTLS_ERR_PEM_PASSWORD_MISMATCH* = -0x00001380 + MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE* = -0x00001400 + MBEDTLS_ERR_PEM_BAD_INPUT_DATA* = -0x00001480 +type + mbedtls_pem_context* {.bycopy.} = object + private_buf*: ptr byte + private_buflen*: uint + private_info*: ptr byte + +proc mbedtls_pem_init*(ctx: ptr mbedtls_pem_context) {.importc, cdecl.} +proc mbedtls_pem_read_buffer*(ctx: ptr mbedtls_pem_context; header: cstring; + footer: cstring; data: ptr byte; + pwd: ptr byte; pwdlen: uint; use_len: ptr uint): cint {. + importc, cdecl.} +proc mbedtls_pem_free*(ctx: ptr mbedtls_pem_context) {.importc, cdecl.} +proc mbedtls_pem_write_buffer*(header: cstring; footer: cstring; + der_data: ptr byte; der_len: uint; + buf: ptr byte; buf_len: uint; olen: ptr uint): cint {. + importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/pk.nim b/webrtc/mbedtls/pk.nim new file mode 100644 index 0000000..fe8e9e4 --- /dev/null +++ b/webrtc/mbedtls/pk.nim @@ -0,0 +1,226 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "pem" +import "md" +import "platform_time" +import "rsa" +import "ecp" +import "ecdh" +import "ecdsa" +import "psa_util" +import "psa/crypto" +{.compile: "./mbedtls/library/pk_wrap.c".} +{.compile: "./mbedtls/library/pk.c".} +{.compile: "./mbedtls/library/pkparse.c".} +{.compile: "./mbedtls/library/pkwrite.c".} +# Generated @ 2023-05-11T11:19:12+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/pk.h + +# const 'MBEDTLS_PK_SIGNATURE_MAX_SIZE' has unsupported value 'MBEDTLS_MPI_MAX_SIZE' +# proc 'mbedtls_pk_get_len' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_pk_rsa' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_pk_ec' skipped - static inline procs cannot work with '--noHeader | -H' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(mbedtls_pk_type_t) +defineEnum(mbedtls_pk_debug_type) +const + MBEDTLS_ERR_PK_ALLOC_FAILED* = -0x00003F80 + MBEDTLS_ERR_PK_TYPE_MISMATCH* = -0x00003F00 + MBEDTLS_ERR_PK_BAD_INPUT_DATA* = -0x00003E80 + MBEDTLS_ERR_PK_FILE_IO_ERROR* = -0x00003E00 + MBEDTLS_ERR_PK_KEY_INVALID_VERSION* = -0x00003D80 + MBEDTLS_ERR_PK_KEY_INVALID_FORMAT* = -0x00003D00 + MBEDTLS_ERR_PK_UNKNOWN_PK_ALG* = -0x00003C80 + MBEDTLS_ERR_PK_PASSWORD_REQUIRED* = -0x00003C00 + MBEDTLS_ERR_PK_PASSWORD_MISMATCH* = -0x00003B80 + MBEDTLS_ERR_PK_INVALID_PUBKEY* = -0x00003B00 + MBEDTLS_ERR_PK_INVALID_ALG* = -0x00003A80 + MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE* = -0x00003A00 + MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE* = -0x00003980 + MBEDTLS_ERR_PK_SIG_LEN_MISMATCH* = -0x00003900 + MBEDTLS_ERR_PK_BUFFER_TOO_SMALL* = -0x00003880 + MBEDTLS_PK_NONE* = (0).mbedtls_pk_type_t + MBEDTLS_PK_RSA* = (MBEDTLS_PK_NONE + 1).mbedtls_pk_type_t + MBEDTLS_PK_ECKEY* = (MBEDTLS_PK_RSA + 1).mbedtls_pk_type_t + MBEDTLS_PK_ECKEY_DH* = (MBEDTLS_PK_ECKEY + 1).mbedtls_pk_type_t + MBEDTLS_PK_ECDSA* = (MBEDTLS_PK_ECKEY_DH + 1).mbedtls_pk_type_t + MBEDTLS_PK_RSA_ALT* = (MBEDTLS_PK_ECDSA + 1).mbedtls_pk_type_t + MBEDTLS_PK_RSASSA_PSS* = (MBEDTLS_PK_RSA_ALT + 1).mbedtls_pk_type_t + MBEDTLS_PK_OPAQUE* = (MBEDTLS_PK_RSASSA_PSS + 1).mbedtls_pk_type_t + MBEDTLS_PK_SIGNATURE_MAX_SIZE* = 0 + MBEDTLS_PK_DEBUG_NONE* = (0).mbedtls_pk_debug_type + MBEDTLS_PK_DEBUG_MPI* = (MBEDTLS_PK_DEBUG_NONE + 1).mbedtls_pk_debug_type + MBEDTLS_PK_DEBUG_ECP* = (MBEDTLS_PK_DEBUG_MPI + 1).mbedtls_pk_debug_type + MBEDTLS_PK_DEBUG_MAX_ITEMS* = 3 +type + mbedtls_pk_rsassa_pss_options* {.bycopy.} = object + mgf1_hash_id*: mbedtls_md_type_t + expected_salt_len*: cint + + mbedtls_pk_debug_item* {.bycopy.} = object + private_type*: mbedtls_pk_debug_type + private_name*: cstring + private_value*: pointer + + mbedtls_pk_info_t* {.incompleteStruct.} = object + mbedtls_pk_context* {.bycopy.} = object + private_pk_info*: ptr mbedtls_pk_info_t + private_pk_ctx*: pointer + + mbedtls_pk_restart_ctx* = object + mbedtls_pk_rsa_alt_decrypt_func* = proc (ctx: pointer; olen: ptr uint; + input: ptr byte; output: ptr byte; output_max_len: uint): cint {.cdecl.} + mbedtls_pk_rsa_alt_sign_func* = proc (ctx: pointer; f_rng: proc (a1: pointer; + a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; + md_alg: mbedtls_md_type_t; + hashlen: cuint; hash: ptr byte; + sig: ptr byte): cint {.cdecl.} + mbedtls_pk_rsa_alt_key_len_func* = proc (ctx: pointer): uint {.cdecl.} +proc mbedtls_pk_info_from_type*(pk_type: mbedtls_pk_type_t): ptr mbedtls_pk_info_t {. + importc, cdecl.} +proc mbedtls_pk_init*(ctx: ptr mbedtls_pk_context) {.importc, cdecl.} +proc mbedtls_pk_free*(ctx: ptr mbedtls_pk_context) {.importc, cdecl.} +proc mbedtls_pk_setup*(ctx: ptr mbedtls_pk_context; info: ptr mbedtls_pk_info_t): cint {. + importc, cdecl.} +proc mbedtls_pk_setup_rsa_alt*(ctx: ptr mbedtls_pk_context; key: pointer; + decrypt_func: mbedtls_pk_rsa_alt_decrypt_func; + sign_func: mbedtls_pk_rsa_alt_sign_func; + key_len_func: mbedtls_pk_rsa_alt_key_len_func): cint {. + importc, cdecl.} +proc mbedtls_pk_get_bitlen*(ctx: ptr mbedtls_pk_context): uint {.importc, cdecl.} +proc mbedtls_pk_can_do*(ctx: ptr mbedtls_pk_context; `type`: mbedtls_pk_type_t): cint {. + importc, cdecl.} +proc mbedtls_pk_verify*(ctx: ptr mbedtls_pk_context; md_alg: mbedtls_md_type_t; + hash: ptr byte; hash_len: uint; sig: ptr byte; + sig_len: uint): cint {.importc, cdecl.} +proc mbedtls_pk_verify_restartable*(ctx: ptr mbedtls_pk_context; + md_alg: mbedtls_md_type_t; hash: ptr byte; + hash_len: uint; sig: ptr byte; + sig_len: uint; + rs_ctx: ptr mbedtls_pk_restart_ctx): cint {. + importc, cdecl.} +proc mbedtls_pk_verify_ext*(`type`: mbedtls_pk_type_t; options: pointer; + ctx: ptr mbedtls_pk_context; + md_alg: mbedtls_md_type_t; hash: ptr byte; + hash_len: uint; sig: ptr byte; sig_len: uint): cint {. + importc, cdecl.} +proc mbedtls_pk_sign*(ctx: ptr mbedtls_pk_context; md_alg: mbedtls_md_type_t; + hash: ptr byte; hash_len: uint; sig: ptr byte; + sig_size: uint; sig_len: ptr uint; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_pk_sign_ext*(pk_type: mbedtls_pk_type_t; + ctx: ptr mbedtls_pk_context; + md_alg: mbedtls_md_type_t; hash: ptr byte; + hash_len: uint; sig: ptr byte; sig_size: uint; + sig_len: ptr uint; f_rng: proc (a1: pointer; + a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, + cdecl.} +proc mbedtls_pk_sign_restartable*(ctx: ptr mbedtls_pk_context; + md_alg: mbedtls_md_type_t; hash: ptr byte; + hash_len: uint; sig: ptr byte; + sig_size: uint; sig_len: ptr uint; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; + rs_ctx: ptr mbedtls_pk_restart_ctx): cint {. + importc, cdecl.} +proc mbedtls_pk_decrypt*(ctx: ptr mbedtls_pk_context; input: ptr byte; + ilen: uint; output: ptr byte; olen: ptr uint; + osize: uint; f_rng: proc (a1: pointer; a2: ptr byte; + a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, cdecl.} +proc mbedtls_pk_encrypt*(ctx: ptr mbedtls_pk_context; input: ptr byte; + ilen: uint; output: ptr byte; olen: ptr uint; + osize: uint; f_rng: proc (a1: pointer; a2: ptr byte; + a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, cdecl.} +proc mbedtls_pk_check_pair*(pub: ptr mbedtls_pk_context; + prv: ptr mbedtls_pk_context; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_pk_debug*(ctx: ptr mbedtls_pk_context; + items: ptr mbedtls_pk_debug_item): cint {.importc, cdecl.} +proc mbedtls_pk_get_name*(ctx: ptr mbedtls_pk_context): cstring {.importc, cdecl.} +proc mbedtls_pk_get_type*(ctx: ptr mbedtls_pk_context): mbedtls_pk_type_t {. + importc, cdecl.} +proc mbedtls_pk_parse_key*(ctx: ptr mbedtls_pk_context; key: ptr byte; + keylen: uint; pwd: ptr byte; pwdlen: uint; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_pk_parse_public_key*(ctx: ptr mbedtls_pk_context; key: ptr byte; + keylen: uint): cint {.importc, cdecl.} +proc mbedtls_pk_parse_keyfile*(ctx: ptr mbedtls_pk_context; path: cstring; + password: cstring; f_rng: proc (a1: pointer; + a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, + cdecl.} +proc mbedtls_pk_parse_public_keyfile*(ctx: ptr mbedtls_pk_context; path: cstring): cint {. + importc, cdecl.} +proc mbedtls_pk_write_key_der*(ctx: ptr mbedtls_pk_context; buf: ptr byte; + size: uint): cint {.importc, cdecl.} +proc mbedtls_pk_write_pubkey_der*(ctx: ptr mbedtls_pk_context; buf: ptr byte; + size: uint): cint {.importc, cdecl.} +proc mbedtls_pk_write_pubkey_pem*(ctx: ptr mbedtls_pk_context; buf: ptr byte; + size: uint): cint {.importc, cdecl.} +proc mbedtls_pk_write_key_pem*(ctx: ptr mbedtls_pk_context; buf: ptr byte; + size: uint): cint {.importc, cdecl.} +proc mbedtls_pk_parse_subpubkey*(p: ptr ptr byte; `end`: ptr byte; + pk: ptr mbedtls_pk_context): cint {.importc, + cdecl.} +proc mbedtls_pk_write_pubkey*(p: ptr ptr byte; start: ptr byte; + key: ptr mbedtls_pk_context): cint {.importc, + cdecl.} +proc mbedtls_pk_load_file*(path: cstring; buf: ptr ptr byte; n: ptr uint): cint {. + importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/pkcs12.nim b/webrtc/mbedtls/pkcs12.nim new file mode 100644 index 0000000..b082ba0 --- /dev/null +++ b/webrtc/mbedtls/pkcs12.nim @@ -0,0 +1,47 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "md" +import "platform_time" +import "cipher" +import "asn1" +import "ctr_drbg" +import "hash_info" +{.compile: "./mbedtls/library/pkcs12.c".} +# Generated @ 2023-05-11T11:19:12+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/pkcs12.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA* = -0x00001F80 + MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE* = -0x00001F00 + MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT* = -0x00001E80 + MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH* = -0x00001E00 + MBEDTLS_PKCS12_DERIVE_KEY* = 1 + MBEDTLS_PKCS12_DERIVE_IV* = 2 + MBEDTLS_PKCS12_DERIVE_MAC_KEY* = 3 + MBEDTLS_PKCS12_PBE_DECRYPT* = 0 + MBEDTLS_PKCS12_PBE_ENCRYPT* = 1 +proc mbedtls_pkcs12_pbe*(pbe_params: ptr mbedtls_asn1_buf; mode: cint; + cipher_type: mbedtls_cipher_type_t; + md_type: mbedtls_md_type_t; pwd: ptr byte; + pwdlen: uint; input: ptr byte; len: uint; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_pkcs12_derivation*(data: ptr byte; datalen: uint; + pwd: ptr byte; pwdlen: uint; salt: ptr byte; + saltlen: uint; mbedtls_md: mbedtls_md_type_t; + id: cint; iterations: cint): cint {.importc, + cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/pkcs5.nim b/webrtc/mbedtls/pkcs5.nim new file mode 100644 index 0000000..275f8e3 --- /dev/null +++ b/webrtc/mbedtls/pkcs5.nim @@ -0,0 +1,50 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "asn1" +import "platform_time" +import "md" +import "cipher" +import "ctr_drbg" +import "rsa" +import "hash_info" +{.compile: "./mbedtls/library/pkcs5.c".} +# Generated @ 2023-05-11T11:19:12+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/pkcs5.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA* = -0x00002F80 + MBEDTLS_ERR_PKCS5_INVALID_FORMAT* = -0x00002F00 + MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE* = -0x00002E80 + MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH* = -0x00002E00 + MBEDTLS_PKCS5_DECRYPT* = 0 + MBEDTLS_PKCS5_ENCRYPT* = 1 +proc mbedtls_pkcs5_pbes2*(pbe_params: ptr mbedtls_asn1_buf; mode: cint; + pwd: ptr byte; pwdlen: uint; data: ptr byte; + datalen: uint; output: ptr byte): cint {.importc, + cdecl.} +proc mbedtls_pkcs5_pbkdf2_hmac_ext*(md_type: mbedtls_md_type_t; + password: ptr byte; plen: uint; + salt: ptr byte; slen: uint; + iteration_count: cuint; key_length: uint32; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_pkcs5_pbkdf2_hmac*(ctx: ptr mbedtls_md_context_t; + password: ptr byte; plen: uint; + salt: ptr byte; slen: uint; + iteration_count: cuint; key_length: uint32; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_pkcs5_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/pkcs7.nim b/webrtc/mbedtls/pkcs7.nim new file mode 100644 index 0000000..7bad6b6 --- /dev/null +++ b/webrtc/mbedtls/pkcs7.nim @@ -0,0 +1,135 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "asn1" +import "platform_time" +import "x509" +import "pk" +import "md" +import "rsa" +import "ecp" +import "ecdsa" +import "x509_crt" +import "x509_crl" +{.compile: "./mbedtls/library/pkcs7.c".} +# Generated @ 2023-05-11T11:19:12+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/pkcs7.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(mbedtls_pkcs7_type) +const + MBEDTLS_ERR_PKCS7_INVALID_FORMAT* = -0x00005300 + MBEDTLS_ERR_PKCS7_FEATURE_UNAVAILABLE* = -0x00005380 + MBEDTLS_ERR_PKCS7_INVALID_VERSION* = -0x00005400 + MBEDTLS_ERR_PKCS7_INVALID_CONTENT_INFO* = -0x00005480 + MBEDTLS_ERR_PKCS7_INVALID_ALG* = -0x00005500 + MBEDTLS_ERR_PKCS7_INVALID_CERT* = -0x00005580 + MBEDTLS_ERR_PKCS7_INVALID_SIGNATURE* = -0x00005600 + MBEDTLS_ERR_PKCS7_INVALID_SIGNER_INFO* = -0x00005680 + MBEDTLS_ERR_PKCS7_BAD_INPUT_DATA* = -0x00005700 + MBEDTLS_ERR_PKCS7_ALLOC_FAILED* = -0x00005780 + MBEDTLS_ERR_PKCS7_VERIFY_FAIL* = -0x00005800 + MBEDTLS_ERR_PKCS7_CERT_DATE_INVALID* = -0x00005880 + MBEDTLS_PKCS7_SUPPORTED_VERSION* = 0x00000001 + MBEDTLS_PKCS7_NONE* = (0).mbedtls_pkcs7_type + MBEDTLS_PKCS7_DATA* = (MBEDTLS_PKCS7_NONE + 1).mbedtls_pkcs7_type + MBEDTLS_PKCS7_SIGNED_DATA* = (MBEDTLS_PKCS7_DATA + 1).mbedtls_pkcs7_type + MBEDTLS_PKCS7_ENVELOPED_DATA* = (MBEDTLS_PKCS7_SIGNED_DATA + 1).mbedtls_pkcs7_type + MBEDTLS_PKCS7_SIGNED_AND_ENVELOPED_DATA* = (MBEDTLS_PKCS7_ENVELOPED_DATA + 1).mbedtls_pkcs7_type + MBEDTLS_PKCS7_DIGESTED_DATA* = (MBEDTLS_PKCS7_SIGNED_AND_ENVELOPED_DATA + 1).mbedtls_pkcs7_type + MBEDTLS_PKCS7_ENCRYPTED_DATA* = (MBEDTLS_PKCS7_DIGESTED_DATA + 1).mbedtls_pkcs7_type +type + mbedtls_pkcs7_buf* = mbedtls_asn1_buf + mbedtls_pkcs7_name* = mbedtls_asn1_named_data + mbedtls_pkcs7_sequence* = mbedtls_asn1_sequence + mbedtls_pkcs7_signer_info* {.bycopy.} = object + private_version*: cint + private_serial*: mbedtls_x509_buf + private_issuer*: mbedtls_x509_name + private_issuer_raw*: mbedtls_x509_buf + private_alg_identifier*: mbedtls_x509_buf + private_sig_alg_identifier*: mbedtls_x509_buf + private_sig*: mbedtls_x509_buf + private_next*: ptr mbedtls_pkcs7_signer_info + + mbedtls_pkcs7_signed_data* {.bycopy.} = object + private_version*: cint + private_digest_alg_identifiers*: mbedtls_pkcs7_buf + private_no_of_certs*: cint + private_certs*: mbedtls_x509_crt + private_no_of_crls*: cint + private_crl*: mbedtls_x509_crl + private_no_of_signers*: cint + private_signers*: mbedtls_pkcs7_signer_info + + mbedtls_pkcs7* {.bycopy.} = object + private_raw*: mbedtls_pkcs7_buf + private_signed_data*: mbedtls_pkcs7_signed_data + +proc mbedtls_pkcs7_init*(pkcs7: ptr mbedtls_pkcs7) {.importc, cdecl.} +proc mbedtls_pkcs7_parse_der*(pkcs7: ptr mbedtls_pkcs7; buf: ptr byte; + buflen: uint): cint {.importc, cdecl.} +proc mbedtls_pkcs7_signed_data_verify*(pkcs7: ptr mbedtls_pkcs7; + cert: ptr mbedtls_x509_crt; + data: ptr byte; datalen: uint): cint {. + importc, cdecl.} +proc mbedtls_pkcs7_signed_hash_verify*(pkcs7: ptr mbedtls_pkcs7; + cert: ptr mbedtls_x509_crt; + hash: ptr byte; hashlen: uint): cint {. + importc, cdecl.} +proc mbedtls_pkcs7_free*(pkcs7: ptr mbedtls_pkcs7) {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/platform.nim b/webrtc/mbedtls/platform.nim new file mode 100644 index 0000000..c28a78d --- /dev/null +++ b/webrtc/mbedtls/platform.nim @@ -0,0 +1,60 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "platform_time" +{.compile: "./mbedtls/library/platform.c".} +# Generated @ 2023-05-11T11:19:12+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/platform.h + +# const 'MBEDTLS_PLATFORM_STD_SNPRINTF' has unsupported value 'snprintf' +# const 'MBEDTLS_PLATFORM_STD_VSNPRINTF' has unsupported value 'vsnprintf' +# const 'MBEDTLS_PLATFORM_STD_PRINTF' has unsupported value 'printf' +# const 'MBEDTLS_PLATFORM_STD_FPRINTF' has unsupported value 'fprintf' +# const 'MBEDTLS_PLATFORM_STD_CALLOC' has unsupported value 'calloc' +# const 'MBEDTLS_PLATFORM_STD_FREE' has unsupported value 'free' +# const 'MBEDTLS_PLATFORM_STD_SETBUF' has unsupported value 'setbuf' +# const 'MBEDTLS_PLATFORM_STD_EXIT' has unsupported value 'exit' +# const 'MBEDTLS_PLATFORM_STD_TIME' has unsupported value 'time' +# const 'MBEDTLS_PLATFORM_STD_EXIT_SUCCESS' has unsupported value 'EXIT_SUCCESS' +# const 'MBEDTLS_PLATFORM_STD_EXIT_FAILURE' has unsupported value 'EXIT_FAILURE' +# const 'MBEDTLS_PLATFORM_STD_NV_SEED_READ' has unsupported value 'mbedtls_platform_std_nv_seed_read' +# const 'MBEDTLS_PLATFORM_STD_NV_SEED_WRITE' has unsupported value 'mbedtls_platform_std_nv_seed_write' +# const 'mbedtls_free' has unsupported value 'free' +# const 'mbedtls_calloc' has unsupported value 'calloc' +# const 'mbedtls_fprintf' has unsupported value 'fprintf' +# const 'mbedtls_printf' has unsupported value 'printf' +# const 'mbedtls_snprintf' has unsupported value 'MBEDTLS_PLATFORM_STD_SNPRINTF' +# const 'mbedtls_vsnprintf' has unsupported value 'vsnprintf' +# const 'mbedtls_setbuf' has unsupported value 'setbuf' +# const 'mbedtls_exit' has unsupported value 'exit' +# const 'MBEDTLS_EXIT_SUCCESS' has unsupported value 'MBEDTLS_PLATFORM_STD_EXIT_SUCCESS' +# const 'MBEDTLS_EXIT_FAILURE' has unsupported value 'MBEDTLS_PLATFORM_STD_EXIT_FAILURE' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_PLATFORM_STD_NV_SEED_FILE* = "seedfile" +type + mbedtls_platform_context* {.bycopy.} = object + private_dummy*: cchar + +proc mbedtls_platform_setup*(ctx: ptr mbedtls_platform_context): cint {.importc, + cdecl.} +proc mbedtls_platform_teardown*(ctx: ptr mbedtls_platform_context) {.importc, + cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/platform_time.nim b/webrtc/mbedtls/platform_time.nim new file mode 100644 index 0000000..db439b7 --- /dev/null +++ b/webrtc/mbedtls/platform_time.nim @@ -0,0 +1,34 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +# import "build_info" +# import "mbedtls_config" +# import "config_psa" +# import "check_config" +{.used.} +{.compile: "./mbedtls/library/platform_util.c".} +# Generated @ 2023-05-11T11:19:12+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/platform_time.h + +# const 'mbedtls_time' has unsupported value 'time' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + +import std/time_t as std_time_t +type time_t* = std_time_t.Time + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +type + mbedtls_time_t* = time_t + mbedtls_ms_time_t* = int64 +proc mbedtls_ms_time*(): mbedtls_ms_time_t {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/platform_util.nim b/webrtc/mbedtls/platform_util.nim new file mode 100644 index 0000000..b79f2a4 --- /dev/null +++ b/webrtc/mbedtls/platform_util.nim @@ -0,0 +1,32 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +type tm {.importc: "struct tm", header: "".} = object +# import "build_info" +# import "mbedtls_config" +# import "config_psa" +# import "check_config" +import "platform_time" +# {.compile: "./mbedtls/library/platform_util.c".} +# Generated @ 2023-05-11T11:19:12+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/platform_util.h + +# const 'MBEDTLS_CHECK_RETURN' has unsupported value '__attribute__((__warn_unused_result__))' +# const 'MBEDTLS_CHECK_RETURN_CRITICAL' has unsupported value 'MBEDTLS_CHECK_RETURN' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +proc mbedtls_platform_zeroize*(buf: pointer; len: uint) {.importc, cdecl.} +proc mbedtls_platform_gmtime_r*(tt: ptr mbedtls_time_t; tm_buf: ptr tm): ptr tm {. + importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/poly1305.nim b/webrtc/mbedtls/poly1305.nim new file mode 100644 index 0000000..98c5188 --- /dev/null +++ b/webrtc/mbedtls/poly1305.nim @@ -0,0 +1,45 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "md" +{.compile: "./mbedtls/library/poly1305.c".} +# Generated @ 2023-05-11T11:19:12+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/poly1305.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA* = -0x00000057 +type + mbedtls_poly1305_context* {.bycopy.} = object + private_r*: array[4, uint32] + private_s*: array[4, uint32] + private_acc*: array[5, uint32] + private_queue*: array[16, uint8] + private_queue_len*: uint + +proc mbedtls_poly1305_init*(ctx: ptr mbedtls_poly1305_context) {.importc, cdecl.} +proc mbedtls_poly1305_free*(ctx: ptr mbedtls_poly1305_context) {.importc, cdecl.} +proc mbedtls_poly1305_starts*(ctx: ptr mbedtls_poly1305_context; + key: array[32, byte]): cint {.importc, cdecl.} +proc mbedtls_poly1305_update*(ctx: ptr mbedtls_poly1305_context; + input: ptr byte; ilen: uint): cint {.importc, + cdecl.} +proc mbedtls_poly1305_finish*(ctx: ptr mbedtls_poly1305_context; + mac: array[16, byte]): cint {.importc, cdecl.} +proc mbedtls_poly1305_mac*(key: array[32, byte]; input: ptr byte; + ilen: uint; mac: array[16, byte]): cint {.importc, + cdecl.} +proc mbedtls_poly1305_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/private_access.nim b/webrtc/mbedtls/private_access.nim new file mode 100644 index 0000000..cfdc0e1 --- /dev/null +++ b/webrtc/mbedtls/private_access.nim @@ -0,0 +1,20 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +# Generated @ 2023-05-11T11:19:13+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/private_access.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto.nim b/webrtc/mbedtls/psa/crypto.nim new file mode 100644 index 0000000..4ab1c00 --- /dev/null +++ b/webrtc/mbedtls/psa/crypto.nim @@ -0,0 +1,651 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "crypto_types" +import "crypto_values" +import "crypto_sizes" +import "crypto_struct" +import "crypto_driver_contexts_primitives" +import "crypto_driver_common" +import "crypto_sizes" +import "crypto_builtin_primitives" +import "crypto_driver_contexts_composites" +import "crypto_builtin_composites" +import "crypto_driver_contexts_key_derivation" +import "../pk" +import "../ecp" +import "../rsa" +import "../ecdh" +import "../cmac" +import "../cipher" +import "../ctr_drbg" +{.compile: "./mbedtls/library/psa_crypto.c".} +{.compile: "./mbedtls/library/psa_crypto_hash.c".} +{.compile: "./mbedtls/library/psa_crypto_slot_management.c".} +{.compile: "./mbedtls/library/psa_crypto_storage.c".} +{.compile: "./mbedtls/library/psa_its_file.c".} +{.compile: "./mbedtls/library/psa_crypto_driver_wrappers.c".} +{.compile: "./mbedtls/library/psa_crypto_pake.c".} +{.compile: "./mbedtls/library/psa_crypto_rsa.c".} +{.compile: "./mbedtls/library/psa_crypto_mac.c".} +{.compile: "./mbedtls/library/psa_crypto_ecp.c".} +{.compile: "./mbedtls/library/psa_crypto_aead.c".} +{.compile: "./mbedtls/library/psa_crypto_cipher.c".} +# Generated @ 2023-05-12T13:12:42+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.pragma: impcryptoHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto.h".} +{.pragma: impcrypto_compatHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_compat.h".} +{.pragma: impcrypto_extraHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_extra.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(psa_jpake_step) +defineEnum(psa_jpake_state) +defineEnum(psa_jpake_sequence) +defineEnum(psa_crypto_driver_pake_step) +const + PSA_CRYPTO_API_VERSION_MAJOR* = 1 + PSA_CRYPTO_API_VERSION_MINOR* = 0 + PSA_KEY_DERIVATION_UNLIMITED_CAPACITY* = (cast[uint]((-1))) + + PSA_CRYPTO_ITS_RANDOM_SEED_UID* = 0xFFFFFF52 + MBEDTLS_PSA_KEY_SLOT_COUNT* = 32 + PSA_KEY_TYPE_DSA_PUBLIC_KEY* = (cast[psa_key_type_t](0x00004002)) + PSA_KEY_TYPE_DSA_KEY_PAIR* = (cast[psa_key_type_t](0x00007002)) + PSA_ALG_DSA_BASE* = (cast[psa_algorithm_t](0x06000400)) + PSA_ALG_DETERMINISTIC_DSA_BASE* = (cast[psa_algorithm_t](0x06000500)) + PSA_DH_FAMILY_CUSTOM* = (cast[psa_dh_family_t](0x0000007E)) + PSA_PAKE_OPERATION_STAGE_SETUP* = 0 + PSA_PAKE_OPERATION_STAGE_COLLECT_INPUTS* = 1 + PSA_PAKE_OPERATION_STAGE_COMPUTATION* = 2 + MBEDTLS_PSA_KEY_ID_BUILTIN_MIN* = (cast[psa_key_id_t](0x7FFF0000)) + MBEDTLS_PSA_KEY_ID_BUILTIN_MAX* = (cast[psa_key_id_t](0x7FFFEFFF)) + PSA_ALG_CATEGORY_PAKE* = (cast[psa_algorithm_t](0x0A000000)) + PSA_ALG_JPAKE* = (cast[psa_algorithm_t](0x0A000100)) + PSA_PAKE_ROLE_NONE* = (cast[psa_pake_role_t](0x00000000)) + PSA_PAKE_ROLE_FIRST* = (cast[psa_pake_role_t](0x00000001)) + PSA_PAKE_ROLE_SECOND* = (cast[psa_pake_role_t](0x00000002)) + PSA_PAKE_ROLE_CLIENT* = (cast[psa_pake_role_t](0x00000011)) + PSA_PAKE_ROLE_SERVER* = (cast[psa_pake_role_t](0x00000012)) + PSA_PAKE_PRIMITIVE_TYPE_ECC* = (cast[psa_pake_primitive_type_t](0x00000001)) + PSA_PAKE_PRIMITIVE_TYPE_DH* = (cast[psa_pake_primitive_type_t](0x00000002)) + PSA_PAKE_STEP_KEY_SHARE* = (cast[psa_pake_step_t](0x00000001)) + PSA_PAKE_STEP_ZK_PUBLIC* = (cast[psa_pake_step_t](0x00000002)) + PSA_PAKE_STEP_ZK_PROOF* = (cast[psa_pake_step_t](0x00000003)) + PSA_PAKE_OUTPUT_MAX_SIZE* = 65 + PSA_PAKE_INPUT_MAX_SIZE* = 65 + PSA_PAKE_STEP_INVALID* = (0).psa_jpake_step + PSA_PAKE_STEP_X1_X2* = (1).psa_jpake_step + PSA_PAKE_STEP_X2S* = (2).psa_jpake_step + PSA_PAKE_STEP_DERIVE* = (3).psa_jpake_step + PSA_PAKE_STATE_INVALID* = (0).psa_jpake_state + PSA_PAKE_STATE_SETUP* = (1).psa_jpake_state + PSA_PAKE_STATE_READY* = (2).psa_jpake_state + PSA_PAKE_OUTPUT_X1_X2* = (3).psa_jpake_state + PSA_PAKE_OUTPUT_X2S* = (4).psa_jpake_state + PSA_PAKE_INPUT_X1_X2* = (5).psa_jpake_state + PSA_PAKE_INPUT_X4S* = (6).psa_jpake_state + PSA_PAKE_SEQ_INVALID* = (0).psa_jpake_sequence + PSA_PAKE_X1_STEP_KEY_SHARE* = (1).psa_jpake_sequence + PSA_PAKE_X1_STEP_ZK_PUBLIC* = (2).psa_jpake_sequence + PSA_PAKE_X1_STEP_ZK_PROOF* = (3).psa_jpake_sequence + PSA_PAKE_X2_STEP_KEY_SHARE* = (4).psa_jpake_sequence + PSA_PAKE_X2_STEP_ZK_PUBLIC* = (5).psa_jpake_sequence + PSA_PAKE_X2_STEP_ZK_PROOF* = (6).psa_jpake_sequence + PSA_PAKE_SEQ_END* = (7).psa_jpake_sequence + PSA_JPAKE_STEP_INVALID* = (0).psa_crypto_driver_pake_step + PSA_JPAKE_X1_STEP_KEY_SHARE* = (1).psa_crypto_driver_pake_step + PSA_JPAKE_X1_STEP_ZK_PUBLIC* = (2).psa_crypto_driver_pake_step + PSA_JPAKE_X1_STEP_ZK_PROOF* = (3).psa_crypto_driver_pake_step + PSA_JPAKE_X2_STEP_KEY_SHARE* = (4).psa_crypto_driver_pake_step + PSA_JPAKE_X2_STEP_ZK_PUBLIC* = (5).psa_crypto_driver_pake_step + PSA_JPAKE_X2_STEP_ZK_PROOF* = (6).psa_crypto_driver_pake_step + PSA_JPAKE_X2S_STEP_KEY_SHARE* = (7).psa_crypto_driver_pake_step + PSA_JPAKE_X2S_STEP_ZK_PUBLIC* = (8).psa_crypto_driver_pake_step + PSA_JPAKE_X2S_STEP_ZK_PROOF* = (9).psa_crypto_driver_pake_step + PSA_JPAKE_X4S_STEP_KEY_SHARE* = (10).psa_crypto_driver_pake_step + PSA_JPAKE_X4S_STEP_ZK_PUBLIC* = (11).psa_crypto_driver_pake_step + PSA_JPAKE_X4S_STEP_ZK_PROOF* = (12).psa_crypto_driver_pake_step + +type + psa_hash_operation_t* {.importc, impcryptoHdr.} = psa_hash_operation_s + psa_mac_operation_t* {.importc, impcryptoHdr.} = psa_mac_operation_s + psa_cipher_operation_t* {.importc, impcryptoHdr.} = psa_cipher_operation_s + psa_aead_operation_t* {.importc, impcryptoHdr.} = psa_aead_operation_s + psa_key_derivation_operation_t* {.importc, impcryptoHdr.} = psa_key_derivation_s + psa_sign_hash_interruptible_operation_t* {.importc, impcryptoHdr.} = psa_sign_hash_interruptible_operation_s + psa_verify_hash_interruptible_operation_t* {.importc, impcryptoHdr.} = psa_verify_hash_interruptible_operation_s + + psa_key_handle_t* {.importc, impcrypto_compatHdr.} = mbedtls_svc_key_id_t + + mbedtls_psa_stats_s* {.bycopy, impcrypto_extraHdr, + importc: "struct mbedtls_psa_stats_s".} = object + private_volatile_slots*: uint + private_persistent_slots*: uint + private_external_slots*: uint + private_half_filled_slots*: uint + private_cache_slots*: uint + private_empty_slots*: uint + private_locked_slots*: uint + private_max_open_internal_key_id*: psa_key_id_t + private_max_open_external_key_id*: psa_key_id_t + + mbedtls_psa_stats_t* {.importc, impcrypto_extraHdr.} = mbedtls_psa_stats_s + psa_drv_slot_number_t* {.importc, impcrypto_extraHdr.} = uint64 + psa_pake_role_t* {.importc, impcrypto_extraHdr.} = uint8 + psa_pake_step_t* {.importc, impcrypto_extraHdr.} = uint8 + psa_pake_primitive_type_t* {.importc, impcrypto_extraHdr.} = uint8 + psa_pake_family_t* {.importc, impcrypto_extraHdr.} = uint8 + psa_pake_primitive_t* {.importc, impcrypto_extraHdr.} = uint32 + psa_pake_cipher_suite_t* {.importc, impcrypto_extraHdr.} = psa_pake_cipher_suite_s + psa_pake_operation_t* {.importc, impcrypto_extraHdr.} = psa_pake_operation_s + psa_crypto_driver_pake_inputs_t* {.importc, impcrypto_extraHdr.} = psa_crypto_driver_pake_inputs_s + psa_jpake_computation_stage_t* {.importc, impcrypto_extraHdr.} = psa_jpake_computation_stage_s + psa_pake_cipher_suite_s* {.bycopy, impcrypto_extraHdr, + importc: "struct psa_pake_cipher_suite_s".} = object + algorithm*: psa_algorithm_t + `type`*: psa_pake_primitive_type_t + family*: psa_pake_family_t + bits*: uint16 + hash*: psa_algorithm_t + + psa_crypto_driver_pake_inputs_s* {.bycopy, impcrypto_extraHdr, importc: "struct psa_crypto_driver_pake_inputs_s".} = object + private_password*: ptr uint8 + private_password_len*: uint + private_role*: psa_pake_role_t + private_user*: ptr uint8 + private_user_len*: uint + private_peer*: ptr uint8 + private_peer_len*: uint + private_attributes*: psa_key_attributes_t + private_cipher_suite*: psa_pake_cipher_suite_t + + psa_jpake_step_t* {.importc, impcrypto_extraHdr.} = psa_jpake_step + psa_jpake_state_t* {.importc, impcrypto_extraHdr.} = psa_jpake_state + psa_jpake_sequence_t* {.importc, impcrypto_extraHdr.} = psa_jpake_sequence + psa_crypto_driver_pake_step_t* {.importc, impcrypto_extraHdr.} = psa_crypto_driver_pake_step + psa_jpake_computation_stage_s* {.bycopy, impcrypto_extraHdr, importc: "struct psa_jpake_computation_stage_s".} = object + private_state*: psa_jpake_state_t + private_sequence*: psa_jpake_sequence_t + private_input_step*: psa_jpake_step_t + private_output_step*: psa_jpake_step_t + + Union_crypto_extrah1* {.union, bycopy, impcrypto_extraHdr, + importc: "union Union_crypto_extrah1".} = object + private_dummy*: uint8 + private_jpake*: psa_jpake_computation_stage_t + + Union_crypto_extrah2* {.union, bycopy, impcrypto_extraHdr, + importc: "union Union_crypto_extrah2".} = object + private_ctx*: psa_driver_pake_context_t + private_inputs*: psa_crypto_driver_pake_inputs_t + + psa_pake_operation_s* {.bycopy, impcrypto_extraHdr, + importc: "struct psa_pake_operation_s".} = object + private_id*: cuint + private_alg*: psa_algorithm_t + private_primitive*: psa_pake_primitive_t + private_stage*: uint8 + private_computation_stage*: Union_crypto_extrah1 + private_data*: Union_crypto_extrah2 + +proc psa_crypto_init*(): psa_status_t {.importc, cdecl, impcryptoHdr.} +proc psa_key_attributes_init*(): psa_key_attributes_t {.importc, cdecl, + impcryptoHdr.} +proc psa_set_key_id*(attributes: ptr psa_key_attributes_t; + key: mbedtls_svc_key_id_t) {.importc, cdecl, impcryptoHdr.} +proc psa_set_key_lifetime*(attributes: ptr psa_key_attributes_t; + lifetime: psa_key_lifetime_t) {.importc, cdecl, + impcryptoHdr.} +proc psa_get_key_id*(attributes: ptr psa_key_attributes_t): mbedtls_svc_key_id_t {. + importc, cdecl, impcryptoHdr.} +proc psa_get_key_lifetime*(attributes: ptr psa_key_attributes_t): psa_key_lifetime_t {. + importc, cdecl, impcryptoHdr.} +proc psa_set_key_usage_flags*(attributes: ptr psa_key_attributes_t; + usage_flags: psa_key_usage_t) {.importc, cdecl, + impcryptoHdr.} +proc psa_get_key_usage_flags*(attributes: ptr psa_key_attributes_t): psa_key_usage_t {. + importc, cdecl, impcryptoHdr.} +proc psa_set_key_algorithm*(attributes: ptr psa_key_attributes_t; + alg: psa_algorithm_t) {.importc, cdecl, impcryptoHdr.} +proc psa_get_key_algorithm*(attributes: ptr psa_key_attributes_t): psa_algorithm_t {. + importc, cdecl, impcryptoHdr.} +proc psa_set_key_type*(attributes: ptr psa_key_attributes_t; + `type`: psa_key_type_t) {.importc, cdecl, impcryptoHdr.} +proc psa_set_key_bits*(attributes: ptr psa_key_attributes_t; bits: uint) {. + importc, cdecl, impcryptoHdr.} +proc psa_get_key_type*(attributes: ptr psa_key_attributes_t): psa_key_type_t {. + importc, cdecl, impcryptoHdr.} +proc psa_get_key_bits*(attributes: ptr psa_key_attributes_t): uint {.importc, + cdecl, impcryptoHdr.} +proc psa_get_key_attributes*(key: mbedtls_svc_key_id_t; + attributes: ptr psa_key_attributes_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_reset_key_attributes*(attributes: ptr psa_key_attributes_t) {.importc, + cdecl, impcryptoHdr.} +proc psa_purge_key*(key: mbedtls_svc_key_id_t): psa_status_t {.importc, cdecl, + impcryptoHdr.} +proc psa_copy_key*(source_key: mbedtls_svc_key_id_t; + attributes: ptr psa_key_attributes_t; + target_key: ptr mbedtls_svc_key_id_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_destroy_key*(key: mbedtls_svc_key_id_t): psa_status_t {.importc, cdecl, + impcryptoHdr.} +proc psa_import_key*(attributes: ptr psa_key_attributes_t; data: ptr uint8; + data_length: uint; key: ptr mbedtls_svc_key_id_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_export_key*(key: mbedtls_svc_key_id_t; data: ptr uint8; + data_size: uint; data_length: ptr uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_export_public_key*(key: mbedtls_svc_key_id_t; data: ptr uint8; + data_size: uint; data_length: ptr uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_hash_compute*(alg: psa_algorithm_t; input: ptr uint8; + input_length: uint; hash: ptr uint8; hash_size: uint; + hash_length: ptr uint): psa_status_t {.importc, cdecl, + impcryptoHdr.} +proc psa_hash_compare*(alg: psa_algorithm_t; input: ptr uint8; + input_length: uint; hash: ptr uint8; hash_length: uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_hash_operation_init*(): psa_hash_operation_t {.importc, cdecl, + impcryptoHdr.} +proc psa_hash_setup*(operation: ptr psa_hash_operation_t; alg: psa_algorithm_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_hash_update*(operation: ptr psa_hash_operation_t; input: ptr uint8; + input_length: uint): psa_status_t {.importc, cdecl, + impcryptoHdr.} +proc psa_hash_finish*(operation: ptr psa_hash_operation_t; hash: ptr uint8; + hash_size: uint; hash_length: ptr uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_hash_verify*(operation: ptr psa_hash_operation_t; hash: ptr uint8; + hash_length: uint): psa_status_t {.importc, cdecl, + impcryptoHdr.} +proc psa_hash_abort*(operation: ptr psa_hash_operation_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_hash_clone*(source_operation: ptr psa_hash_operation_t; + target_operation: ptr psa_hash_operation_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_mac_compute*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; + input: ptr uint8; input_length: uint; mac: ptr uint8; + mac_size: uint; mac_length: ptr uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_mac_verify*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; + input: ptr uint8; input_length: uint; mac: ptr uint8; + mac_length: uint): psa_status_t {.importc, cdecl, + impcryptoHdr.} +proc psa_mac_operation_init*(): psa_mac_operation_t {.importc, cdecl, + impcryptoHdr.} +proc psa_mac_sign_setup*(operation: ptr psa_mac_operation_t; + key: mbedtls_svc_key_id_t; alg: psa_algorithm_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_mac_verify_setup*(operation: ptr psa_mac_operation_t; + key: mbedtls_svc_key_id_t; alg: psa_algorithm_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_mac_update*(operation: ptr psa_mac_operation_t; input: ptr uint8; + input_length: uint): psa_status_t {.importc, cdecl, + impcryptoHdr.} +proc psa_mac_sign_finish*(operation: ptr psa_mac_operation_t; mac: ptr uint8; + mac_size: uint; mac_length: ptr uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_mac_verify_finish*(operation: ptr psa_mac_operation_t; mac: ptr uint8; + mac_length: uint): psa_status_t {.importc, cdecl, + impcryptoHdr.} +proc psa_mac_abort*(operation: ptr psa_mac_operation_t): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_cipher_encrypt*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; + input: ptr uint8; input_length: uint; + output: ptr uint8; output_size: uint; + output_length: ptr uint): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_cipher_decrypt*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; + input: ptr uint8; input_length: uint; + output: ptr uint8; output_size: uint; + output_length: ptr uint): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_cipher_operation_init*(): psa_cipher_operation_t {.importc, cdecl, + impcryptoHdr.} +proc psa_cipher_encrypt_setup*(operation: ptr psa_cipher_operation_t; + key: mbedtls_svc_key_id_t; alg: psa_algorithm_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_cipher_decrypt_setup*(operation: ptr psa_cipher_operation_t; + key: mbedtls_svc_key_id_t; alg: psa_algorithm_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_cipher_generate_iv*(operation: ptr psa_cipher_operation_t; + iv: ptr uint8; iv_size: uint; iv_length: ptr uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_cipher_set_iv*(operation: ptr psa_cipher_operation_t; iv: ptr uint8; + iv_length: uint): psa_status_t {.importc, cdecl, + impcryptoHdr.} +proc psa_cipher_update*(operation: ptr psa_cipher_operation_t; input: ptr uint8; + input_length: uint; output: ptr uint8; + output_size: uint; output_length: ptr uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_cipher_finish*(operation: ptr psa_cipher_operation_t; + output: ptr uint8; output_size: uint; + output_length: ptr uint): psa_status_t {.importc, cdecl, + impcryptoHdr.} +proc psa_cipher_abort*(operation: ptr psa_cipher_operation_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_aead_encrypt*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; + nonce: ptr uint8; nonce_length: uint; + additional_data: ptr uint8; additional_data_length: uint; + plaintext: ptr uint8; plaintext_length: uint; + ciphertext: ptr uint8; ciphertext_size: uint; + ciphertext_length: ptr uint): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_aead_decrypt*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; + nonce: ptr uint8; nonce_length: uint; + additional_data: ptr uint8; additional_data_length: uint; + ciphertext: ptr uint8; ciphertext_length: uint; + plaintext: ptr uint8; plaintext_size: uint; + plaintext_length: ptr uint): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_aead_operation_init*(): psa_aead_operation_t {.importc, cdecl, + impcryptoHdr.} +proc psa_aead_encrypt_setup*(operation: ptr psa_aead_operation_t; + key: mbedtls_svc_key_id_t; alg: psa_algorithm_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_aead_decrypt_setup*(operation: ptr psa_aead_operation_t; + key: mbedtls_svc_key_id_t; alg: psa_algorithm_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_aead_generate_nonce*(operation: ptr psa_aead_operation_t; + nonce: ptr uint8; nonce_size: uint; + nonce_length: ptr uint): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_aead_set_nonce*(operation: ptr psa_aead_operation_t; nonce: ptr uint8; + nonce_length: uint): psa_status_t {.importc, cdecl, + impcryptoHdr.} +proc psa_aead_set_lengths*(operation: ptr psa_aead_operation_t; ad_length: uint; + plaintext_length: uint): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_aead_update_ad*(operation: ptr psa_aead_operation_t; input: ptr uint8; + input_length: uint): psa_status_t {.importc, cdecl, + impcryptoHdr.} +proc psa_aead_update*(operation: ptr psa_aead_operation_t; input: ptr uint8; + input_length: uint; output: ptr uint8; output_size: uint; + output_length: ptr uint): psa_status_t {.importc, cdecl, + impcryptoHdr.} +proc psa_aead_finish*(operation: ptr psa_aead_operation_t; + ciphertext: ptr uint8; ciphertext_size: uint; + ciphertext_length: ptr uint; tag: ptr uint8; + tag_size: uint; tag_length: ptr uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_aead_verify*(operation: ptr psa_aead_operation_t; plaintext: ptr uint8; + plaintext_size: uint; plaintext_length: ptr uint; + tag: ptr uint8; tag_length: uint): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_aead_abort*(operation: ptr psa_aead_operation_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_sign_message*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; + input: ptr uint8; input_length: uint; + signature: ptr uint8; signature_size: uint; + signature_length: ptr uint): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_verify_message*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; + input: ptr uint8; input_length: uint; + signature: ptr uint8; signature_length: uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_sign_hash*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; + hash: ptr uint8; hash_length: uint; signature: ptr uint8; + signature_size: uint; signature_length: ptr uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_verify_hash*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; + hash: ptr uint8; hash_length: uint; signature: ptr uint8; + signature_length: uint): psa_status_t {.importc, cdecl, + impcryptoHdr.} +proc psa_asymmetric_encrypt*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; + input: ptr uint8; input_length: uint; + salt: ptr uint8; salt_length: uint; + output: ptr uint8; output_size: uint; + output_length: ptr uint): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_asymmetric_decrypt*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; + input: ptr uint8; input_length: uint; + salt: ptr uint8; salt_length: uint; + output: ptr uint8; output_size: uint; + output_length: ptr uint): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_key_derivation_operation_init*(): psa_key_derivation_operation_t {. + importc, cdecl, impcryptoHdr.} +proc psa_key_derivation_setup*(operation: ptr psa_key_derivation_operation_t; + alg: psa_algorithm_t): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_key_derivation_get_capacity*(operation: ptr psa_key_derivation_operation_t; + capacity: ptr uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_key_derivation_set_capacity*(operation: ptr psa_key_derivation_operation_t; + capacity: uint): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_key_derivation_input_bytes*(operation: ptr psa_key_derivation_operation_t; + step: psa_key_derivation_step_t; + data: ptr uint8; data_length: uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_key_derivation_input_integer*(operation: ptr psa_key_derivation_operation_t; + step: psa_key_derivation_step_t; + value: uint64): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_key_derivation_input_key*(operation: ptr psa_key_derivation_operation_t; + step: psa_key_derivation_step_t; + key: mbedtls_svc_key_id_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_key_derivation_key_agreement*(operation: ptr psa_key_derivation_operation_t; + step: psa_key_derivation_step_t; + private_key: mbedtls_svc_key_id_t; + peer_key: ptr uint8; + peer_key_length: uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_key_derivation_output_bytes*(operation: ptr psa_key_derivation_operation_t; + output: ptr uint8; output_length: uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_key_derivation_output_key*(attributes: ptr psa_key_attributes_t; + operation: ptr psa_key_derivation_operation_t; key: ptr mbedtls_svc_key_id_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_key_derivation_verify_bytes*(operation: ptr psa_key_derivation_operation_t; + expected_output: ptr uint8; + output_length: uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_key_derivation_verify_key*(operation: ptr psa_key_derivation_operation_t; + expected: psa_key_id_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_key_derivation_abort*(operation: ptr psa_key_derivation_operation_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_raw_key_agreement*(alg: psa_algorithm_t; + private_key: mbedtls_svc_key_id_t; + peer_key: ptr uint8; peer_key_length: uint; + output: ptr uint8; output_size: uint; + output_length: ptr uint): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_generate_random*(output: ptr uint8; output_size: uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_generate_key*(attributes: ptr psa_key_attributes_t; + key: ptr mbedtls_svc_key_id_t): psa_status_t {.importc, + cdecl, impcryptoHdr.} +proc psa_interruptible_set_max_ops*(max_ops: uint32) {.importc, cdecl, + impcryptoHdr.} +proc psa_interruptible_get_max_ops*(): uint32 {.importc, cdecl, impcryptoHdr.} +proc psa_sign_hash_get_num_ops*(operation: ptr psa_sign_hash_interruptible_operation_t): uint32 {. + importc, cdecl, impcryptoHdr.} +proc psa_verify_hash_get_num_ops*(operation: ptr psa_verify_hash_interruptible_operation_t): uint32 {. + importc, cdecl, impcryptoHdr.} +proc psa_sign_hash_start*(operation: ptr psa_sign_hash_interruptible_operation_t; + key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; + hash: ptr uint8; hash_length: uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_sign_hash_complete*(operation: ptr psa_sign_hash_interruptible_operation_t; + signature: ptr uint8; signature_size: uint; + signature_length: ptr uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_sign_hash_abort*(operation: ptr psa_sign_hash_interruptible_operation_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_verify_hash_start*(operation: ptr psa_verify_hash_interruptible_operation_t; + key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; + hash: ptr uint8; hash_length: uint; + signature: ptr uint8; signature_length: uint): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_verify_hash_complete*(operation: ptr psa_verify_hash_interruptible_operation_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} +proc psa_verify_hash_abort*(operation: ptr psa_verify_hash_interruptible_operation_t): psa_status_t {. + importc, cdecl, impcryptoHdr.} + +proc psa_key_handle_is_null*(handle: psa_key_handle_t): cint {.importc, cdecl, + impcrypto_compatHdr.} +proc psa_open_key*(key: mbedtls_svc_key_id_t; handle: ptr psa_key_handle_t): psa_status_t {. + importc, cdecl, impcrypto_compatHdr.} +proc psa_close_key*(handle: psa_key_handle_t): psa_status_t {.importc, cdecl, + impcrypto_compatHdr.} + +proc psa_set_key_enrollment_algorithm*(attributes: ptr psa_key_attributes_t; + alg2: psa_algorithm_t) {.importc, cdecl, + impcrypto_extraHdr.} +proc psa_get_key_enrollment_algorithm*(attributes: ptr psa_key_attributes_t): psa_algorithm_t {. + importc, cdecl, impcrypto_extraHdr.} +proc mbedtls_psa_crypto_free*() {.importc, cdecl, impcrypto_extraHdr.} +proc mbedtls_psa_get_stats*(stats: ptr mbedtls_psa_stats_t) {.importc, cdecl, + impcrypto_extraHdr.} +proc mbedtls_psa_inject_entropy*(seed: ptr uint8; seed_size: uint): psa_status_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_set_key_domain_parameters*(attributes: ptr psa_key_attributes_t; + `type`: psa_key_type_t; data: ptr uint8; + data_length: uint): psa_status_t {.importc, + cdecl, impcrypto_extraHdr.} +proc psa_get_key_domain_parameters*(attributes: ptr psa_key_attributes_t; + data: ptr uint8; data_size: uint; + data_length: ptr uint): psa_status_t {. + importc, cdecl, impcrypto_extraHdr.} +proc mbedtls_ecc_group_to_psa*(grpid: mbedtls_ecp_group_id; bits: ptr uint): psa_ecc_family_t {. + importc, cdecl, impcrypto_extraHdr.} +proc mbedtls_ecc_group_of_psa*(curve: psa_ecc_family_t; bits: uint; + bits_is_sloppy: cint): mbedtls_ecp_group_id {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_pake_cipher_suite_init*(): psa_pake_cipher_suite_t {.importc, cdecl, + impcrypto_extraHdr.} +proc psa_pake_cs_get_algorithm*(cipher_suite: ptr psa_pake_cipher_suite_t): psa_algorithm_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_pake_cs_set_algorithm*(cipher_suite: ptr psa_pake_cipher_suite_t; + algorithm: psa_algorithm_t) {.importc, cdecl, + impcrypto_extraHdr.} +proc psa_pake_cs_get_primitive*(cipher_suite: ptr psa_pake_cipher_suite_t): psa_pake_primitive_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_pake_cs_set_primitive*(cipher_suite: ptr psa_pake_cipher_suite_t; + primitive: psa_pake_primitive_t) {.importc, + cdecl, impcrypto_extraHdr.} +proc psa_pake_cs_get_family*(cipher_suite: ptr psa_pake_cipher_suite_t): psa_pake_family_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_pake_cs_get_bits*(cipher_suite: ptr psa_pake_cipher_suite_t): uint16 {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_pake_cs_get_hash*(cipher_suite: ptr psa_pake_cipher_suite_t): psa_algorithm_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_pake_cs_set_hash*(cipher_suite: ptr psa_pake_cipher_suite_t; + hash: psa_algorithm_t) {.importc, cdecl, + impcrypto_extraHdr.} +proc psa_pake_operation_init*(): psa_pake_operation_t {.importc, cdecl, + impcrypto_extraHdr.} +proc psa_crypto_driver_pake_get_password_len*( + inputs: ptr psa_crypto_driver_pake_inputs_t; password_len: ptr uint): psa_status_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_crypto_driver_pake_get_password*( + inputs: ptr psa_crypto_driver_pake_inputs_t; buffer: ptr uint8; + buffer_size: uint; buffer_length: ptr uint): psa_status_t {.importc, cdecl, + impcrypto_extraHdr.} +proc psa_crypto_driver_pake_get_role*(inputs: ptr psa_crypto_driver_pake_inputs_t; + role: ptr psa_pake_role_t): psa_status_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_crypto_driver_pake_get_user_len*( + inputs: ptr psa_crypto_driver_pake_inputs_t; user_len: ptr uint): psa_status_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_crypto_driver_pake_get_peer_len*( + inputs: ptr psa_crypto_driver_pake_inputs_t; peer_len: ptr uint): psa_status_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_crypto_driver_pake_get_user*(inputs: ptr psa_crypto_driver_pake_inputs_t; + user_id: ptr uint8; user_id_size: uint; + user_id_len: ptr uint): psa_status_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_crypto_driver_pake_get_peer*(inputs: ptr psa_crypto_driver_pake_inputs_t; + peer_id: ptr uint8; peer_id_size: uint; + peer_id_length: ptr uint): psa_status_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_crypto_driver_pake_get_cipher_suite*( + inputs: ptr psa_crypto_driver_pake_inputs_t; + cipher_suite: ptr psa_pake_cipher_suite_t): psa_status_t {.importc, cdecl, + impcrypto_extraHdr.} +proc psa_pake_setup*(operation: ptr psa_pake_operation_t; + cipher_suite: ptr psa_pake_cipher_suite_t): psa_status_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_pake_set_password_key*(operation: ptr psa_pake_operation_t; + password: mbedtls_svc_key_id_t): psa_status_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_pake_set_user*(operation: ptr psa_pake_operation_t; user_id: ptr uint8; + user_id_len: uint): psa_status_t {.importc, cdecl, + impcrypto_extraHdr.} +proc psa_pake_set_peer*(operation: ptr psa_pake_operation_t; peer_id: ptr uint8; + peer_id_len: uint): psa_status_t {.importc, cdecl, + impcrypto_extraHdr.} +proc psa_pake_set_role*(operation: ptr psa_pake_operation_t; + role: psa_pake_role_t): psa_status_t {.importc, cdecl, + impcrypto_extraHdr.} +proc psa_pake_output*(operation: ptr psa_pake_operation_t; + step: psa_pake_step_t; output: ptr uint8; + output_size: uint; output_length: ptr uint): psa_status_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_pake_input*(operation: ptr psa_pake_operation_t; step: psa_pake_step_t; + input: ptr uint8; input_length: uint): psa_status_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_pake_get_implicit_key*(operation: ptr psa_pake_operation_t; + output: ptr psa_key_derivation_operation_t): psa_status_t {. + importc, cdecl, impcrypto_extraHdr.} +proc psa_pake_abort*(operation: ptr psa_pake_operation_t): psa_status_t {. + importc, cdecl, impcrypto_extraHdr.} +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_builtin_composites.nim b/webrtc/mbedtls/psa/crypto_builtin_composites.nim new file mode 100644 index 0000000..47551bf --- /dev/null +++ b/webrtc/mbedtls/psa/crypto_builtin_composites.nim @@ -0,0 +1,34 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +# Generated @ 2023-05-12T13:12:43+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_builtin_composites.h + +# const 'MBEDTLS_PSA_HMAC_OPERATION_INIT' has unsupported value '{ 0, PSA_HASH_OPERATION_INIT, { 0 } }' +# const 'MBEDTLS_PSA_MAC_OPERATION_INIT' has unsupported value '{ 0, { 0 } }' +# const 'MBEDTLS_PSA_AEAD_OPERATION_INIT' has unsupported value '{ 0, 0, 0, 0, { 0 } }' +# const 'MBEDTLS_PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT' has unsupported value '{ 0 }' +# const 'MBEDTLS_VERIFY_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT' has unsupported value '{ 0 }' +# const 'MBEDTLS_PSA_PAKE_OPERATION_INIT' has unsupported value '{ { 0 } }' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.pragma: impcrypto_builtin_compositesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_builtin_composites.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_PSA_BUILTIN_AEAD* = 1 + MBEDTLS_PSA_BUILTIN_PAKE* = 1 + MBEDTLS_PSA_JPAKE_BUFFER_SIZE* = ((3 + typeof(3)(1) + typeof(3)(65) + + typeof(3)(1) + + typeof(3)(65) + + typeof(3)(1) + + typeof(3)(32)) * + typeof(3)(2)) +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_builtin_primitives.nim b/webrtc/mbedtls/psa/crypto_builtin_primitives.nim new file mode 100644 index 0000000..415add7 --- /dev/null +++ b/webrtc/mbedtls/psa/crypto_builtin_primitives.nim @@ -0,0 +1,28 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "crypto_driver_common" +import "crypto_types" +import "crypto_platform" +import "crypto_values" +import "crypto_sizes" +# Generated @ 2023-05-12T13:12:43+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_builtin_primitives.h + +# const 'MBEDTLS_PSA_HASH_OPERATION_INIT' has unsupported value '{ 0, { 0 } }' +# const 'MBEDTLS_PSA_CIPHER_OPERATION_INIT' has unsupported value '{ 0, 0, 0, { 0 } }' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.pragma: impcrypto_builtin_primitivesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_builtin_primitives.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_PSA_BUILTIN_CIPHER* = 1 +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_compat.nim b/webrtc/mbedtls/psa/crypto_compat.nim new file mode 100644 index 0000000..7bbb30c --- /dev/null +++ b/webrtc/mbedtls/psa/crypto_compat.nim @@ -0,0 +1,20 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +# Generated @ 2023-05-12T13:12:43+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_compat.h + +# const 'PSA_KEY_HANDLE_INIT' has unsupported value 'MBEDTLS_SVC_KEY_ID_INIT' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.pragma: impcrypto_compatHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_compat.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_config.nim b/webrtc/mbedtls/psa/crypto_config.nim new file mode 100644 index 0000000..f17e15d --- /dev/null +++ b/webrtc/mbedtls/psa/crypto_config.nim @@ -0,0 +1,83 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +# Generated @ 2023-05-12T13:12:43+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_config.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.pragma: impcrypto_configHdr, + header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_config.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + PSA_WANT_ALG_CBC_NO_PADDING* = 1 + PSA_WANT_ALG_CBC_PKCS7* = 1 + PSA_WANT_ALG_CCM* = 1 + PSA_WANT_ALG_CCM_STAR_NO_TAG* = 1 + PSA_WANT_ALG_CMAC* = 1 + PSA_WANT_ALG_CFB* = 1 + PSA_WANT_ALG_CHACHA20_POLY1305* = 1 + PSA_WANT_ALG_CTR* = 1 + PSA_WANT_ALG_DETERMINISTIC_ECDSA* = 1 + PSA_WANT_ALG_ECB_NO_PADDING* = 1 + PSA_WANT_ALG_ECDH* = 1 + PSA_WANT_ALG_ECDSA* = 1 + PSA_WANT_ALG_JPAKE* = 1 + PSA_WANT_ALG_GCM* = 1 + PSA_WANT_ALG_HKDF* = 1 + PSA_WANT_ALG_HKDF_EXTRACT* = 1 + PSA_WANT_ALG_HKDF_EXPAND* = 1 + PSA_WANT_ALG_HMAC* = 1 + PSA_WANT_ALG_MD5* = 1 + PSA_WANT_ALG_OFB* = 1 + PSA_WANT_ALG_RIPEMD160* = 1 + PSA_WANT_ALG_RSA_OAEP* = 1 + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT* = 1 + PSA_WANT_ALG_RSA_PKCS1V15_SIGN* = 1 + PSA_WANT_ALG_RSA_PSS* = 1 + PSA_WANT_ALG_SHA_1* = 1 + PSA_WANT_ALG_SHA_224* = 1 + PSA_WANT_ALG_SHA_256* = 1 + PSA_WANT_ALG_SHA_384* = 1 + PSA_WANT_ALG_SHA_512* = 1 + PSA_WANT_ALG_STREAM_CIPHER* = 1 + PSA_WANT_ALG_TLS12_PRF* = 1 + PSA_WANT_ALG_TLS12_PSK_TO_MS* = 1 + PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS* = 1 + PSA_WANT_ECC_BRAINPOOL_P_R1_256* = 1 + PSA_WANT_ECC_BRAINPOOL_P_R1_384* = 1 + PSA_WANT_ECC_BRAINPOOL_P_R1_512* = 1 + PSA_WANT_ECC_MONTGOMERY_255* = 1 + PSA_WANT_ECC_MONTGOMERY_448* = 1 + PSA_WANT_ECC_SECP_K1_192* = 1 + PSA_WANT_ECC_SECP_K1_256* = 1 + PSA_WANT_ECC_SECP_R1_192* = 1 + PSA_WANT_ECC_SECP_R1_224* = 1 + PSA_WANT_ECC_SECP_R1_256* = 1 + PSA_WANT_ECC_SECP_R1_384* = 1 + PSA_WANT_ECC_SECP_R1_521* = 1 + PSA_WANT_KEY_TYPE_DERIVE* = 1 + PSA_WANT_KEY_TYPE_PASSWORD* = 1 + PSA_WANT_KEY_TYPE_PASSWORD_HASH* = 1 + PSA_WANT_KEY_TYPE_HMAC* = 1 + PSA_WANT_KEY_TYPE_AES* = 1 + PSA_WANT_KEY_TYPE_ARIA* = 1 + PSA_WANT_KEY_TYPE_CAMELLIA* = 1 + PSA_WANT_KEY_TYPE_CHACHA20* = 1 + PSA_WANT_KEY_TYPE_DES* = 1 + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR* = 1 + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY* = 1 + PSA_WANT_KEY_TYPE_RAW_DATA* = 1 + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR* = 1 + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY* = 1 +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_driver_common.nim b/webrtc/mbedtls/psa/crypto_driver_common.nim new file mode 100644 index 0000000..67653f4 --- /dev/null +++ b/webrtc/mbedtls/psa/crypto_driver_common.nim @@ -0,0 +1,71 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "crypto_types" +import "crypto_platform" +import "crypto_values" +import "crypto_sizes" +# Generated @ 2023-05-12T13:12:43+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_driver_common.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.pragma: impcrypto_driver_commonHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_driver_common.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(psa_encrypt_or_decrypt_t) +const + PSA_CRYPTO_DRIVER_DECRYPT* = (0).psa_encrypt_or_decrypt_t + PSA_CRYPTO_DRIVER_ENCRYPT* = (PSA_CRYPTO_DRIVER_DECRYPT + 1).psa_encrypt_or_decrypt_t +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_driver_contexts_composites.nim b/webrtc/mbedtls/psa/crypto_driver_contexts_composites.nim new file mode 100644 index 0000000..c4d3a20 --- /dev/null +++ b/webrtc/mbedtls/psa/crypto_driver_contexts_composites.nim @@ -0,0 +1,27 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "crypto_driver_common" +import "crypto_types" +import "crypto_platform" +import "crypto_values" +import "crypto_sizes" +import "crypto_builtin_composites" +# Generated @ 2023-05-12T13:12:43+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_driver_contexts_composites.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.pragma: impcrypto_driver_contexts_compositesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_driver_contexts_composites.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_driver_contexts_key_derivation.nim b/webrtc/mbedtls/psa/crypto_driver_contexts_key_derivation.nim new file mode 100644 index 0000000..3e99495 --- /dev/null +++ b/webrtc/mbedtls/psa/crypto_driver_contexts_key_derivation.nim @@ -0,0 +1,26 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "crypto_driver_common" +import "crypto_types" +import "crypto_platform" +import "crypto_values" +import "crypto_sizes" +# Generated @ 2023-05-12T13:12:43+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_driver_contexts_key_derivation.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.pragma: impcrypto_driver_contexts_key_derivationHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_driver_contexts_key_derivation.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_driver_contexts_primitives.nim b/webrtc/mbedtls/psa/crypto_driver_contexts_primitives.nim new file mode 100644 index 0000000..c015dcd --- /dev/null +++ b/webrtc/mbedtls/psa/crypto_driver_contexts_primitives.nim @@ -0,0 +1,27 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "crypto_driver_common" +import "crypto_types" +import "crypto_platform" +import "crypto_values" +import "crypto_sizes" +import "crypto_builtin_primitives" +# Generated @ 2023-05-12T13:12:43+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_driver_contexts_primitives.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.pragma: impcrypto_driver_contexts_primitivesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_driver_contexts_primitives.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_extra.nim b/webrtc/mbedtls/psa/crypto_extra.nim new file mode 100644 index 0000000..9168adb --- /dev/null +++ b/webrtc/mbedtls/psa/crypto_extra.nim @@ -0,0 +1,23 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +# Generated @ 2023-05-12T13:12:43+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_extra.h + +# const 'PSA_ALG_DSA_DETERMINISTIC_FLAG' has unsupported value 'PSA_ALG_ECDSA_DETERMINISTIC_FLAG' +# const 'PSA_PAKE_CIPHER_SUITE_INIT' has unsupported value '{ PSA_ALG_NONE, 0, 0, 0, PSA_ALG_NONE }' +# const 'PSA_PAKE_OPERATION_INIT' has unsupported value '{ 0, PSA_ALG_NONE, 0, PSA_PAKE_OPERATION_STAGE_SETUP, { 0 }, { { 0 } } }' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.pragma: impcrypto_extraHdr, + header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_extra.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_platform.nim b/webrtc/mbedtls/psa/crypto_platform.nim new file mode 100644 index 0000000..b73f92d --- /dev/null +++ b/webrtc/mbedtls/psa/crypto_platform.nim @@ -0,0 +1,22 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +# Generated @ 2023-05-12T13:12:43+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_platform.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.pragma: impcrypto_platformHdr, + header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_platform.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_se_driver.nim b/webrtc/mbedtls/psa/crypto_se_driver.nim new file mode 100644 index 0000000..d480aaa --- /dev/null +++ b/webrtc/mbedtls/psa/crypto_se_driver.nim @@ -0,0 +1,260 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "crypto_driver_common" +import "crypto_types" +import "crypto_platform" +import "crypto_values" +import "crypto_sizes" +{.compile: "./mbedtls/library/psa_crypto_se.c".} +# Generated @ 2023-05-12T13:12:44+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_se_driver.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.pragma: impcrypto_se_driverHdr, + header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_se_driver.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(psa_key_creation_method_t) +const + PSA_KEY_CREATION_IMPORT* = (0).psa_key_creation_method_t + PSA_KEY_CREATION_GENERATE* = (PSA_KEY_CREATION_IMPORT + 1).psa_key_creation_method_t + PSA_KEY_CREATION_DERIVE* = (PSA_KEY_CREATION_GENERATE + 1).psa_key_creation_method_t + PSA_KEY_CREATION_COPY* = (PSA_KEY_CREATION_DERIVE + 1).psa_key_creation_method_t + PSA_KEY_CREATION_REGISTER* = (PSA_KEY_CREATION_COPY + 1).psa_key_creation_method_t + PSA_DRV_SE_HAL_VERSION* = 0x00000005 +type + psa_drv_se_context_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object + private_persistent_data*: pointer + private_persistent_data_size*: uint + private_transient_data*: ptr uint + + psa_drv_se_init_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; persistent_data: pointer; + location: psa_key_location_t): psa_status_t {.cdecl.} + psa_key_slot_number_t* {.importc, impcrypto_se_driverHdr.} = uint64 + psa_drv_se_mac_setup_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; op_context: pointer; + key_slot: psa_key_slot_number_t; algorithm: psa_algorithm_t): psa_status_t {. + cdecl.} + psa_drv_se_mac_update_t* {.importc, impcrypto_se_driverHdr.} = proc ( + op_context: pointer; p_input: ptr uint8; input_length: uint): psa_status_t {. + cdecl.} + psa_drv_se_mac_finish_t* {.importc, impcrypto_se_driverHdr.} = proc ( + op_context: pointer; p_mac: ptr uint8; mac_size: uint; + p_mac_length: ptr uint): psa_status_t {.cdecl.} + psa_drv_se_mac_finish_verify_t* {.importc, impcrypto_se_driverHdr.} = proc ( + op_context: pointer; p_mac: ptr uint8; mac_length: uint): psa_status_t {. + cdecl.} + psa_drv_se_mac_abort_t* {.importc, impcrypto_se_driverHdr.} = proc ( + op_context: pointer): psa_status_t {.cdecl.} + psa_drv_se_mac_generate_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; p_input: ptr uint8; + input_length: uint; key_slot: psa_key_slot_number_t; alg: psa_algorithm_t; + p_mac: ptr uint8; mac_size: uint; p_mac_length: ptr uint): psa_status_t {. + cdecl.} + psa_drv_se_mac_verify_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; p_input: ptr uint8; + input_length: uint; key_slot: psa_key_slot_number_t; alg: psa_algorithm_t; + p_mac: ptr uint8; mac_length: uint): psa_status_t {.cdecl.} + psa_drv_se_mac_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object + private_context_size*: uint + private_p_setup*: psa_drv_se_mac_setup_t + private_p_update*: psa_drv_se_mac_update_t + private_p_finish*: psa_drv_se_mac_finish_t + private_p_finish_verify*: psa_drv_se_mac_finish_verify_t + private_p_abort*: psa_drv_se_mac_abort_t + private_p_mac*: psa_drv_se_mac_generate_t + private_p_mac_verify*: psa_drv_se_mac_verify_t + + psa_drv_se_cipher_setup_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; op_context: pointer; + key_slot: psa_key_slot_number_t; algorithm: psa_algorithm_t; + direction: psa_encrypt_or_decrypt_t): psa_status_t {.cdecl.} + psa_drv_se_cipher_set_iv_t* {.importc, impcrypto_se_driverHdr.} = proc ( + op_context: pointer; p_iv: ptr uint8; iv_length: uint): psa_status_t {. + cdecl.} + psa_drv_se_cipher_update_t* {.importc, impcrypto_se_driverHdr.} = proc ( + op_context: pointer; p_input: ptr uint8; input_size: uint; + p_output: ptr uint8; output_size: uint; p_output_length: ptr uint): psa_status_t {. + cdecl.} + psa_drv_se_cipher_finish_t* {.importc, impcrypto_se_driverHdr.} = proc ( + op_context: pointer; p_output: ptr uint8; output_size: uint; + p_output_length: ptr uint): psa_status_t {.cdecl.} + psa_drv_se_cipher_abort_t* {.importc, impcrypto_se_driverHdr.} = proc ( + op_context: pointer): psa_status_t {.cdecl.} + psa_drv_se_cipher_ecb_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; + algorithm: psa_algorithm_t; direction: psa_encrypt_or_decrypt_t; + p_input: ptr uint8; input_size: uint; p_output: ptr uint8; + output_size: uint): psa_status_t {.cdecl.} + psa_drv_se_cipher_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object + private_context_size*: uint + private_p_setup*: psa_drv_se_cipher_setup_t + private_p_set_iv*: psa_drv_se_cipher_set_iv_t + private_p_update*: psa_drv_se_cipher_update_t + private_p_finish*: psa_drv_se_cipher_finish_t + private_p_abort*: psa_drv_se_cipher_abort_t + private_p_ecb*: psa_drv_se_cipher_ecb_t + + psa_drv_se_asymmetric_sign_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; + alg: psa_algorithm_t; p_hash: ptr uint8; hash_length: uint; + p_signature: ptr uint8; signature_size: uint; p_signature_length: ptr uint): psa_status_t {. + cdecl.} + psa_drv_se_asymmetric_verify_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; + alg: psa_algorithm_t; p_hash: ptr uint8; hash_length: uint; + p_signature: ptr uint8; signature_length: uint): psa_status_t {.cdecl.} + psa_drv_se_asymmetric_encrypt_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; + alg: psa_algorithm_t; p_input: ptr uint8; input_length: uint; + p_salt: ptr uint8; salt_length: uint; p_output: ptr uint8; + output_size: uint; p_output_length: ptr uint): psa_status_t {.cdecl.} + psa_drv_se_asymmetric_decrypt_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; + alg: psa_algorithm_t; p_input: ptr uint8; input_length: uint; + p_salt: ptr uint8; salt_length: uint; p_output: ptr uint8; + output_size: uint; p_output_length: ptr uint): psa_status_t {.cdecl.} + psa_drv_se_asymmetric_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object + private_p_sign*: psa_drv_se_asymmetric_sign_t + private_p_verify*: psa_drv_se_asymmetric_verify_t + private_p_encrypt*: psa_drv_se_asymmetric_encrypt_t + private_p_decrypt*: psa_drv_se_asymmetric_decrypt_t + + psa_drv_se_aead_encrypt_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; + algorithm: psa_algorithm_t; p_nonce: ptr uint8; nonce_length: uint; + p_additional_data: ptr uint8; additional_data_length: uint; + p_plaintext: ptr uint8; plaintext_length: uint; p_ciphertext: ptr uint8; + ciphertext_size: uint; p_ciphertext_length: ptr uint): psa_status_t {. + cdecl.} + psa_drv_se_aead_decrypt_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; + algorithm: psa_algorithm_t; p_nonce: ptr uint8; nonce_length: uint; + p_additional_data: ptr uint8; additional_data_length: uint; + p_ciphertext: ptr uint8; ciphertext_length: uint; p_plaintext: ptr uint8; + plaintext_size: uint; p_plaintext_length: ptr uint): psa_status_t {.cdecl.} + psa_drv_se_aead_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object + private_p_encrypt*: psa_drv_se_aead_encrypt_t + private_p_decrypt*: psa_drv_se_aead_decrypt_t + + psa_drv_se_allocate_key_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; persistent_data: pointer; + attributes: ptr psa_key_attributes_t; `method`: psa_key_creation_method_t; + key_slot: ptr psa_key_slot_number_t): psa_status_t {.cdecl.} + psa_drv_se_validate_slot_number_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; persistent_data: pointer; + attributes: ptr psa_key_attributes_t; `method`: psa_key_creation_method_t; + key_slot: psa_key_slot_number_t): psa_status_t {.cdecl.} + psa_drv_se_import_key_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; + attributes: ptr psa_key_attributes_t; data: ptr uint8; data_length: uint; + bits: ptr uint): psa_status_t {.cdecl.} + psa_drv_se_destroy_key_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; persistent_data: pointer; + key_slot: psa_key_slot_number_t): psa_status_t {.cdecl.} + psa_drv_se_export_key_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; key: psa_key_slot_number_t; + p_data: ptr uint8; data_size: uint; p_data_length: ptr uint): psa_status_t {. + cdecl.} + psa_drv_se_generate_key_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; + attributes: ptr psa_key_attributes_t; pubkey: ptr uint8; + pubkey_size: uint; pubkey_length: ptr uint): psa_status_t {.cdecl.} + psa_drv_se_key_management_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object + private_p_allocate*: psa_drv_se_allocate_key_t + private_p_validate_slot_number*: psa_drv_se_validate_slot_number_t + private_p_import*: psa_drv_se_import_key_t + private_p_generate*: psa_drv_se_generate_key_t + private_p_destroy*: psa_drv_se_destroy_key_t + private_p_export*: psa_drv_se_export_key_t + private_p_export_public*: psa_drv_se_export_key_t + + psa_drv_se_key_derivation_setup_t* {.importc, impcrypto_se_driverHdr.} = proc ( + drv_context: ptr psa_drv_se_context_t; op_context: pointer; + kdf_alg: psa_algorithm_t; source_key: psa_key_slot_number_t): psa_status_t {. + cdecl.} + psa_drv_se_key_derivation_collateral_t* {.importc, impcrypto_se_driverHdr.} = proc ( + op_context: pointer; collateral_id: uint32; p_collateral: ptr uint8; + collateral_size: uint): psa_status_t {.cdecl.} + psa_drv_se_key_derivation_derive_t* {.importc, impcrypto_se_driverHdr.} = proc ( + op_context: pointer; dest_key: psa_key_slot_number_t): psa_status_t {. + cdecl.} + psa_drv_se_key_derivation_export_t* {.importc, impcrypto_se_driverHdr.} = proc ( + op_context: pointer; p_output: ptr uint8; output_size: uint; + p_output_length: ptr uint): psa_status_t {.cdecl.} + psa_drv_se_key_derivation_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object + private_context_size*: uint + private_p_setup*: psa_drv_se_key_derivation_setup_t + private_p_collateral*: psa_drv_se_key_derivation_collateral_t + private_p_derive*: psa_drv_se_key_derivation_derive_t + private_p_export*: psa_drv_se_key_derivation_export_t + + psa_drv_se_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object + private_hal_version*: uint32 + private_persistent_data_size*: uint + private_p_init*: psa_drv_se_init_t + private_key_management*: ptr psa_drv_se_key_management_t + private_mac*: ptr psa_drv_se_mac_t + private_cipher*: ptr psa_drv_se_cipher_t + private_aead*: ptr psa_drv_se_aead_t + private_asymmetric*: ptr psa_drv_se_asymmetric_t + private_derivation*: ptr psa_drv_se_key_derivation_t + +proc psa_register_se_driver*(location: psa_key_location_t; + methods: ptr psa_drv_se_t): psa_status_t {.importc, + cdecl, impcrypto_se_driverHdr.} +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_sizes.nim b/webrtc/mbedtls/psa/crypto_sizes.nim new file mode 100644 index 0000000..f039f20 --- /dev/null +++ b/webrtc/mbedtls/psa/crypto_sizes.nim @@ -0,0 +1,45 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +# Generated @ 2023-05-12T13:12:44+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_sizes.h + +# const 'PSA_MAC_MAX_SIZE' has unsupported value 'PSA_HASH_MAX_SIZE' +# const 'PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE' has unsupported value 'PSA_ECDSA_SIGNATURE_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)' +# const 'PSA_SIGNATURE_MAX_SIZE' has unsupported value '(PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS) > PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE ? PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS) : PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE)' +# const 'PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE' has unsupported value '(PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS))' +# const 'PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE' has unsupported value '(PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS))' +# const 'PSA_EXPORT_KEY_PAIR_MAX_SIZE' has unsupported value '(PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) > PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS) ? PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) : PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS))' +# const 'PSA_EXPORT_PUBLIC_KEY_MAX_SIZE' has unsupported value '(PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) > PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS) ? PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) : PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS))' +# const 'PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE' has unsupported value '(PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS))' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.pragma: impcrypto_sizesHdr, + header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_sizes.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + PSA_HASH_MAX_SIZE* = 64 + PSA_HMAC_MAX_HASH_BLOCK_SIZE* = 128 + PSA_AEAD_TAG_MAX_SIZE* = 16 + PSA_VENDOR_RSA_MAX_KEY_BITS* = 4096 + PSA_VENDOR_ECC_MAX_CURVE_BITS* = 521 + PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE* = 128 + PSA_TLS12_ECJPAKE_TO_PMS_INPUT_SIZE* = 65 + PSA_TLS12_ECJPAKE_TO_PMS_DATA_SIZE* = 32 + PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE* = 16 + PSA_AEAD_NONCE_MAX_SIZE* = 13 + PSA_AEAD_FINISH_OUTPUT_MAX_SIZE* = (PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE) + PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE* = (PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE) + PSA_CIPHER_IV_MAX_SIZE* = 16 + PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE* = (PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE) +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_struct.nim b/webrtc/mbedtls/psa/crypto_struct.nim new file mode 100644 index 0000000..f46b1e9 --- /dev/null +++ b/webrtc/mbedtls/psa/crypto_struct.nim @@ -0,0 +1,105 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "crypto_driver_contexts_primitives" +import "crypto_driver_common" +import "crypto_types" +import "crypto_platform" +import "crypto_values" +import "crypto_sizes" +import "crypto_builtin_primitives" +import "crypto_driver_contexts_composites" +import "crypto_builtin_composites" +import "crypto_driver_contexts_key_derivation" +{.compile: "./mbedtls/library/psa_crypto_client.c".} +# Generated @ 2023-05-12T13:12:44+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_struct.h + +# const 'PSA_HASH_OPERATION_INIT' has unsupported value '{ 0, { 0 } }' +# const 'PSA_CIPHER_OPERATION_INIT' has unsupported value '{ 0, 0, 0, 0, { 0 } }' +# const 'PSA_MAC_OPERATION_INIT' has unsupported value '{ 0, 0, 0, { 0 } }' +# const 'PSA_AEAD_OPERATION_INIT' has unsupported value '{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { 0 } }' +# const 'PSA_KEY_DERIVATION_OPERATION_INIT' has unsupported value '{ 0, 0, 0, { 0 } }' +# const 'PSA_KEY_POLICY_INIT' has unsupported value '{ 0, 0, 0 }' +# const 'PSA_KEY_BITS_TOO_LARGE' has unsupported value '((psa_key_bits_t) -1)' +# const 'PSA_CORE_KEY_ATTRIBUTES_INIT' has unsupported value '{ PSA_KEY_TYPE_NONE, 0, PSA_KEY_LIFETIME_VOLATILE, MBEDTLS_SVC_KEY_ID_INIT, PSA_KEY_POLICY_INIT, 0 }' +# const 'PSA_KEY_ATTRIBUTES_INIT' has unsupported value '{ PSA_CORE_KEY_ATTRIBUTES_INIT, NULL, 0 }' +# const 'PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT' has unsupported value '{ 0, { 0 }, 0, 0 }' +# const 'PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT' has unsupported value '{ 0, { 0 }, 0, 0 }' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.pragma: impcrypto_structHdr, + header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_struct.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + PSA_MAX_KEY_BITS* = 0x0000FFF8 + MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER* = ( + cast[psa_key_attributes_flag_t](0x00000001)) + MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY* = (MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER or + typeof(MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER)(0)) + MBEDTLS_PSA_KA_MASK_DUAL_USE* = (0) + +proc psa_hash_operation_init*(): psa_hash_operation_s {.importc, cdecl, + impcrypto_structHdr.} +proc psa_cipher_operation_init*(): psa_cipher_operation_s {.importc, cdecl, + impcrypto_structHdr.} +proc psa_mac_operation_init*(): psa_mac_operation_s {.importc, cdecl, + impcrypto_structHdr.} +proc psa_aead_operation_init*(): psa_aead_operation_s {.importc, cdecl, + impcrypto_structHdr.} +proc psa_key_derivation_operation_init*(): psa_key_derivation_s {.importc, + cdecl, impcrypto_structHdr.} +proc psa_key_policy_init*(): psa_key_policy_s {.importc, cdecl, + impcrypto_structHdr.} +proc psa_key_attributes_init*(): psa_key_attributes_s {.importc, cdecl, + impcrypto_structHdr.} +proc psa_set_key_id*(attributes: ptr psa_key_attributes_t; + key: mbedtls_svc_key_id_t) {.importc, cdecl, + impcrypto_structHdr.} +proc psa_get_key_id*(attributes: ptr psa_key_attributes_t): mbedtls_svc_key_id_t {. + importc, cdecl, impcrypto_structHdr.} +proc psa_set_key_lifetime*(attributes: ptr psa_key_attributes_t; + lifetime: psa_key_lifetime_t) {.importc, cdecl, + impcrypto_structHdr.} +proc psa_get_key_lifetime*(attributes: ptr psa_key_attributes_t): psa_key_lifetime_t {. + importc, cdecl, impcrypto_structHdr.} +proc psa_extend_key_usage_flags*(usage_flags: ptr psa_key_usage_t) {.importc, + cdecl, impcrypto_structHdr.} +proc psa_set_key_usage_flags*(attributes: ptr psa_key_attributes_t; + usage_flags: psa_key_usage_t) {.importc, cdecl, + impcrypto_structHdr.} +proc psa_get_key_usage_flags*(attributes: ptr psa_key_attributes_t): psa_key_usage_t {. + importc, cdecl, impcrypto_structHdr.} +proc psa_set_key_algorithm*(attributes: ptr psa_key_attributes_t; + alg: psa_algorithm_t) {.importc, cdecl, + impcrypto_structHdr.} +proc psa_get_key_algorithm*(attributes: ptr psa_key_attributes_t): psa_algorithm_t {. + importc, cdecl, impcrypto_structHdr.} +proc psa_set_key_domain_parameters*(attributes: ptr psa_key_attributes_t; + `type`: psa_key_type_t; data: ptr uint8; + data_length: uint): psa_status_t {.importc, + cdecl, impcrypto_structHdr.} +proc psa_set_key_type*(attributes: ptr psa_key_attributes_t; + `type`: psa_key_type_t) {.importc, cdecl, + impcrypto_structHdr.} +proc psa_get_key_type*(attributes: ptr psa_key_attributes_t): psa_key_type_t {. + importc, cdecl, impcrypto_structHdr.} +proc psa_set_key_bits*(attributes: ptr psa_key_attributes_t; bits: uint) {. + importc, cdecl, impcrypto_structHdr.} +proc psa_get_key_bits*(attributes: ptr psa_key_attributes_t): uint {.importc, + cdecl, impcrypto_structHdr.} +proc psa_sign_hash_interruptible_operation_init*(): psa_sign_hash_interruptible_operation_s {. + importc, cdecl, impcrypto_structHdr.} +proc psa_verify_hash_interruptible_operation_init*(): psa_verify_hash_interruptible_operation_s {. + importc, cdecl, impcrypto_structHdr.} +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_types.nim b/webrtc/mbedtls/psa/crypto_types.nim new file mode 100644 index 0000000..7fdc6ab --- /dev/null +++ b/webrtc/mbedtls/psa/crypto_types.nim @@ -0,0 +1,347 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "crypto_platform" +import "../md5" +import "../ripemd160" +import "../sha1" +import "../sha256" +import "../sha512" +import "../cipher" +import "../ccm" +import "../gcm" +import "../chachapoly" +import "../ecjpake" +# Generated @ 2023-05-12T13:12:44+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_types.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.pragma: impcrypto_builtin_key_derivationHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_builtin_key_derivation.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(psa_tls12_prf_key_derivation_state_t) +const + PSA_TLS12_PRF_STATE_INIT* = (0).psa_tls12_prf_key_derivation_state_t + PSA_TLS12_PRF_STATE_SEED_SET* = (PSA_TLS12_PRF_STATE_INIT + 1).psa_tls12_prf_key_derivation_state_t + PSA_TLS12_PRF_STATE_OTHER_KEY_SET* = (PSA_TLS12_PRF_STATE_SEED_SET + 1).psa_tls12_prf_key_derivation_state_t + PSA_TLS12_PRF_STATE_KEY_SET* = (PSA_TLS12_PRF_STATE_OTHER_KEY_SET + 1).psa_tls12_prf_key_derivation_state_t + PSA_TLS12_PRF_STATE_LABEL_SET* = (PSA_TLS12_PRF_STATE_KEY_SET + 1).psa_tls12_prf_key_derivation_state_t + PSA_TLS12_PRF_STATE_OUTPUT* = (PSA_TLS12_PRF_STATE_LABEL_SET + 1).psa_tls12_prf_key_derivation_state_t + + +{.pragma: impcrypto_typesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_types.h".} +{.pragma: impcrypto_builtin_primitivesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_builtin_primitives.h".} +{.pragma: impcrypto_driver_contexts_primitivesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_driver_contexts_primitives.h".} +{.pragma: impcrypto_structHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_struct.h".} +{.pragma: impcrypto_builtin_compositesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_builtin_composites.h".} +{.pragma: impcrypto_driver_contexts_compositesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_driver_contexts_composites.h".} +{.pragma: impcrypto_builtin_key_derivationHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_builtin_key_derivation.h".} +{.pragma: impcrypto_driver_contexts_key_derivationHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_driver_contexts_key_derivation.h".} +{.experimental: "codeReordering".} +{.experimental: "codeReordering".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +type + psa_hkdf_key_derivation_t* {.bycopy, importc, + impcrypto_builtin_key_derivationHdr.} = object + private_info*: ptr uint8 + private_info_length*: uint + private_offset_in_block*: uint8 + private_block_number*: uint8 + private_state* {.bitsize: 2.}: cuint + private_info_set* {.bitsize: 1.}: cuint + private_output_block*: array[64, uint8] + private_prk*: array[64, uint8] + private_hmac*: psa_mac_operation_s + + psa_tls12_ecjpake_to_pms_t* {.bycopy, importc, + impcrypto_builtin_key_derivationHdr.} = object + private_data*: array[32, uint8] + + psa_tls12_prf_key_derivation_s* {.bycopy, impcrypto_builtin_key_derivationHdr, importc: "struct psa_tls12_prf_key_derivation_s".} = object + private_left_in_block*: uint8 + private_block_number*: uint8 + private_state*: psa_tls12_prf_key_derivation_state_t + private_secret*: ptr uint8 + private_secret_length*: uint + private_seed*: ptr uint8 + private_seed_length*: uint + private_label*: ptr uint8 + private_label_length*: uint + private_other_secret*: ptr uint8 + private_other_secret_length*: uint + private_Ai*: array[64, uint8] + private_output_block*: array[64, uint8] + + psa_tls12_prf_key_derivation_t* {.importc, impcrypto_builtin_key_derivationHdr.} = psa_tls12_prf_key_derivation_s + psa_driver_key_derivation_context_t* {.union, bycopy, importc, + impcrypto_driver_contexts_key_derivationHdr.} = object + dummy*: cuint + private_hkdf*: psa_hkdf_key_derivation_t + private_tls12_prf*: psa_tls12_prf_key_derivation_t + private_tls12_ecjpake_to_pms*: psa_tls12_ecjpake_to_pms_t + + mbedtls_psa_hmac_operation_t* {.bycopy, importc, + impcrypto_builtin_compositesHdr.} = object + private_alg*: psa_algorithm_t + hash_ctx*: psa_hash_operation_s + private_opad*: array[128, uint8] + + Union_crypto_builtin_compositesh1* {.union, bycopy, + impcrypto_builtin_compositesHdr, importc: "union Union_crypto_builtin_compositesh1".} = object + private_dummy*: cuint + private_hmac*: mbedtls_psa_hmac_operation_t + private_cmac*: mbedtls_cipher_context_t + + mbedtls_psa_mac_operation_t* {.bycopy, importc, + impcrypto_builtin_compositesHdr.} = object + private_alg*: psa_algorithm_t + private_ctx*: Union_crypto_builtin_compositesh1 + + Union_crypto_builtin_compositesh2* {.union, bycopy, + impcrypto_builtin_compositesHdr, importc: "union Union_crypto_builtin_compositesh2".} = object + dummy*: cuint + private_ccm*: mbedtls_ccm_context + private_gcm*: mbedtls_gcm_context + private_chachapoly*: mbedtls_chachapoly_context + + mbedtls_psa_aead_operation_t* {.bycopy, importc, + impcrypto_builtin_compositesHdr.} = object + private_alg*: psa_algorithm_t + private_key_type*: psa_key_type_t + private_is_encrypt* {.bitsize: 1.}: cuint + private_tag_length*: uint8 + ctx*: Union_crypto_builtin_compositesh2 + + mbedtls_psa_sign_hash_interruptible_operation_t* {.bycopy, importc, + impcrypto_builtin_compositesHdr.} = object + private_dummy*: cuint + + mbedtls_psa_verify_hash_interruptible_operation_t* {.bycopy, importc, + impcrypto_builtin_compositesHdr.} = object + private_dummy*: cuint + + Union_crypto_builtin_compositesh3* {.union, bycopy, + impcrypto_builtin_compositesHdr, importc: "union Union_crypto_builtin_compositesh3".} = object + private_dummy*: cuint + private_jpake*: mbedtls_ecjpake_context + + mbedtls_psa_pake_operation_t* {.bycopy, importc, + impcrypto_builtin_compositesHdr.} = object + private_alg*: psa_algorithm_t + private_password*: ptr uint8 + private_password_len*: uint + private_role*: uint8 + private_buffer*: array[((3 + typeof(3)(1) + typeof(3)(65) + typeof(3)(1) + + typeof(3)(65) + + typeof(3)(1) + + typeof(3)(32)) * + typeof(3)(2)), uint8] + private_buffer_length*: uint + private_buffer_offset*: uint + private_ctx*: Union_crypto_builtin_compositesh3 + + psa_driver_mac_context_t* {.union, bycopy, importc, + impcrypto_driver_contexts_compositesHdr.} = object + dummy*: cuint + mbedtls_ctx*: mbedtls_psa_mac_operation_t + + psa_driver_aead_context_t* {.union, bycopy, importc, + impcrypto_driver_contexts_compositesHdr.} = object + dummy*: cuint + mbedtls_ctx*: mbedtls_psa_aead_operation_t + + psa_driver_sign_hash_interruptible_context_t* {.union, bycopy, importc, + impcrypto_driver_contexts_compositesHdr.} = object + dummy*: cuint + mbedtls_ctx*: mbedtls_psa_sign_hash_interruptible_operation_t + + psa_driver_verify_hash_interruptible_context_t* {.union, bycopy, importc, + impcrypto_driver_contexts_compositesHdr.} = object + dummy*: cuint + mbedtls_ctx*: mbedtls_psa_verify_hash_interruptible_operation_t + + psa_driver_pake_context_t* {.union, bycopy, importc, + impcrypto_driver_contexts_compositesHdr.} = object + dummy*: cuint + mbedtls_ctx*: mbedtls_psa_pake_operation_t + + Union_crypto_builtin_primitivesh1* {.union, bycopy, + impcrypto_builtin_primitivesHdr, importc: "union Union_crypto_builtin_primitivesh1".} = object + dummy*: cuint + md5*: mbedtls_md5_context + ripemd160*: mbedtls_ripemd160_context + sha1*: mbedtls_sha1_context + sha256*: mbedtls_sha256_context + sha512*: mbedtls_sha512_context + + mbedtls_psa_hash_operation_t* {.bycopy, importc, + impcrypto_builtin_primitivesHdr.} = object + private_alg*: psa_algorithm_t + private_ctx*: Union_crypto_builtin_primitivesh1 + + Union_crypto_builtin_primitivesh2* {.union, bycopy, + impcrypto_builtin_primitivesHdr, importc: "union Union_crypto_builtin_primitivesh2".} = object + private_dummy*: cuint + private_cipher*: mbedtls_cipher_context_t + + mbedtls_psa_cipher_operation_t* {.bycopy, importc, + impcrypto_builtin_primitivesHdr.} = object + private_alg*: psa_algorithm_t + private_iv_length*: uint8 + private_block_length*: uint8 + private_ctx*: Union_crypto_builtin_primitivesh2 + psa_driver_hash_context_t* {.union, bycopy, importc, + impcrypto_driver_contexts_primitivesHdr.} = object + dummy*: cuint + mbedtls_ctx*: mbedtls_psa_hash_operation_t + + psa_driver_cipher_context_t* {.union, bycopy, importc, + impcrypto_driver_contexts_primitivesHdr.} = object + dummy*: cuint + mbedtls_ctx*: mbedtls_psa_cipher_operation_t + + psa_hash_operation_s* {.bycopy, impcrypto_structHdr, + importc: "struct psa_hash_operation_s".} = object + private_id*: cuint + private_ctx*: psa_driver_hash_context_t + + psa_cipher_operation_s* {.bycopy, impcrypto_structHdr, + importc: "struct psa_cipher_operation_s".} = object + private_id*: cuint + private_iv_required* {.bitsize: 1.}: cuint + private_iv_set* {.bitsize: 1.}: cuint + private_default_iv_length*: uint8 + private_ctx*: psa_driver_cipher_context_t + + psa_mac_operation_s* {.bycopy, impcrypto_structHdr, + importc: "struct psa_mac_operation_s".} = object + private_id*: cuint + private_mac_size*: uint8 + private_is_sign* {.bitsize: 1.}: cuint + private_ctx*: psa_driver_mac_context_t + + psa_aead_operation_s* {.bycopy, impcrypto_structHdr, + importc: "struct psa_aead_operation_s".} = object + private_id*: cuint + private_alg*: psa_algorithm_t + private_key_type*: psa_key_type_t + private_ad_remaining*: uint + private_body_remaining*: uint + private_nonce_set* {.bitsize: 1.}: cuint + private_lengths_set* {.bitsize: 1.}: cuint + private_ad_started* {.bitsize: 1.}: cuint + private_body_started* {.bitsize: 1.}: cuint + private_is_encrypt* {.bitsize: 1.}: cuint + private_ctx*: psa_driver_aead_context_t + + psa_key_derivation_s* {.bycopy, impcrypto_structHdr, + importc: "struct psa_key_derivation_s".} = object + private_alg*: psa_algorithm_t + private_can_output_key* {.bitsize: 1.}: cuint + private_capacity*: uint + private_ctx*: psa_driver_key_derivation_context_t + + psa_key_policy_s* {.bycopy, impcrypto_structHdr, + importc: "struct psa_key_policy_s".} = object + private_usage*: psa_key_usage_t + private_alg*: psa_algorithm_t + private_alg2*: psa_algorithm_t + + psa_key_policy_t* {.importc, impcrypto_structHdr.} = psa_key_policy_s + psa_key_bits_t* {.importc, impcrypto_structHdr.} = uint16 + psa_key_attributes_flag_t* {.importc, impcrypto_structHdr.} = uint16 + psa_core_key_attributes_t* {.bycopy, importc, impcrypto_structHdr.} = object + private_type*: psa_key_type_t + private_bits*: psa_key_bits_t + private_lifetime*: psa_key_lifetime_t + private_id*: mbedtls_svc_key_id_t + private_policy*: psa_key_policy_t + private_flags*: psa_key_attributes_flag_t + + psa_key_attributes_s* {.bycopy, impcrypto_structHdr, + importc: "struct psa_key_attributes_s".} = object + private_core*: psa_core_key_attributes_t + private_domain_parameters*: pointer + private_domain_parameters_size*: uint + + psa_sign_hash_interruptible_operation_s* {.bycopy, impcrypto_structHdr, + importc: "struct psa_sign_hash_interruptible_operation_s".} = object + private_id*: cuint + private_ctx*: psa_driver_sign_hash_interruptible_context_t + private_error_occurred* {.bitsize: 1.}: cuint + private_num_ops*: uint32 + + psa_verify_hash_interruptible_operation_s* {.bycopy, impcrypto_structHdr, + importc: "struct psa_verify_hash_interruptible_operation_s".} = object + private_id*: cuint + private_ctx*: psa_driver_verify_hash_interruptible_context_t + private_error_occurred* {.bitsize: 1.}: cuint + private_num_ops*: uint32 + + psa_status_t* {.importc, impcrypto_typesHdr.} = int32 + psa_key_type_t* {.importc, impcrypto_typesHdr.} = uint16 + psa_ecc_family_t* {.importc, impcrypto_typesHdr.} = uint8 + psa_dh_family_t* {.importc, impcrypto_typesHdr.} = uint8 + psa_algorithm_t* {.importc, impcrypto_typesHdr.} = uint32 + psa_key_lifetime_t* {.importc, impcrypto_typesHdr.} = uint32 + psa_key_persistence_t* {.importc, impcrypto_typesHdr.} = uint8 + psa_key_location_t* {.importc, impcrypto_typesHdr.} = uint32 + psa_key_id_t* {.importc, impcrypto_typesHdr.} = uint32 + mbedtls_svc_key_id_t* {.importc, impcrypto_typesHdr.} = psa_key_id_t + psa_key_usage_t* {.importc, impcrypto_typesHdr.} = uint32 + psa_key_attributes_t* {.importc, impcrypto_typesHdr.} = psa_key_attributes_s + psa_key_derivation_step_t* {.importc, impcrypto_typesHdr.} = uint16 +{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_values.nim b/webrtc/mbedtls/psa/crypto_values.nim new file mode 100644 index 0000000..171a837 --- /dev/null +++ b/webrtc/mbedtls/psa/crypto_values.nim @@ -0,0 +1,210 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +import "crypto_types" +# +# Generated @ 2023-05-12T13:12:44+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_values.h + +# const 'PSA_ERROR_GENERIC_ERROR' has unsupported value '((psa_status_t)-132)' +# const 'PSA_ERROR_NOT_SUPPORTED' has unsupported value '((psa_status_t)-134)' +# const 'PSA_ERROR_NOT_PERMITTED' has unsupported value '((psa_status_t)-133)' +# const 'PSA_ERROR_BUFFER_TOO_SMALL' has unsupported value '((psa_status_t)-138)' +# const 'PSA_ERROR_ALREADY_EXISTS' has unsupported value '((psa_status_t)-139)' +# const 'PSA_ERROR_DOES_NOT_EXIST' has unsupported value '((psa_status_t)-140)' +# const 'PSA_ERROR_BAD_STATE' has unsupported value '((psa_status_t)-137)' +# const 'PSA_ERROR_INVALID_ARGUMENT' has unsupported value '((psa_status_t)-135)' +# const 'PSA_ERROR_INSUFFICIENT_MEMORY' has unsupported value '((psa_status_t)-141)' +# const 'PSA_ERROR_INSUFFICIENT_STORAGE' has unsupported value '((psa_status_t)-142)' +# const 'PSA_ERROR_COMMUNICATION_FAILURE' has unsupported value '((psa_status_t)-145)' +# const 'PSA_ERROR_STORAGE_FAILURE' has unsupported value '((psa_status_t)-146)' +# const 'PSA_ERROR_HARDWARE_FAILURE' has unsupported value '((psa_status_t)-147)' +# const 'PSA_ERROR_CORRUPTION_DETECTED' has unsupported value '((psa_status_t)-151)' +# const 'PSA_ERROR_INSUFFICIENT_ENTROPY' has unsupported value '((psa_status_t)-148)' +# const 'PSA_ERROR_INVALID_SIGNATURE' has unsupported value '((psa_status_t)-149)' +# const 'PSA_ERROR_INVALID_PADDING' has unsupported value '((psa_status_t)-150)' +# const 'PSA_ERROR_INSUFFICIENT_DATA' has unsupported value '((psa_status_t)-143)' +# const 'PSA_ERROR_INVALID_HANDLE' has unsupported value '((psa_status_t)-136)' +# const 'PSA_ERROR_DATA_CORRUPT' has unsupported value '((psa_status_t)-152)' +# const 'PSA_ERROR_DATA_INVALID' has unsupported value '((psa_status_t)-153)' +# const 'PSA_OPERATION_INCOMPLETE' has unsupported value '((psa_status_t)-248)' +# const 'PSA_ALG_RSA_PKCS1V15_SIGN_RAW' has unsupported value 'PSA_ALG_RSA_PKCS1V15_SIGN_BASE' +# const 'PSA_ALG_ECDSA_ANY' has unsupported value 'PSA_ALG_ECDSA_BASE' +# const 'PSA_INTERRUPTIBLE_MAX_OPS_UNLIMITED' has unsupported value 'UINT32_MAX' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.pragma: impcrypto_valuesHdr, + header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_values.h".} +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + PSA_SUCCESS* = (cast[psa_status_t](0)) + PSA_KEY_TYPE_NONE* = (cast[psa_key_type_t](0x00000000)) + PSA_KEY_TYPE_VENDOR_FLAG* = (cast[psa_key_type_t](0x00008000)) + PSA_KEY_TYPE_CATEGORY_MASK* = (cast[psa_key_type_t](0x00007000)) + PSA_KEY_TYPE_CATEGORY_RAW* = (cast[psa_key_type_t](0x00001000)) + PSA_KEY_TYPE_CATEGORY_SYMMETRIC* = (cast[psa_key_type_t](0x00002000)) + PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY* = (cast[psa_key_type_t](0x00004000)) + PSA_KEY_TYPE_CATEGORY_KEY_PAIR* = (cast[psa_key_type_t](0x00007000)) + PSA_KEY_TYPE_CATEGORY_FLAG_PAIR* = (cast[psa_key_type_t](0x00003000)) + PSA_KEY_TYPE_RAW_DATA* = (cast[psa_key_type_t](0x00001001)) + PSA_KEY_TYPE_HMAC* = (cast[psa_key_type_t](0x00001100)) + PSA_KEY_TYPE_DERIVE* = (cast[psa_key_type_t](0x00001200)) + PSA_KEY_TYPE_PASSWORD* = (cast[psa_key_type_t](0x00001203)) + PSA_KEY_TYPE_PASSWORD_HASH* = (cast[psa_key_type_t](0x00001205)) + PSA_KEY_TYPE_PEPPER* = (cast[psa_key_type_t](0x00001206)) + PSA_KEY_TYPE_AES* = (cast[psa_key_type_t](0x00002400)) + PSA_KEY_TYPE_ARIA* = (cast[psa_key_type_t](0x00002406)) + PSA_KEY_TYPE_DES* = (cast[psa_key_type_t](0x00002301)) + PSA_KEY_TYPE_CAMELLIA* = (cast[psa_key_type_t](0x00002403)) + PSA_KEY_TYPE_CHACHA20* = (cast[psa_key_type_t](0x00002004)) + PSA_KEY_TYPE_RSA_PUBLIC_KEY* = (cast[psa_key_type_t](0x00004001)) + PSA_KEY_TYPE_RSA_KEY_PAIR* = (cast[psa_key_type_t](0x00007001)) + PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE* = (cast[psa_key_type_t](0x00004100)) + PSA_KEY_TYPE_ECC_KEY_PAIR_BASE* = (cast[psa_key_type_t](0x00007100)) + PSA_KEY_TYPE_ECC_CURVE_MASK* = (cast[psa_key_type_t](0x000000FF)) + PSA_ECC_FAMILY_SECP_K1* = (cast[psa_ecc_family_t](0x00000017)) + PSA_ECC_FAMILY_SECP_R1* = (cast[psa_ecc_family_t](0x00000012)) + PSA_ECC_FAMILY_SECP_R2* = (cast[psa_ecc_family_t](0x0000001B)) + PSA_ECC_FAMILY_SECT_K1* = (cast[psa_ecc_family_t](0x00000027)) + PSA_ECC_FAMILY_SECT_R1* = (cast[psa_ecc_family_t](0x00000022)) + PSA_ECC_FAMILY_SECT_R2* = (cast[psa_ecc_family_t](0x0000002B)) + PSA_ECC_FAMILY_BRAINPOOL_P_R1* = (cast[psa_ecc_family_t](0x00000030)) + PSA_ECC_FAMILY_MONTGOMERY* = (cast[psa_ecc_family_t](0x00000041)) + PSA_ECC_FAMILY_TWISTED_EDWARDS* = (cast[psa_ecc_family_t](0x00000042)) + PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE* = (cast[psa_key_type_t](0x00004200)) + PSA_KEY_TYPE_DH_KEY_PAIR_BASE* = (cast[psa_key_type_t](0x00007200)) + PSA_KEY_TYPE_DH_GROUP_MASK* = (cast[psa_key_type_t](0x000000FF)) + PSA_DH_FAMILY_RFC7919* = (cast[psa_dh_family_t](0x00000003)) + PSA_ALG_VENDOR_FLAG* = (cast[psa_algorithm_t](0x80000000)) + PSA_ALG_CATEGORY_MASK* = (cast[psa_algorithm_t](0x7F000000)) + PSA_ALG_CATEGORY_HASH* = (cast[psa_algorithm_t](0x02000000)) + PSA_ALG_CATEGORY_MAC* = (cast[psa_algorithm_t](0x03000000)) + PSA_ALG_CATEGORY_CIPHER* = (cast[psa_algorithm_t](0x04000000)) + PSA_ALG_CATEGORY_AEAD* = (cast[psa_algorithm_t](0x05000000)) + PSA_ALG_CATEGORY_SIGN* = (cast[psa_algorithm_t](0x06000000)) + PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION* = (cast[psa_algorithm_t](0x07000000)) + PSA_ALG_CATEGORY_KEY_DERIVATION* = (cast[psa_algorithm_t](0x08000000)) + PSA_ALG_CATEGORY_KEY_AGREEMENT* = (cast[psa_algorithm_t](0x09000000)) + PSA_ALG_NONE* = (cast[psa_algorithm_t](0)) + PSA_ALG_HASH_MASK* = (cast[psa_algorithm_t](0x000000FF)) + PSA_ALG_MD5* = (cast[psa_algorithm_t](0x02000003)) + PSA_ALG_RIPEMD160* = (cast[psa_algorithm_t](0x02000004)) + PSA_ALG_SHA_1* = (cast[psa_algorithm_t](0x02000005)) + PSA_ALG_SHA_224* = (cast[psa_algorithm_t](0x02000008)) + PSA_ALG_SHA_256* = (cast[psa_algorithm_t](0x02000009)) + PSA_ALG_SHA_384* = (cast[psa_algorithm_t](0x0200000A)) + PSA_ALG_SHA_512* = (cast[psa_algorithm_t](0x0200000B)) + PSA_ALG_SHA_512_224* = (cast[psa_algorithm_t](0x0200000C)) + PSA_ALG_SHA_512_256* = (cast[psa_algorithm_t](0x0200000D)) + PSA_ALG_SHA3_224* = (cast[psa_algorithm_t](0x02000010)) + PSA_ALG_SHA3_256* = (cast[psa_algorithm_t](0x02000011)) + PSA_ALG_SHA3_384* = (cast[psa_algorithm_t](0x02000012)) + PSA_ALG_SHA3_512* = (cast[psa_algorithm_t](0x02000013)) + PSA_ALG_SHAKE256_512* = (cast[psa_algorithm_t](0x02000015)) + PSA_ALG_ANY_HASH* = (cast[psa_algorithm_t](0x020000FF)) + PSA_ALG_MAC_SUBCATEGORY_MASK* = (cast[psa_algorithm_t](0x00C00000)) + PSA_ALG_HMAC_BASE* = (cast[psa_algorithm_t](0x03800000)) + PSA_ALG_MAC_TRUNCATION_MASK* = (cast[psa_algorithm_t](0x003F0000)) + PSA_MAC_TRUNCATION_OFFSET* = 16 + PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG* = (cast[psa_algorithm_t](0x00008000)) + PSA_ALG_CIPHER_MAC_BASE* = (cast[psa_algorithm_t](0x03C00000)) + PSA_ALG_CBC_MAC* = (cast[psa_algorithm_t](0x03C00100)) + PSA_ALG_CMAC* = (cast[psa_algorithm_t](0x03C00200)) + PSA_ALG_CIPHER_STREAM_FLAG* = (cast[psa_algorithm_t](0x00800000)) + PSA_ALG_CIPHER_FROM_BLOCK_FLAG* = (cast[psa_algorithm_t](0x00400000)) + PSA_ALG_STREAM_CIPHER* = (cast[psa_algorithm_t](0x04800100)) + PSA_ALG_CTR* = (cast[psa_algorithm_t](0x04C01000)) + PSA_ALG_CFB* = (cast[psa_algorithm_t](0x04C01100)) + PSA_ALG_OFB* = (cast[psa_algorithm_t](0x04C01200)) + PSA_ALG_XTS* = (cast[psa_algorithm_t](0x0440FF00)) + PSA_ALG_ECB_NO_PADDING* = (cast[psa_algorithm_t](0x04404400)) + PSA_ALG_CBC_NO_PADDING* = (cast[psa_algorithm_t](0x04404000)) + PSA_ALG_CBC_PKCS7* = (cast[psa_algorithm_t](0x04404100)) + PSA_ALG_AEAD_FROM_BLOCK_FLAG* = (cast[psa_algorithm_t](0x00400000)) + PSA_ALG_CCM* = (cast[psa_algorithm_t](0x05500100)) + PSA_ALG_CCM_STAR_NO_TAG* = (cast[psa_algorithm_t](0x04C01300)) + PSA_ALG_GCM* = (cast[psa_algorithm_t](0x05500200)) + PSA_ALG_CHACHA20_POLY1305* = (cast[psa_algorithm_t](0x05100500)) + PSA_ALG_AEAD_TAG_LENGTH_MASK* = (cast[psa_algorithm_t](0x003F0000)) + PSA_AEAD_TAG_LENGTH_OFFSET* = 16 + PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG* = (cast[psa_algorithm_t](0x00008000)) + PSA_ALG_RSA_PKCS1V15_SIGN_BASE* = (cast[psa_algorithm_t](0x06000200)) + PSA_ALG_RSA_PSS_BASE* = (cast[psa_algorithm_t](0x06000300)) + PSA_ALG_RSA_PSS_ANY_SALT_BASE* = (cast[psa_algorithm_t](0x06001300)) + PSA_ALG_ECDSA_BASE* = (cast[psa_algorithm_t](0x06000600)) + PSA_ALG_DETERMINISTIC_ECDSA_BASE* = (cast[psa_algorithm_t](0x06000700)) + PSA_ALG_ECDSA_DETERMINISTIC_FLAG* = (cast[psa_algorithm_t](0x00000100)) + PSA_ALG_PURE_EDDSA* = (cast[psa_algorithm_t](0x06000800)) + PSA_ALG_HASH_EDDSA_BASE* = (cast[psa_algorithm_t](0x06000900)) + PSA_ALG_ED25519PH* = (PSA_ALG_HASH_EDDSA_BASE or + typeof(PSA_ALG_HASH_EDDSA_BASE)((PSA_ALG_SHA_512 and + typeof(PSA_ALG_HASH_EDDSA_BASE)(PSA_ALG_HASH_MASK)))) + PSA_ALG_ED448PH* = (PSA_ALG_HASH_EDDSA_BASE or + typeof(PSA_ALG_HASH_EDDSA_BASE)((PSA_ALG_SHAKE256_512 and + typeof(PSA_ALG_HASH_EDDSA_BASE)(PSA_ALG_HASH_MASK)))) + PSA_ALG_RSA_PKCS1V15_CRYPT* = (cast[psa_algorithm_t](0x07000200)) + PSA_ALG_RSA_OAEP_BASE* = (cast[psa_algorithm_t](0x07000300)) + PSA_ALG_HKDF_BASE* = (cast[psa_algorithm_t](0x08000100)) + PSA_ALG_HKDF_EXTRACT_BASE* = (cast[psa_algorithm_t](0x08000400)) + PSA_ALG_HKDF_EXPAND_BASE* = (cast[psa_algorithm_t](0x08000500)) + PSA_ALG_TLS12_PRF_BASE* = (cast[psa_algorithm_t](0x08000200)) + PSA_ALG_TLS12_PSK_TO_MS_BASE* = (cast[psa_algorithm_t](0x08000300)) + PSA_ALG_TLS12_ECJPAKE_TO_PMS* = (cast[psa_algorithm_t](0x08000609)) + PSA_ALG_KEY_DERIVATION_STRETCHING_FLAG* = (cast[psa_algorithm_t](0x00800000)) + PSA_ALG_PBKDF2_HMAC_BASE* = (cast[psa_algorithm_t](0x08800100)) + PSA_ALG_PBKDF2_AES_CMAC_PRF_128* = (cast[psa_algorithm_t](0x08800200)) + PSA_ALG_KEY_DERIVATION_MASK* = (cast[psa_algorithm_t](0xFE00FFFF)) + PSA_ALG_KEY_AGREEMENT_MASK* = (cast[psa_algorithm_t](0xFFFF0000)) + PSA_ALG_FFDH* = (cast[psa_algorithm_t](0x09010000)) + PSA_ALG_ECDH* = (cast[psa_algorithm_t](0x09020000)) + PSA_KEY_LIFETIME_VOLATILE* = (cast[psa_key_lifetime_t](0x00000000)) + PSA_KEY_LIFETIME_PERSISTENT* = (cast[psa_key_lifetime_t](0x00000001)) + PSA_KEY_PERSISTENCE_VOLATILE* = (cast[psa_key_persistence_t](0x00000000)) + PSA_KEY_PERSISTENCE_DEFAULT* = (cast[psa_key_persistence_t](0x00000001)) + PSA_KEY_PERSISTENCE_READ_ONLY* = (cast[psa_key_persistence_t](0x000000FF)) + PSA_KEY_LOCATION_LOCAL_STORAGE* = (cast[psa_key_location_t](0x00000000)) + PSA_KEY_LOCATION_VENDOR_FLAG* = (cast[psa_key_location_t](0x00800000)) + PSA_KEY_ID_NULL* = (cast[psa_key_id_t](0)) + PSA_KEY_ID_USER_MIN* = (cast[psa_key_id_t](0x00000001)) + PSA_KEY_ID_USER_MAX* = (cast[psa_key_id_t](0x3FFFFFFF)) + PSA_KEY_ID_VENDOR_MIN* = (cast[psa_key_id_t](0x40000000)) + PSA_KEY_ID_VENDOR_MAX* = (cast[psa_key_id_t](0x7FFFFFFF)) + MBEDTLS_SVC_KEY_ID_INIT* = (cast[psa_key_id_t](0)) + PSA_KEY_USAGE_EXPORT* = (cast[psa_key_usage_t](0x00000001)) + PSA_KEY_USAGE_COPY* = (cast[psa_key_usage_t](0x00000002)) + PSA_KEY_USAGE_ENCRYPT* = (cast[psa_key_usage_t](0x00000100)) + PSA_KEY_USAGE_DECRYPT* = (cast[psa_key_usage_t](0x00000200)) + PSA_KEY_USAGE_SIGN_MESSAGE* = (cast[psa_key_usage_t](0x00000400)) + PSA_KEY_USAGE_VERIFY_MESSAGE* = (cast[psa_key_usage_t](0x00000800)) + PSA_KEY_USAGE_SIGN_HASH* = (cast[psa_key_usage_t](0x00001000)) + PSA_KEY_USAGE_VERIFY_HASH* = (cast[psa_key_usage_t](0x00002000)) + PSA_KEY_USAGE_DERIVE* = (cast[psa_key_usage_t](0x00004000)) + PSA_KEY_USAGE_VERIFY_DERIVATION* = (cast[psa_key_usage_t](0x00008000)) + PSA_KEY_DERIVATION_INPUT_SECRET* = ( + cast[psa_key_derivation_step_t](0x00000101)) + PSA_KEY_DERIVATION_INPUT_PASSWORD* = ( + cast[psa_key_derivation_step_t](0x00000102)) + PSA_KEY_DERIVATION_INPUT_OTHER_SECRET* = ( + cast[psa_key_derivation_step_t](0x00000103)) + PSA_KEY_DERIVATION_INPUT_LABEL* = (cast[psa_key_derivation_step_t](0x00000201)) + PSA_KEY_DERIVATION_INPUT_SALT* = (cast[psa_key_derivation_step_t](0x00000202)) + PSA_KEY_DERIVATION_INPUT_INFO* = (cast[psa_key_derivation_step_t](0x00000203)) + PSA_KEY_DERIVATION_INPUT_SEED* = (cast[psa_key_derivation_step_t](0x00000204)) + PSA_KEY_DERIVATION_INPUT_COST* = (cast[psa_key_derivation_step_t](0x00000205)) +proc mbedtls_svc_key_id_make*(unused: cuint; key_id: psa_key_id_t): mbedtls_svc_key_id_t {. + importc, cdecl, impcrypto_valuesHdr.} +proc mbedtls_svc_key_id_equal*(id1: mbedtls_svc_key_id_t; + id2: mbedtls_svc_key_id_t): cint {.importc, + cdecl, impcrypto_valuesHdr.} +proc mbedtls_svc_key_id_is_null*(key: mbedtls_svc_key_id_t): cint {.importc, + cdecl, impcrypto_valuesHdr.} +{.pop.} diff --git a/webrtc/mbedtls/psa_util.nim b/webrtc/mbedtls/psa_util.nim new file mode 100644 index 0000000..fc8d8de --- /dev/null +++ b/webrtc/mbedtls/psa_util.nim @@ -0,0 +1,53 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "ctr_drbg" +import "pkcs5" +import "pkcs12" +import "psa/crypto_types" +{.compile: "./mbedtls/library/psa_util.c".} +# Generated @ 2023-05-11T11:19:13+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/psa_util.h + +# proc 'mbedtls_psa_translate_cipher_type' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_psa_translate_cipher_mode' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_psa_translate_cipher_operation' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_psa_translate_md' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_psa_get_ecc_oid_from_id' skipped - static inline procs cannot work with '--noHeader | -H' +# const 'MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH' has unsupported value 'PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)' +# const 'MBEDTLS_PSA_MAX_EC_KEY_PAIR_LENGTH' has unsupported value 'PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)' +# const 'MBEDTLS_PSA_RANDOM_STATE' has unsupported value 'mbedtls_psa_random_state' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +type + mbedtls_f_rng_t* = proc (p_rng: pointer; output: ptr byte; output_size: uint): cint {. + cdecl.} + mbedtls_psa_drbg_context_t* = mbedtls_ctr_drbg_context + mbedtls_error_pair_t* {.bycopy.} = object + psa_status*: psa_status_t + mbedtls_error*: int16 + +var + mbedtls_psa_get_random* {.importc.}: ptr mbedtls_f_rng_t + mbedtls_psa_random_state* {.importc.}: ptr mbedtls_psa_drbg_context_t + psa_to_lms_errors* {.importc.}: array[3, mbedtls_error_pair_t] + psa_to_pk_rsa_errors* {.importc.}: array[8, mbedtls_error_pair_t] +proc psa_generic_status_to_mbedtls*(status: psa_status_t): cint {.importc, cdecl.} +proc psa_status_to_mbedtls*(status: psa_status_t; + local_translations: ptr mbedtls_error_pair_t; + local_errors_num: uint; + fallback_f: proc (a1: psa_status_t): cint {.cdecl.}): cint {. + importc, cdecl.} +proc psa_pk_status_to_mbedtls*(status: psa_status_t): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/ripemd160.nim b/webrtc/mbedtls/ripemd160.nim new file mode 100644 index 0000000..78f3885 --- /dev/null +++ b/webrtc/mbedtls/ripemd160.nim @@ -0,0 +1,47 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "platform_time" +{.compile: "./mbedtls/library/ripemd160.c".} +# Generated @ 2023-05-11T11:19:13+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ripemd160.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +type + mbedtls_ripemd160_context* {.bycopy.} = object + private_total*: array[2, uint32] + private_state*: array[5, uint32] + private_buffer*: array[64, byte] + +proc mbedtls_ripemd160_init*(ctx: ptr mbedtls_ripemd160_context) {.importc, + cdecl.} +proc mbedtls_ripemd160_free*(ctx: ptr mbedtls_ripemd160_context) {.importc, + cdecl.} +proc mbedtls_ripemd160_clone*(dst: ptr mbedtls_ripemd160_context; + src: ptr mbedtls_ripemd160_context) {.importc, + cdecl.} +proc mbedtls_ripemd160_starts*(ctx: ptr mbedtls_ripemd160_context): cint {. + importc, cdecl.} +proc mbedtls_ripemd160_update*(ctx: ptr mbedtls_ripemd160_context; + input: ptr byte; ilen: uint): cint {.importc, + cdecl.} +proc mbedtls_ripemd160_finish*(ctx: ptr mbedtls_ripemd160_context; + output: array[20, byte]): cint {.importc, cdecl.} +proc mbedtls_internal_ripemd160_process*(ctx: ptr mbedtls_ripemd160_context; + data: array[64, byte]): cint {.importc, cdecl.} +proc mbedtls_ripemd160*(input: ptr byte; ilen: uint; output: array[20, byte]): cint {. + importc, cdecl.} +proc mbedtls_ripemd160_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/rsa.nim b/webrtc/mbedtls/rsa.nim new file mode 100644 index 0000000..b6f77bd --- /dev/null +++ b/webrtc/mbedtls/rsa.nim @@ -0,0 +1,177 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "hash_info" +import "bignum" +import "md" +import "platform_time" +{.compile: "./mbedtls/library/oid.c"} +{.compile: "./mbedtls/library/rsa.c"} +{.compile: "./mbedtls/library/rsa_alt_helpers.c"} +# Generated @ 2023-05-11T11:19:13+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/rsa.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_RSA_BAD_INPUT_DATA* = -0x00004080 + MBEDTLS_ERR_RSA_INVALID_PADDING* = -0x00004100 + MBEDTLS_ERR_RSA_KEY_GEN_FAILED* = -0x00004180 + MBEDTLS_ERR_RSA_KEY_CHECK_FAILED* = -0x00004200 + MBEDTLS_ERR_RSA_PUBLIC_FAILED* = -0x00004280 + MBEDTLS_ERR_RSA_PRIVATE_FAILED* = -0x00004300 + MBEDTLS_ERR_RSA_VERIFY_FAILED* = -0x00004380 + MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE* = -0x00004400 + MBEDTLS_ERR_RSA_RNG_FAILED* = -0x00004480 + MBEDTLS_RSA_PKCS_V15* = 0 + MBEDTLS_RSA_PKCS_V21* = 1 + MBEDTLS_RSA_SIGN* = 1 + MBEDTLS_RSA_CRYPT* = 2 + MBEDTLS_RSA_SALT_LEN_ANY* = -1 +type + mbedtls_rsa_context* {.bycopy.} = object + private_ver*: cint + private_len*: uint + private_N*: mbedtls_mpi + private_E*: mbedtls_mpi + private_D*: mbedtls_mpi + private_P*: mbedtls_mpi + private_Q*: mbedtls_mpi + private_DP*: mbedtls_mpi + private_DQ*: mbedtls_mpi + private_QP*: mbedtls_mpi + private_RN*: mbedtls_mpi + private_RP*: mbedtls_mpi + private_RQ*: mbedtls_mpi + private_Vi*: mbedtls_mpi + private_Vf*: mbedtls_mpi + private_padding*: cint + private_hash_id*: cint + +proc mbedtls_rsa_init*(ctx: ptr mbedtls_rsa_context) {.importc, cdecl.} +proc mbedtls_rsa_set_padding*(ctx: ptr mbedtls_rsa_context; padding: cint; + hash_id: mbedtls_md_type_t): cint {.importc, cdecl.} +proc mbedtls_rsa_get_padding_mode*(ctx: ptr mbedtls_rsa_context): cint {. + importc, cdecl.} +proc mbedtls_rsa_get_md_alg*(ctx: ptr mbedtls_rsa_context): cint {.importc, + cdecl.} +proc mbedtls_rsa_import*(ctx: ptr mbedtls_rsa_context; N: ptr mbedtls_mpi; + P: ptr mbedtls_mpi; Q: ptr mbedtls_mpi; + D: ptr mbedtls_mpi; E: ptr mbedtls_mpi): cint {. + importc, cdecl.} +proc mbedtls_rsa_import_raw*(ctx: ptr mbedtls_rsa_context; N: ptr byte; + N_len: uint; P: ptr byte; P_len: uint; + Q: ptr byte; Q_len: uint; D: ptr byte; + D_len: uint; E: ptr byte; E_len: uint): cint {. + importc, cdecl.} +proc mbedtls_rsa_complete*(ctx: ptr mbedtls_rsa_context): cint {.importc, cdecl.} +proc mbedtls_rsa_export*(ctx: ptr mbedtls_rsa_context; N: ptr mbedtls_mpi; + P: ptr mbedtls_mpi; Q: ptr mbedtls_mpi; + D: ptr mbedtls_mpi; E: ptr mbedtls_mpi): cint {. + importc, cdecl.} +proc mbedtls_rsa_export_raw*(ctx: ptr mbedtls_rsa_context; N: ptr byte; + N_len: uint; P: ptr byte; P_len: uint; + Q: ptr byte; Q_len: uint; D: ptr byte; + D_len: uint; E: ptr byte; E_len: uint): cint {. + importc, cdecl.} +proc mbedtls_rsa_export_crt*(ctx: ptr mbedtls_rsa_context; DP: ptr mbedtls_mpi; + DQ: ptr mbedtls_mpi; QP: ptr mbedtls_mpi): cint {. + importc, cdecl.} +proc mbedtls_rsa_get_len*(ctx: ptr mbedtls_rsa_context): uint {.importc, cdecl.} +proc mbedtls_rsa_gen_key*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; + nbits: cuint; exponent: cint): cint {.importc, cdecl.} +proc mbedtls_rsa_check_pubkey*(ctx: ptr mbedtls_rsa_context): cint {.importc, + cdecl.} +proc mbedtls_rsa_check_privkey*(ctx: ptr mbedtls_rsa_context): cint {.importc, + cdecl.} +proc mbedtls_rsa_check_pub_priv*(pub: ptr mbedtls_rsa_context; + prv: ptr mbedtls_rsa_context): cint {.importc, + cdecl.} +proc mbedtls_rsa_public*(ctx: ptr mbedtls_rsa_context; input: ptr byte; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_rsa_private*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; + input: ptr byte; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_rsa_pkcs1_encrypt*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; + ilen: uint; input: ptr byte; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_rsa_rsaes_pkcs1_v15_encrypt*(ctx: ptr mbedtls_rsa_context; + f_rng: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; + p_rng: pointer; ilen: uint; input: ptr byte; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_rsa_rsaes_oaep_encrypt*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; + label: ptr byte; label_len: uint; + ilen: uint; input: ptr byte; + output: ptr byte): cint {.importc, cdecl.} +proc mbedtls_rsa_pkcs1_decrypt*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; + olen: ptr uint; input: ptr byte; + output: ptr byte; output_max_len: uint): cint {. + importc, cdecl.} +proc mbedtls_rsa_rsaes_pkcs1_v15_decrypt*(ctx: ptr mbedtls_rsa_context; + f_rng: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; + p_rng: pointer; olen: ptr uint; input: ptr byte; output: ptr byte; + output_max_len: uint): cint {.importc, cdecl.} +proc mbedtls_rsa_rsaes_oaep_decrypt*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; + label: ptr byte; label_len: uint; + olen: ptr uint; input: ptr byte; + output: ptr byte; output_max_len: uint): cint {. + importc, cdecl.} +proc mbedtls_rsa_pkcs1_sign*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; + md_alg: mbedtls_md_type_t; hashlen: cuint; + hash: ptr byte; sig: ptr byte): cint {.importc, + cdecl.} +proc mbedtls_rsa_rsassa_pkcs1_v15_sign*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; + md_alg: mbedtls_md_type_t; + hashlen: cuint; hash: ptr byte; + sig: ptr byte): cint {.importc, cdecl.} +proc mbedtls_rsa_rsassa_pss_sign_ext*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; + md_alg: mbedtls_md_type_t; hashlen: cuint; + hash: ptr byte; saltlen: cint; + sig: ptr byte): cint {.importc, cdecl.} +proc mbedtls_rsa_rsassa_pss_sign*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; + md_alg: mbedtls_md_type_t; hashlen: cuint; + hash: ptr byte; sig: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_rsa_pkcs1_verify*(ctx: ptr mbedtls_rsa_context; + md_alg: mbedtls_md_type_t; hashlen: cuint; + hash: ptr byte; sig: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_rsa_rsassa_pkcs1_v15_verify*(ctx: ptr mbedtls_rsa_context; + md_alg: mbedtls_md_type_t; hashlen: cuint; hash: ptr byte; sig: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_rsa_rsassa_pss_verify*(ctx: ptr mbedtls_rsa_context; + md_alg: mbedtls_md_type_t; hashlen: cuint; + hash: ptr byte; sig: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_rsa_rsassa_pss_verify_ext*(ctx: ptr mbedtls_rsa_context; + md_alg: mbedtls_md_type_t; + hashlen: cuint; hash: ptr byte; + mgf1_hash_id: mbedtls_md_type_t; + expected_salt_len: cint; sig: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_rsa_copy*(dst: ptr mbedtls_rsa_context; + src: ptr mbedtls_rsa_context): cint {.importc, cdecl.} +proc mbedtls_rsa_free*(ctx: ptr mbedtls_rsa_context) {.importc, cdecl.} +proc mbedtls_rsa_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/sha1.nim b/webrtc/mbedtls/sha1.nim new file mode 100644 index 0000000..a1b1e2e --- /dev/null +++ b/webrtc/mbedtls/sha1.nim @@ -0,0 +1,45 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "platform_time" +{.compile: "./mbedtls/library/sha1.c".} +# Generated @ 2023-05-11T11:19:13+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/sha1.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_SHA1_BAD_INPUT_DATA* = -0x00000073 +type + mbedtls_sha1_context* {.bycopy.} = object + private_total*: array[2, uint32] + private_state*: array[5, uint32] + private_buffer*: array[64, byte] + +proc mbedtls_sha1_init*(ctx: ptr mbedtls_sha1_context) {.importc, cdecl.} +proc mbedtls_sha1_free*(ctx: ptr mbedtls_sha1_context) {.importc, cdecl.} +proc mbedtls_sha1_clone*(dst: ptr mbedtls_sha1_context; + src: ptr mbedtls_sha1_context) {.importc, cdecl.} +proc mbedtls_sha1_starts*(ctx: ptr mbedtls_sha1_context): cint {.importc, cdecl.} +proc mbedtls_sha1_update*(ctx: ptr mbedtls_sha1_context; input: ptr byte; + ilen: uint): cint {.importc, cdecl.} +proc mbedtls_sha1_finish*(ctx: ptr mbedtls_sha1_context; + output: array[20, byte]): cint {.importc, cdecl.} +proc mbedtls_internal_sha1_process*(ctx: ptr mbedtls_sha1_context; + data: array[64, byte]): cint {.importc, + cdecl.} +proc mbedtls_sha1*(input: ptr byte; ilen: uint; output: array[20, byte]): cint {. + importc, cdecl.} +proc mbedtls_sha1_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/sha256.nim b/webrtc/mbedtls/sha256.nim new file mode 100644 index 0000000..edfe16c --- /dev/null +++ b/webrtc/mbedtls/sha256.nim @@ -0,0 +1,48 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "platform_time" +{.compile: "./mbedtls/library/sha256.c".} +# Generated @ 2023-05-11T11:19:13+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/sha256.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_SHA256_BAD_INPUT_DATA* = -0x00000074 +type + mbedtls_sha256_context* {.bycopy.} = object + private_total*: array[2, uint32] + private_state*: array[8, uint32] + private_buffer*: array[64, byte] + private_is224*: cint + +proc mbedtls_sha256_init*(ctx: ptr mbedtls_sha256_context) {.importc, cdecl.} +proc mbedtls_sha256_free*(ctx: ptr mbedtls_sha256_context) {.importc, cdecl.} +proc mbedtls_sha256_clone*(dst: ptr mbedtls_sha256_context; + src: ptr mbedtls_sha256_context) {.importc, cdecl.} +proc mbedtls_sha256_starts*(ctx: ptr mbedtls_sha256_context; is224: cint): cint {. + importc, cdecl.} +proc mbedtls_sha256_update*(ctx: ptr mbedtls_sha256_context; input: ptr byte; + ilen: uint): cint {.importc, cdecl.} +proc mbedtls_sha256_finish*(ctx: ptr mbedtls_sha256_context; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_internal_sha256_process*(ctx: ptr mbedtls_sha256_context; + data: array[64, byte]): cint {.importc, + cdecl.} +proc mbedtls_sha256*(input: ptr byte; ilen: uint; output: ptr byte; + is224: cint): cint {.importc, cdecl.} +proc mbedtls_sha224_self_test*(verbose: cint): cint {.importc, cdecl.} +proc mbedtls_sha256_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/sha512.nim b/webrtc/mbedtls/sha512.nim new file mode 100644 index 0000000..90a3939 --- /dev/null +++ b/webrtc/mbedtls/sha512.nim @@ -0,0 +1,48 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "platform_time" +{.compile: "./mbedtls/library/sha512.c".} +# Generated @ 2023-05-11T11:19:13+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/sha512.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_SHA512_BAD_INPUT_DATA* = -0x00000075 +type + mbedtls_sha512_context* {.bycopy.} = object + private_total*: array[2, uint64] + private_state*: array[8, uint64] + private_buffer*: array[128, byte] + private_is384*: cint + +proc mbedtls_sha512_init*(ctx: ptr mbedtls_sha512_context) {.importc, cdecl.} +proc mbedtls_sha512_free*(ctx: ptr mbedtls_sha512_context) {.importc, cdecl.} +proc mbedtls_sha512_clone*(dst: ptr mbedtls_sha512_context; + src: ptr mbedtls_sha512_context) {.importc, cdecl.} +proc mbedtls_sha512_starts*(ctx: ptr mbedtls_sha512_context; is384: cint): cint {. + importc, cdecl.} +proc mbedtls_sha512_update*(ctx: ptr mbedtls_sha512_context; input: ptr byte; + ilen: uint): cint {.importc, cdecl.} +proc mbedtls_sha512_finish*(ctx: ptr mbedtls_sha512_context; output: ptr byte): cint {. + importc, cdecl.} +proc mbedtls_internal_sha512_process*(ctx: ptr mbedtls_sha512_context; + data: array[128, byte]): cint {.importc, + cdecl.} +proc mbedtls_sha512*(input: ptr byte; ilen: uint; output: ptr byte; + is384: cint): cint {.importc, cdecl.} +proc mbedtls_sha384_self_test*(verbose: cint): cint {.importc, cdecl.} +proc mbedtls_sha512_self_test*(verbose: cint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/ssl.nim b/webrtc/mbedtls/ssl.nim new file mode 100644 index 0000000..5591ee6 --- /dev/null +++ b/webrtc/mbedtls/ssl.nim @@ -0,0 +1,893 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "platform_util" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "platform_time" +import "private_access" +import "bignum" +import "ecp" +import "ssl_ciphersuites" +import "pk" +import "md" +import "rsa" +import "ecdsa" +import "cipher" +import "x509_crt" +import "x509" +import "asn1" +import "x509_crl" +import "dhm" +import "ecdh" +import "md5" +import "ripemd160" +import "sha1" +import "sha256" +import "sha512" +import "cmac" +import "gcm" +import "ccm" +import "chachapoly" +import "poly1305" +import "chacha20" +import "ecjpake" +{.compile: "./mbedtls/library/ssl_ciphersuites.c".} +{.compile: "./mbedtls/library/ssl_msg.c".} +{.compile: "./mbedtls/library/ssl_tls12_server.c".} +{.compile: "./mbedtls/library/ssl_tls.c".} +# Generated @ 2023-05-11T11:19:14+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ssl.h + +# const 'MBEDTLS_PREMASTER_SIZE' has unsupported value 'sizeof(union mbedtls_ssl_premaster_secret)' +# const 'MBEDTLS_TLS1_3_MD_MAX_SIZE' has unsupported value 'PSA_HASH_MAX_SIZE' +# proc 'mbedtls_ssl_context_get_config' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_conf_cert_cb' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_conf_set_user_data_p' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_conf_set_user_data_n' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_conf_get_user_data_p' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_conf_get_user_data_n' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_set_user_data_p' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_set_user_data_n' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_get_user_data_p' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_get_user_data_n' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_conf_dn_hints' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_conf_max_tls_version' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_conf_min_tls_version' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_get_version_number' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_is_handshake_over' skipped - static inline procs cannot work with '--noHeader | -H' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(mbedtls_ssl_states) +defineEnum(mbedtls_ssl_protocol_version) +defineEnum(mbedtls_tls_prf_types) +defineEnum(mbedtls_ssl_key_export_type) +const + MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS* = -0x00007000 + MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE* = -0x00007080 + MBEDTLS_ERR_SSL_BAD_INPUT_DATA* = -0x00007100 + MBEDTLS_ERR_SSL_INVALID_MAC* = -0x00007180 + MBEDTLS_ERR_SSL_INVALID_RECORD* = -0x00007200 + MBEDTLS_ERR_SSL_CONN_EOF* = -0x00007280 + MBEDTLS_ERR_SSL_DECODE_ERROR* = -0x00007300 + MBEDTLS_ERR_SSL_NO_RNG* = -0x00007400 + MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE* = -0x00007480 + MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION* = -0x00007500 + MBEDTLS_ERR_SSL_NO_APPLICATION_PROTOCOL* = -0x00007580 + MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED* = -0x00007600 + MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED* = -0x00007680 + MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE* = -0x00007700 + MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE* = -0x00007780 + MBEDTLS_ERR_SSL_UNRECOGNIZED_NAME* = -0x00007800 + MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY* = -0x00007880 + MBEDTLS_ERR_SSL_BAD_CERTIFICATE* = -0x00007A00 + MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET* = -0x00007B00 + MBEDTLS_ERR_SSL_CANNOT_READ_EARLY_DATA* = -0x00007B80 + MBEDTLS_ERR_SSL_CANNOT_WRITE_EARLY_DATA* = -0x00007C00 + MBEDTLS_ERR_SSL_CACHE_ENTRY_NOT_FOUND* = -0x00007E80 + MBEDTLS_ERR_SSL_ALLOC_FAILED* = -0x00007F00 + MBEDTLS_ERR_SSL_HW_ACCEL_FAILED* = -0x00007F80 + MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH* = -0x00006F80 + MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION* = -0x00006E80 + MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE* = -0x00006E00 + MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED* = -0x00006D80 + MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH* = -0x00006D00 + MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY* = -0x00006C80 + MBEDTLS_ERR_SSL_INTERNAL_ERROR* = -0x00006C00 + MBEDTLS_ERR_SSL_COUNTER_WRAPPING* = -0x00006B80 + MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO* = -0x00006B00 + MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED* = -0x00006A80 + MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL* = -0x00006A00 + MBEDTLS_ERR_SSL_WANT_READ* = -0x00006900 + MBEDTLS_ERR_SSL_WANT_WRITE* = -0x00006880 + MBEDTLS_ERR_SSL_TIMEOUT* = -0x00006800 + MBEDTLS_ERR_SSL_CLIENT_RECONNECT* = -0x00006780 + MBEDTLS_ERR_SSL_UNEXPECTED_RECORD* = -0x00006700 + MBEDTLS_ERR_SSL_NON_FATAL* = -0x00006680 + MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER* = -0x00006600 + MBEDTLS_ERR_SSL_CONTINUE_PROCESSING* = -0x00006580 + MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS* = -0x00006500 + MBEDTLS_ERR_SSL_EARLY_MESSAGE* = -0x00006480 + MBEDTLS_ERR_SSL_UNEXPECTED_CID* = -0x00006000 + MBEDTLS_ERR_SSL_VERSION_MISMATCH* = -0x00005F00 + MBEDTLS_ERR_SSL_BAD_CONFIG* = -0x00005E80 + MBEDTLS_SSL_TLS1_3_PSK_MODE_PURE* = 0 + MBEDTLS_SSL_TLS1_3_PSK_MODE_ECDHE* = 1 + MBEDTLS_SSL_IANA_TLS_GROUP_NONE* = 0 + MBEDTLS_SSL_IANA_TLS_GROUP_SECP192K1* = 0x00000012 + MBEDTLS_SSL_IANA_TLS_GROUP_SECP192R1* = 0x00000013 + MBEDTLS_SSL_IANA_TLS_GROUP_SECP224K1* = 0x00000014 + MBEDTLS_SSL_IANA_TLS_GROUP_SECP224R1* = 0x00000015 + MBEDTLS_SSL_IANA_TLS_GROUP_SECP256K1* = 0x00000016 + MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1* = 0x00000017 + MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1* = 0x00000018 + MBEDTLS_SSL_IANA_TLS_GROUP_SECP521R1* = 0x00000019 + MBEDTLS_SSL_IANA_TLS_GROUP_BP256R1* = 0x0000001A + MBEDTLS_SSL_IANA_TLS_GROUP_BP384R1* = 0x0000001B + MBEDTLS_SSL_IANA_TLS_GROUP_BP512R1* = 0x0000001C + MBEDTLS_SSL_IANA_TLS_GROUP_X25519* = 0x0000001D + MBEDTLS_SSL_IANA_TLS_GROUP_X448* = 0x0000001E + MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE2048* = 0x00000100 + MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE3072* = 0x00000101 + MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE4096* = 0x00000102 + MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE6144* = 0x00000103 + MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE8192* = 0x00000104 + MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK* = (1'u shl typeof(1'u)(0)) + MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL* = (1'u shl typeof(1'u)(1)) + MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL* = (1'u shl typeof(1'u)(2)) + MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_ALL* = (MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK or + typeof(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK)( + MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL) or + typeof(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK)( + MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL)) + MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ALL* = (MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK or + typeof(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK)( + MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL)) + MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ALL* = (MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL or + typeof(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL)( + MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL)) + MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_NONE* = (0) + MBEDTLS_SSL_MAJOR_VERSION_3* = 3 + MBEDTLS_SSL_MINOR_VERSION_3* = 3 + MBEDTLS_SSL_MINOR_VERSION_4* = 4 + MBEDTLS_SSL_TRANSPORT_STREAM* = 0 + MBEDTLS_SSL_TRANSPORT_DATAGRAM* = 1 + MBEDTLS_SSL_MAX_HOST_NAME_LEN* = 255 + MBEDTLS_SSL_MAX_ALPN_NAME_LEN* = 255 + MBEDTLS_SSL_MAX_ALPN_LIST_LEN* = 65535 + MBEDTLS_SSL_MAX_FRAG_LEN_NONE* = 0 + MBEDTLS_SSL_MAX_FRAG_LEN_512* = 1 + MBEDTLS_SSL_MAX_FRAG_LEN_1024* = 2 + MBEDTLS_SSL_MAX_FRAG_LEN_2048* = 3 + MBEDTLS_SSL_MAX_FRAG_LEN_4096* = 4 + MBEDTLS_SSL_MAX_FRAG_LEN_INVALID* = 5 + MBEDTLS_SSL_IS_CLIENT* = 0 + MBEDTLS_SSL_IS_SERVER* = 1 + MBEDTLS_SSL_EXTENDED_MS_DISABLED* = 0 + MBEDTLS_SSL_EXTENDED_MS_ENABLED* = 1 + MBEDTLS_SSL_CID_DISABLED* = 0 + MBEDTLS_SSL_CID_ENABLED* = 1 + MBEDTLS_SSL_ETM_DISABLED* = 0 + MBEDTLS_SSL_ETM_ENABLED* = 1 + MBEDTLS_SSL_COMPRESS_NULL* = 0 + MBEDTLS_SSL_VERIFY_NONE* = 0 + MBEDTLS_SSL_VERIFY_OPTIONAL* = 1 + MBEDTLS_SSL_VERIFY_REQUIRED* = 2 + MBEDTLS_SSL_VERIFY_UNSET* = 3 + MBEDTLS_SSL_LEGACY_RENEGOTIATION* = 0 + MBEDTLS_SSL_SECURE_RENEGOTIATION* = 1 + MBEDTLS_SSL_RENEGOTIATION_DISABLED* = 0 + MBEDTLS_SSL_RENEGOTIATION_ENABLED* = 1 + MBEDTLS_SSL_ANTI_REPLAY_DISABLED* = 0 + MBEDTLS_SSL_ANTI_REPLAY_ENABLED* = 1 + MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED* = -1 + MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT* = 16 + MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION* = 0 + MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION* = 1 + MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE* = 2 + MBEDTLS_SSL_TRUNC_HMAC_DISABLED* = 0 + MBEDTLS_SSL_TRUNC_HMAC_ENABLED* = 1 + MBEDTLS_SSL_TRUNCATED_HMAC_LEN* = 10 + MBEDTLS_SSL_SESSION_TICKETS_DISABLED* = 0 + MBEDTLS_SSL_SESSION_TICKETS_ENABLED* = 1 + MBEDTLS_SSL_PRESET_DEFAULT* = 0 + MBEDTLS_SSL_PRESET_SUITEB* = 2 + MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED* = 1 + MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED* = 0 + MBEDTLS_SSL_EARLY_DATA_DISABLED* = 0 + MBEDTLS_SSL_EARLY_DATA_ENABLED* = 1 + MBEDTLS_SSL_DTLS_SRTP_MKI_UNSUPPORTED* = 0 + MBEDTLS_SSL_DTLS_SRTP_MKI_SUPPORTED* = 1 + MBEDTLS_SSL_SRV_CIPHERSUITE_ORDER_CLIENT* = 1 + MBEDTLS_SSL_SRV_CIPHERSUITE_ORDER_SERVER* = 0 + MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN* = 1000 + MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX* = 60000 + MBEDTLS_SSL_IN_CONTENT_LEN* = 16384 + MBEDTLS_SSL_OUT_CONTENT_LEN* = 16384 + MBEDTLS_SSL_DTLS_MAX_BUFFERING* = 32768 + MBEDTLS_SSL_CID_IN_LEN_MAX* = 32 + MBEDTLS_SSL_CID_OUT_LEN_MAX* = 32 + MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY* = 16 + MBEDTLS_SSL_VERIFY_DATA_MAX_LEN* = 12 + MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO* = 0x000000FF + MBEDTLS_SSL_HASH_NONE* = 0 + MBEDTLS_SSL_HASH_MD5* = 1 + MBEDTLS_SSL_HASH_SHA1* = 2 + MBEDTLS_SSL_HASH_SHA224* = 3 + MBEDTLS_SSL_HASH_SHA256* = 4 + MBEDTLS_SSL_HASH_SHA384* = 5 + MBEDTLS_SSL_HASH_SHA512* = 6 + MBEDTLS_SSL_SIG_ANON* = 0 + MBEDTLS_SSL_SIG_RSA* = 1 + MBEDTLS_SSL_SIG_ECDSA* = 3 + MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA256* = 0x00000401 + MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA384* = 0x00000501 + MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA512* = 0x00000601 + MBEDTLS_TLS1_3_SIG_ECDSA_SECP256R1_SHA256* = 0x00000403 + MBEDTLS_TLS1_3_SIG_ECDSA_SECP384R1_SHA384* = 0x00000503 + MBEDTLS_TLS1_3_SIG_ECDSA_SECP521R1_SHA512* = 0x00000603 + MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA256* = 0x00000804 + MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA384* = 0x00000805 + MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA512* = 0x00000806 + MBEDTLS_TLS1_3_SIG_ED25519* = 0x00000807 + MBEDTLS_TLS1_3_SIG_ED448* = 0x00000808 + MBEDTLS_TLS1_3_SIG_RSA_PSS_PSS_SHA256* = 0x00000809 + MBEDTLS_TLS1_3_SIG_RSA_PSS_PSS_SHA384* = 0x0000080A + MBEDTLS_TLS1_3_SIG_RSA_PSS_PSS_SHA512* = 0x0000080B + MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA1* = 0x00000201 + MBEDTLS_TLS1_3_SIG_ECDSA_SHA1* = 0x00000203 + MBEDTLS_TLS1_3_SIG_NONE* = 0x00000000 + MBEDTLS_SSL_CERT_TYPE_RSA_SIGN* = 1 + MBEDTLS_SSL_CERT_TYPE_ECDSA_SIGN* = 64 + MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC* = 20 + MBEDTLS_SSL_MSG_ALERT* = 21 + MBEDTLS_SSL_MSG_HANDSHAKE* = 22 + MBEDTLS_SSL_MSG_APPLICATION_DATA* = 23 + MBEDTLS_SSL_MSG_CID* = 25 + MBEDTLS_SSL_ALERT_LEVEL_WARNING* = 1 + MBEDTLS_SSL_ALERT_LEVEL_FATAL* = 2 + MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY* = 0 + MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE* = 10 + MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC* = 20 + MBEDTLS_SSL_ALERT_MSG_DECRYPTION_FAILED* = 21 + MBEDTLS_SSL_ALERT_MSG_RECORD_OVERFLOW* = 22 + MBEDTLS_SSL_ALERT_MSG_DECOMPRESSION_FAILURE* = 30 + MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE* = 40 + MBEDTLS_SSL_ALERT_MSG_NO_CERT* = 41 + MBEDTLS_SSL_ALERT_MSG_BAD_CERT* = 42 + MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT* = 43 + MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED* = 44 + MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED* = 45 + MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN* = 46 + MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER* = 47 + MBEDTLS_SSL_ALERT_MSG_UNKNOWN_CA* = 48 + MBEDTLS_SSL_ALERT_MSG_ACCESS_DENIED* = 49 + MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR* = 50 + MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR* = 51 + MBEDTLS_SSL_ALERT_MSG_EXPORT_RESTRICTION* = 60 + MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION* = 70 + MBEDTLS_SSL_ALERT_MSG_INSUFFICIENT_SECURITY* = 71 + MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR* = 80 + MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK* = 86 + MBEDTLS_SSL_ALERT_MSG_USER_CANCELED* = 90 + MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION* = 100 + MBEDTLS_SSL_ALERT_MSG_MISSING_EXTENSION* = 109 + MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT* = 110 + MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME* = 112 + MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY* = 115 + MBEDTLS_SSL_ALERT_MSG_CERT_REQUIRED* = 116 + MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL* = 120 + MBEDTLS_SSL_HS_HELLO_REQUEST* = 0 + MBEDTLS_SSL_HS_CLIENT_HELLO* = 1 + MBEDTLS_SSL_HS_SERVER_HELLO* = 2 + MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST* = 3 + MBEDTLS_SSL_HS_NEW_SESSION_TICKET* = 4 + MBEDTLS_SSL_HS_END_OF_EARLY_DATA* = 5 + MBEDTLS_SSL_HS_ENCRYPTED_EXTENSIONS* = 8 + MBEDTLS_SSL_HS_CERTIFICATE* = 11 + MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE* = 12 + MBEDTLS_SSL_HS_CERTIFICATE_REQUEST* = 13 + MBEDTLS_SSL_HS_SERVER_HELLO_DONE* = 14 + MBEDTLS_SSL_HS_CERTIFICATE_VERIFY* = 15 + MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE* = 16 + MBEDTLS_SSL_HS_FINISHED* = 20 + MBEDTLS_SSL_HS_MESSAGE_HASH* = 254 + MBEDTLS_TLS_EXT_SERVERNAME* = 0 + MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME* = 0 + MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH* = 1 + MBEDTLS_TLS_EXT_TRUNCATED_HMAC* = 4 + MBEDTLS_TLS_EXT_STATUS_REQUEST* = 5 + MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES* = 10 + MBEDTLS_TLS_EXT_SUPPORTED_GROUPS* = 10 + MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS* = 11 + MBEDTLS_TLS_EXT_SIG_ALG* = 13 + MBEDTLS_TLS_EXT_USE_SRTP* = 14 + MBEDTLS_TLS_EXT_HEARTBEAT* = 15 + MBEDTLS_TLS_EXT_ALPN* = 16 + MBEDTLS_TLS_EXT_SCT* = 18 + MBEDTLS_TLS_EXT_CLI_CERT_TYPE* = 19 + MBEDTLS_TLS_EXT_SERV_CERT_TYPE* = 20 + MBEDTLS_TLS_EXT_PADDING* = 21 + MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC* = 22 + MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET* = 0x00000017 + MBEDTLS_TLS_EXT_RECORD_SIZE_LIMIT* = 28 + MBEDTLS_TLS_EXT_SESSION_TICKET* = 35 + MBEDTLS_TLS_EXT_PRE_SHARED_KEY* = 41 + MBEDTLS_TLS_EXT_EARLY_DATA* = 42 + MBEDTLS_TLS_EXT_SUPPORTED_VERSIONS* = 43 + MBEDTLS_TLS_EXT_COOKIE* = 44 + MBEDTLS_TLS_EXT_PSK_KEY_EXCHANGE_MODES* = 45 + MBEDTLS_TLS_EXT_CERT_AUTH* = 47 + MBEDTLS_TLS_EXT_OID_FILTERS* = 48 + MBEDTLS_TLS_EXT_POST_HANDSHAKE_AUTH* = 49 + MBEDTLS_TLS_EXT_SIG_ALG_CERT* = 50 + MBEDTLS_TLS_EXT_KEY_SHARE* = 51 + MBEDTLS_TLS_EXT_CID* = 54 + MBEDTLS_TLS_EXT_ECJPAKE_KKPP* = 256 + MBEDTLS_TLS_EXT_RENEGOTIATION_INFO* = 0x0000FF01 + MBEDTLS_PSK_MAX_LEN* = 32 + MBEDTLS_SSL_SEQUENCE_NUMBER_LEN* = 8 + MBEDTLS_SSL_HELLO_REQUEST* = (0).mbedtls_ssl_states + MBEDTLS_SSL_CLIENT_HELLO* = (MBEDTLS_SSL_HELLO_REQUEST + 1).mbedtls_ssl_states + MBEDTLS_SSL_SERVER_HELLO* = (MBEDTLS_SSL_CLIENT_HELLO + 1).mbedtls_ssl_states + MBEDTLS_SSL_SERVER_CERTIFICATE* = (MBEDTLS_SSL_SERVER_HELLO + 1).mbedtls_ssl_states + MBEDTLS_SSL_SERVER_KEY_EXCHANGE* = (MBEDTLS_SSL_SERVER_CERTIFICATE + 1).mbedtls_ssl_states + MBEDTLS_SSL_CERTIFICATE_REQUEST* = (MBEDTLS_SSL_SERVER_KEY_EXCHANGE + 1).mbedtls_ssl_states + MBEDTLS_SSL_SERVER_HELLO_DONE* = (MBEDTLS_SSL_CERTIFICATE_REQUEST + 1).mbedtls_ssl_states + MBEDTLS_SSL_CLIENT_CERTIFICATE* = (MBEDTLS_SSL_SERVER_HELLO_DONE + 1).mbedtls_ssl_states + MBEDTLS_SSL_CLIENT_KEY_EXCHANGE* = (MBEDTLS_SSL_CLIENT_CERTIFICATE + 1).mbedtls_ssl_states + MBEDTLS_SSL_CERTIFICATE_VERIFY* = (MBEDTLS_SSL_CLIENT_KEY_EXCHANGE + 1).mbedtls_ssl_states + MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC* = (MBEDTLS_SSL_CERTIFICATE_VERIFY + 1).mbedtls_ssl_states + MBEDTLS_SSL_CLIENT_FINISHED* = (MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC + 1).mbedtls_ssl_states + MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC* = (MBEDTLS_SSL_CLIENT_FINISHED + 1).mbedtls_ssl_states + MBEDTLS_SSL_SERVER_FINISHED* = (MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC + 1).mbedtls_ssl_states + MBEDTLS_SSL_FLUSH_BUFFERS* = (MBEDTLS_SSL_SERVER_FINISHED + 1).mbedtls_ssl_states + MBEDTLS_SSL_HANDSHAKE_WRAPUP* = (MBEDTLS_SSL_FLUSH_BUFFERS + 1).mbedtls_ssl_states + MBEDTLS_SSL_NEW_SESSION_TICKET* = (MBEDTLS_SSL_HANDSHAKE_WRAPUP + 1).mbedtls_ssl_states + MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT* = ( + MBEDTLS_SSL_NEW_SESSION_TICKET + 1).mbedtls_ssl_states + MBEDTLS_SSL_HELLO_RETRY_REQUEST* = (MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT + + 1).mbedtls_ssl_states + MBEDTLS_SSL_ENCRYPTED_EXTENSIONS* = (MBEDTLS_SSL_HELLO_RETRY_REQUEST + 1).mbedtls_ssl_states + MBEDTLS_SSL_END_OF_EARLY_DATA* = (MBEDTLS_SSL_ENCRYPTED_EXTENSIONS + 1).mbedtls_ssl_states + MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY* = (MBEDTLS_SSL_END_OF_EARLY_DATA + 1).mbedtls_ssl_states + MBEDTLS_SSL_CLIENT_CCS_AFTER_SERVER_FINISHED* = ( + MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY + 1).mbedtls_ssl_states + MBEDTLS_SSL_CLIENT_CCS_BEFORE_2ND_CLIENT_HELLO* = ( + MBEDTLS_SSL_CLIENT_CCS_AFTER_SERVER_FINISHED + 1).mbedtls_ssl_states + MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO* = ( + MBEDTLS_SSL_CLIENT_CCS_BEFORE_2ND_CLIENT_HELLO + 1).mbedtls_ssl_states + MBEDTLS_SSL_CLIENT_CCS_AFTER_CLIENT_HELLO* = ( + MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO + 1).mbedtls_ssl_states + MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST* = ( + MBEDTLS_SSL_CLIENT_CCS_AFTER_CLIENT_HELLO + 1).mbedtls_ssl_states + MBEDTLS_SSL_HANDSHAKE_OVER* = (MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST + + 1).mbedtls_ssl_states + MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET* = (MBEDTLS_SSL_HANDSHAKE_OVER + 1).mbedtls_ssl_states + MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH* = ( + MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET + 1).mbedtls_ssl_states + MBEDTLS_SSL_VERSION_UNKNOWN* = (0).mbedtls_ssl_protocol_version + MBEDTLS_SSL_VERSION_TLS1_2* = (0x00000303).mbedtls_ssl_protocol_version + MBEDTLS_SSL_VERSION_TLS1_3* = (0x00000304).mbedtls_ssl_protocol_version + MBEDTLS_SSL_TLS_PRF_NONE* = (0).mbedtls_tls_prf_types + MBEDTLS_SSL_TLS_PRF_SHA384* = (MBEDTLS_SSL_TLS_PRF_NONE + 1).mbedtls_tls_prf_types + MBEDTLS_SSL_TLS_PRF_SHA256* = (MBEDTLS_SSL_TLS_PRF_SHA384 + 1).mbedtls_tls_prf_types + MBEDTLS_SSL_HKDF_EXPAND_SHA384* = (MBEDTLS_SSL_TLS_PRF_SHA256 + 1).mbedtls_tls_prf_types + MBEDTLS_SSL_HKDF_EXPAND_SHA256* = (MBEDTLS_SSL_HKDF_EXPAND_SHA384 + 1).mbedtls_tls_prf_types + MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET* = (0).mbedtls_ssl_key_export_type + MBEDTLS_SSL_UNEXPECTED_CID_IGNORE* = 0 + MBEDTLS_SSL_UNEXPECTED_CID_FAIL* = 1 +type + mbedtls_ssl_premaster_secret* {.union, bycopy.} = object + u_pms_rsa*: array[48, byte] + u_pms_dhm*: array[1024, byte] + u_pms_ecdh*: array[(typeof(521)((521 + typeof(521)(7)) / typeof(521)(8))), + byte] + u_pms_psk*: array[4 + typeof(4)(2 * typeof(4)(32)), byte] + u_pms_dhe_psk*: array[4 + typeof(4)(1024) + typeof(4)(32), byte] + uu_pms_rsa_psk*: array[52 + typeof(52)(32), byte] + uu_pms_ecdhe_psk*: array[4 + + typeof(4)((typeof(4)((521 + typeof(4)(7)) / typeof(4)(8)))) + + typeof(4)(32), byte] + + mbedtls_ssl_send_t* = proc (ctx: pointer; buf: ptr byte; len: uint): cint {. + cdecl.} + mbedtls_ssl_recv_t* = proc (ctx: pointer; buf: ptr byte; len: uint): cint {. + cdecl.} + mbedtls_ssl_recv_timeout_t* = proc (ctx: pointer; buf: ptr byte; len: uint; + timeout: uint32): cint {.cdecl.} + mbedtls_ssl_set_timer_t* = proc (ctx: pointer; int_ms: uint32; fin_ms: uint32) {. + cdecl.} + mbedtls_ssl_get_timer_t* = proc (ctx: pointer): cint {.cdecl.} + mbedtls_ssl_session* {.bycopy.} = object + private_mfl_code*: byte + private_exported*: byte + private_tls_version*: mbedtls_ssl_protocol_version + private_start*: mbedtls_time_t + private_ciphersuite*: cint + private_id_len*: uint + private_id*: array[32, byte] + private_master*: array[48, byte] + private_peer_cert*: ptr mbedtls_x509_crt + private_verify_result*: uint32 + private_ticket*: ptr byte + private_ticket_len*: uint + private_ticket_lifetime*: uint32 + private_encrypt_then_mac*: cint + + mbedtls_ssl_context* {.bycopy.} = object + private_conf*: ptr mbedtls_ssl_config + private_state*: cint + private_renego_status*: cint + private_renego_records_seen*: cint + private_tls_version*: mbedtls_ssl_protocol_version + private_badmac_seen*: cuint + private_f_vrfy*: proc (a1: pointer; a2: ptr mbedtls_x509_crt; a3: cint; + a4: ptr uint32): cint {.cdecl.} + private_p_vrfy*: pointer + private_f_send*: ptr mbedtls_ssl_send_t + private_f_recv*: ptr mbedtls_ssl_recv_t + private_f_recv_timeout*: ptr mbedtls_ssl_recv_timeout_t + private_p_bio*: pointer + private_session_in*: ptr mbedtls_ssl_session + private_session_out*: ptr mbedtls_ssl_session + private_session*: ptr mbedtls_ssl_session + private_session_negotiate*: ptr mbedtls_ssl_session + private_handshake*: ptr mbedtls_ssl_handshake_params + private_transform_in*: ptr mbedtls_ssl_transform + private_transform_out*: ptr mbedtls_ssl_transform + private_transform*: ptr mbedtls_ssl_transform + private_transform_negotiate*: ptr mbedtls_ssl_transform + private_p_timer*: pointer + private_f_set_timer*: ptr mbedtls_ssl_set_timer_t + private_f_get_timer*: ptr mbedtls_ssl_get_timer_t + private_in_buf*: ptr byte + private_in_ctr*: ptr byte + private_in_hdr*: ptr byte + private_in_cid*: ptr byte + private_in_len*: ptr byte + private_in_iv*: ptr byte + private_in_msg*: ptr byte + private_in_offt*: ptr byte + private_in_msgtype*: cint + private_in_msglen*: uint + private_in_left*: uint + private_in_epoch*: uint16 + private_next_record_offset*: uint + private_in_window_top*: uint64 + private_in_window*: uint64 + private_in_hslen*: uint + private_nb_zero*: cint + private_keep_current_message*: cint + private_send_alert*: byte + private_alert_type*: byte + private_alert_reason*: cint + private_disable_datagram_packing*: uint8 + private_out_buf*: ptr byte + private_out_ctr*: ptr byte + private_out_hdr*: ptr byte + private_out_cid*: ptr byte + private_out_len*: ptr byte + private_out_iv*: ptr byte + private_out_msg*: ptr byte + private_out_msgtype*: cint + private_out_msglen*: uint + private_out_left*: uint + private_cur_out_ctr*: array[8, byte] + private_mtu*: uint16 + private_hostname*: cstring + private_alpn_chosen*: cstring + private_cli_id*: ptr byte + private_cli_id_len*: uint + private_secure_renegotiation*: cint + private_verify_data_len*: uint + private_own_verify_data*: array[12, cchar] + private_peer_verify_data*: array[12, cchar] + private_own_cid*: array[32, byte] + private_own_cid_len*: uint8 + private_negotiate_cid*: uint8 + private_f_export_keys*: ptr mbedtls_ssl_export_keys_t + private_p_export_keys*: pointer + private_user_data*: mbedtls_ssl_user_data_t + + mbedtls_ssl_config* {.bycopy.} = object + private_max_tls_version*: mbedtls_ssl_protocol_version + private_min_tls_version*: mbedtls_ssl_protocol_version + private_endpoint*: uint8 + private_transport*: uint8 + private_authmode*: uint8 + private_allow_legacy_renegotiation*: uint8 + private_mfl_code*: uint8 + private_encrypt_then_mac*: uint8 + private_extended_ms*: uint8 + private_anti_replay*: uint8 + private_disable_renegotiation*: uint8 + private_session_tickets*: uint8 + private_cert_req_ca_list*: uint8 + private_respect_cli_pref*: uint8 + private_ignore_unexpected_cid*: uint8 + private_ciphersuite_list*: ptr cint + private_f_dbg*: proc (a1: pointer; a2: cint; a3: cstring; a4: cint; + a5: cstring) {.cdecl.} + private_p_dbg*: pointer + private_f_rng*: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.} + private_p_rng*: pointer + private_f_get_cache*: ptr mbedtls_ssl_cache_get_t + private_f_set_cache*: ptr mbedtls_ssl_cache_set_t + private_p_cache*: pointer + private_f_sni*: proc (a1: pointer; a2: ptr mbedtls_ssl_context; + a3: ptr byte; a4: uint): cint {.cdecl.} + private_p_sni*: pointer + private_f_vrfy*: proc (a1: pointer; a2: ptr mbedtls_x509_crt; a3: cint; + a4: ptr uint32): cint {.cdecl.} + private_p_vrfy*: pointer + private_f_psk*: proc (a1: pointer; a2: ptr mbedtls_ssl_context; + a3: ptr byte; a4: uint): cint {.cdecl.} + private_p_psk*: pointer + private_f_cookie_write*: proc (a1: pointer; a2: ptr ptr byte; + a3: ptr byte; a4: ptr byte; a5: uint): cint {. + cdecl.} + private_f_cookie_check*: proc (a1: pointer; a2: ptr byte; a3: uint; + a4: ptr byte; a5: uint): cint {.cdecl.} + private_p_cookie*: pointer + private_f_ticket_write*: proc (a1: pointer; a2: ptr mbedtls_ssl_session; + a3: ptr byte; a4: ptr byte; a5: ptr uint; + a6: ptr uint32): cint {.cdecl.} + private_f_ticket_parse*: proc (a1: pointer; a2: ptr mbedtls_ssl_session; + a3: ptr byte; a4: uint): cint {.cdecl.} + private_p_ticket*: pointer + private_cid_len*: uint + private_cert_profile*: ptr mbedtls_x509_crt_profile + private_key_cert*: ptr mbedtls_ssl_key_cert + private_ca_chain*: ptr mbedtls_x509_crt + private_ca_crl*: ptr mbedtls_x509_crl + private_sig_hashes*: ptr cint + private_sig_algs*: ptr uint16 + private_curve_list*: ptr mbedtls_ecp_group_id + private_group_list*: ptr uint16 + private_dhm_P*: mbedtls_mpi + private_dhm_G*: mbedtls_mpi + private_psk*: ptr byte + private_psk_len*: uint + private_psk_identity*: ptr byte + private_psk_identity_len*: uint + private_alpn_list*: ptr cstring + private_read_timeout*: uint32 + private_hs_timeout_min*: uint32 + private_hs_timeout_max*: uint32 + private_renego_max_records*: cint + private_renego_period*: array[8, byte] + private_badmac_limit*: cuint + private_dhm_min_bitlen*: cuint + private_user_data*: mbedtls_ssl_user_data_t + private_f_cert_cb*: mbedtls_ssl_hs_cb_t + private_dn_hints*: ptr mbedtls_x509_crt + + mbedtls_ssl_transform* {.incompleteStruct.} = object + mbedtls_ssl_handshake_params* {.incompleteStruct.} = object + mbedtls_ssl_sig_hash_set_t* {.incompleteStruct.} = object + mbedtls_ssl_key_cert* {.incompleteStruct.} = object + mbedtls_ssl_flight_item* {.incompleteStruct.} = object + mbedtls_ssl_cache_get_t* = proc (data: pointer; session_id: ptr byte; + session_id_len: uint; + session: ptr mbedtls_ssl_session): cint {. + cdecl.} + mbedtls_ssl_cache_set_t* = proc (data: pointer; session_id: ptr byte; + session_id_len: uint; + session: ptr mbedtls_ssl_session): cint {. + cdecl.} + mbedtls_ssl_tls13_application_secrets* {.bycopy.} = object + client_application_traffic_secret_N*: array[64, byte] + server_application_traffic_secret_N*: array[64, byte] + exporter_master_secret*: array[64, byte] + resumption_master_secret*: array[64, byte] + + mbedtls_ssl_export_keys_t* = proc (p_expkey: pointer; + `type`: mbedtls_ssl_key_export_type; + secret: ptr byte; secret_len: uint; + client_random: array[32, byte]; + server_random: array[32, byte]; + tls_prf_type: mbedtls_tls_prf_types) {. + cdecl.} + mbedtls_ssl_hs_cb_t* = proc (ssl: ptr mbedtls_ssl_context): cint {.cdecl.} + mbedtls_ssl_user_data_t* {.union, bycopy.} = object + n*: ptr uint + p*: pointer + + mbedtls_ssl_ticket_write_t* = proc (p_ticket: pointer; + session: ptr mbedtls_ssl_session; + start: ptr byte; `end`: ptr byte; + tlen: ptr uint; lifetime: ptr uint32): cint {. + cdecl.} + mbedtls_ssl_ticket_parse_t* = proc (p_ticket: pointer; + session: ptr mbedtls_ssl_session; + buf: ptr byte; len: uint): cint {.cdecl.} + mbedtls_ssl_cookie_write_t* = proc (ctx: pointer; p: ptr ptr byte; + `end`: ptr byte; info: ptr byte; + ilen: uint): cint {.cdecl.} + mbedtls_ssl_cookie_check_t* = proc (ctx: pointer; cookie: ptr byte; + clen: uint; info: ptr byte; ilen: uint): cint {. + cdecl.} +proc mbedtls_ssl_get_ciphersuite_name*(ciphersuite_id: cint): cstring {.importc, + cdecl.} +proc mbedtls_ssl_get_ciphersuite_id*(ciphersuite_name: cstring): cint {.importc, + cdecl.} +proc mbedtls_ssl_init*(ssl: ptr mbedtls_ssl_context) {.importc, cdecl.} +proc mbedtls_ssl_setup*(ssl: ptr mbedtls_ssl_context; + conf: ptr mbedtls_ssl_config): cint {.importc, cdecl.} +proc mbedtls_ssl_session_reset*(ssl: ptr mbedtls_ssl_context): cint {.importc, + cdecl.} +proc mbedtls_ssl_conf_endpoint*(conf: ptr mbedtls_ssl_config; endpoint: cint) {. + importc, cdecl.} +proc mbedtls_ssl_conf_transport*(conf: ptr mbedtls_ssl_config; transport: cint) {. + importc, cdecl.} +proc mbedtls_ssl_conf_authmode*(conf: ptr mbedtls_ssl_config; authmode: cint) {. + importc, cdecl.} +proc mbedtls_ssl_conf_verify*(conf: ptr mbedtls_ssl_config; f_vrfy: proc ( + a1: pointer; a2: ptr mbedtls_x509_crt; a3: cint; a4: ptr uint32): cint {. + cdecl.}; p_vrfy: pointer) {.importc, cdecl.} +proc mbedtls_ssl_conf_rng*(conf: ptr mbedtls_ssl_config; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer) {. + importc, cdecl.} +proc mbedtls_ssl_conf_dbg*(conf: ptr mbedtls_ssl_config; f_dbg: proc ( + a1: pointer; a2: cint; a3: cstring; a4: cint; a5: cstring) {.cdecl.}; + p_dbg: pointer) {.importc, cdecl.} +proc mbedtls_ssl_set_bio*(ssl: ptr mbedtls_ssl_context; p_bio: pointer; + f_send: ptr mbedtls_ssl_send_t; + f_recv: ptr mbedtls_ssl_recv_t; + f_recv_timeout: ptr mbedtls_ssl_recv_timeout_t) {. + importc, cdecl.} +proc mbedtls_ssl_set_cid*(ssl: ptr mbedtls_ssl_context; enable: cint; + own_cid: ptr byte; own_cid_len: uint): cint {. + importc, cdecl.} +proc mbedtls_ssl_get_own_cid*(ssl: ptr mbedtls_ssl_context; enabled: ptr cint; + own_cid: array[32, byte]; own_cid_len: ptr uint): cint {. + importc, cdecl.} +proc mbedtls_ssl_get_peer_cid*(ssl: ptr mbedtls_ssl_context; enabled: ptr cint; + peer_cid: array[32, byte]; + peer_cid_len: ptr uint): cint {.importc, cdecl.} +proc mbedtls_ssl_set_mtu*(ssl: ptr mbedtls_ssl_context; mtu: uint16) {.importc, + cdecl.} +proc mbedtls_ssl_set_verify*(ssl: ptr mbedtls_ssl_context; f_vrfy: proc ( + a1: pointer; a2: ptr mbedtls_x509_crt; a3: cint; a4: ptr uint32): cint {. + cdecl.}; p_vrfy: pointer) {.importc, cdecl.} +proc mbedtls_ssl_conf_read_timeout*(conf: ptr mbedtls_ssl_config; + timeout: uint32) {.importc, cdecl.} +proc mbedtls_ssl_check_record*(ssl: ptr mbedtls_ssl_context; buf: ptr byte; + buflen: uint): cint {.importc, cdecl.} +proc mbedtls_ssl_set_timer_cb*(ssl: ptr mbedtls_ssl_context; p_timer: pointer; + f_set_timer: ptr mbedtls_ssl_set_timer_t; + f_get_timer: ptr mbedtls_ssl_get_timer_t) {. + importc, cdecl.} +proc mbedtls_ssl_conf_session_tickets_cb*(conf: ptr mbedtls_ssl_config; + f_ticket_write: ptr mbedtls_ssl_ticket_write_t; + f_ticket_parse: ptr mbedtls_ssl_ticket_parse_t; p_ticket: pointer) {. + importc, cdecl.} +proc mbedtls_ssl_set_export_keys_cb*(ssl: ptr mbedtls_ssl_context; f_export_keys: ptr mbedtls_ssl_export_keys_t; + p_export_keys: pointer) {.importc, cdecl.} +proc mbedtls_ssl_conf_dtls_cookies*(conf: ptr mbedtls_ssl_config; f_cookie_write: ptr mbedtls_ssl_cookie_write_t; + f_cookie_check: ptr mbedtls_ssl_cookie_check_t; p_cookie: pointer) {. + importc, cdecl.} +proc mbedtls_ssl_set_client_transport_id*(ssl: ptr mbedtls_ssl_context; + info: ptr byte; ilen: uint): cint {.importc, cdecl.} +proc mbedtls_ssl_conf_dtls_anti_replay*(conf: ptr mbedtls_ssl_config; + mode: cchar) {.importc, cdecl.} +proc mbedtls_ssl_conf_dtls_badmac_limit*(conf: ptr mbedtls_ssl_config; + limit: cuint) {.importc, cdecl.} +proc mbedtls_ssl_set_datagram_packing*(ssl: ptr mbedtls_ssl_context; + allow_packing: cuint) {.importc, cdecl.} +proc mbedtls_ssl_conf_handshake_timeout*(conf: ptr mbedtls_ssl_config; + min: uint32; max: uint32) {.importc, cdecl.} +proc mbedtls_ssl_conf_session_cache*(conf: ptr mbedtls_ssl_config; + p_cache: pointer; + f_get_cache: ptr mbedtls_ssl_cache_get_t; + f_set_cache: ptr mbedtls_ssl_cache_set_t) {. + importc, cdecl.} +proc mbedtls_ssl_set_session*(ssl: ptr mbedtls_ssl_context; + session: ptr mbedtls_ssl_session): cint {.importc, + cdecl.} +proc mbedtls_ssl_session_load*(session: ptr mbedtls_ssl_session; + buf: ptr byte; len: uint): cint {.importc, + cdecl.} +proc mbedtls_ssl_session_save*(session: ptr mbedtls_ssl_session; + buf: ptr byte; buf_len: uint; olen: ptr uint): cint {. + importc, cdecl.} +proc mbedtls_ssl_conf_ciphersuites*(conf: ptr mbedtls_ssl_config; + ciphersuites: ptr cint) {.importc, cdecl.} +proc mbedtls_ssl_conf_cid*(conf: ptr mbedtls_ssl_config; len: uint; + ignore_other_cids: cint): cint {.importc, cdecl.} +proc mbedtls_ssl_conf_cert_profile*(conf: ptr mbedtls_ssl_config; + profile: ptr mbedtls_x509_crt_profile) {. + importc, cdecl.} +proc mbedtls_ssl_conf_ca_chain*(conf: ptr mbedtls_ssl_config; + ca_chain: ptr mbedtls_x509_crt; + ca_crl: ptr mbedtls_x509_crl) {.importc, cdecl.} +proc mbedtls_ssl_conf_own_cert*(conf: ptr mbedtls_ssl_config; + own_cert: ptr mbedtls_x509_crt; + pk_key: ptr mbedtls_pk_context): cint {.importc, + cdecl.} +proc mbedtls_ssl_conf_psk*(conf: ptr mbedtls_ssl_config; psk: ptr byte; + psk_len: uint; psk_identity: ptr byte; + psk_identity_len: uint): cint {.importc, cdecl.} +proc mbedtls_ssl_set_hs_psk*(ssl: ptr mbedtls_ssl_context; psk: ptr byte; + psk_len: uint): cint {.importc, cdecl.} +proc mbedtls_ssl_conf_psk_cb*(conf: ptr mbedtls_ssl_config; f_psk: proc ( + a1: pointer; a2: ptr mbedtls_ssl_context; a3: ptr byte; a4: uint): cint {. + cdecl.}; p_psk: pointer) {.importc, cdecl.} +proc mbedtls_ssl_conf_dh_param_bin*(conf: ptr mbedtls_ssl_config; + dhm_P: ptr byte; P_len: uint; + dhm_G: ptr byte; G_len: uint): cint {. + importc, cdecl.} +proc mbedtls_ssl_conf_dh_param_ctx*(conf: ptr mbedtls_ssl_config; + dhm_ctx: ptr mbedtls_dhm_context): cint {. + importc, cdecl.} +proc mbedtls_ssl_conf_dhm_min_bitlen*(conf: ptr mbedtls_ssl_config; + bitlen: cuint) {.importc, cdecl.} +proc mbedtls_ssl_conf_curves*(conf: ptr mbedtls_ssl_config; + curves: ptr mbedtls_ecp_group_id) {.importc, cdecl.} +proc mbedtls_ssl_conf_groups*(conf: ptr mbedtls_ssl_config; groups: ptr uint16) {. + importc, cdecl.} +proc mbedtls_ssl_conf_sig_hashes*(conf: ptr mbedtls_ssl_config; hashes: ptr cint) {. + importc, cdecl.} +proc mbedtls_ssl_conf_sig_algs*(conf: ptr mbedtls_ssl_config; + sig_algs: ptr uint16) {.importc, cdecl.} +proc mbedtls_ssl_set_hostname*(ssl: ptr mbedtls_ssl_context; hostname: cstring): cint {. + importc, cdecl.} +proc mbedtls_ssl_get_hs_sni*(ssl: ptr mbedtls_ssl_context; name_len: ptr uint): ptr byte {. + importc, cdecl.} +proc mbedtls_ssl_set_hs_own_cert*(ssl: ptr mbedtls_ssl_context; + own_cert: ptr mbedtls_x509_crt; + pk_key: ptr mbedtls_pk_context): cint {. + importc, cdecl.} +proc mbedtls_ssl_set_hs_ca_chain*(ssl: ptr mbedtls_ssl_context; + ca_chain: ptr mbedtls_x509_crt; + ca_crl: ptr mbedtls_x509_crl) {.importc, cdecl.} +proc mbedtls_ssl_set_hs_dn_hints*(ssl: ptr mbedtls_ssl_context; + crt: ptr mbedtls_x509_crt) {.importc, cdecl.} +proc mbedtls_ssl_set_hs_authmode*(ssl: ptr mbedtls_ssl_context; authmode: cint) {. + importc, cdecl.} +proc mbedtls_ssl_conf_sni*(conf: ptr mbedtls_ssl_config; f_sni: proc ( + a1: pointer; a2: ptr mbedtls_ssl_context; a3: ptr byte; a4: uint): cint {. + cdecl.}; p_sni: pointer) {.importc, cdecl.} +proc mbedtls_ssl_conf_alpn_protocols*(conf: ptr mbedtls_ssl_config; + protos: ptr cstring): cint {.importc, + cdecl.} +proc mbedtls_ssl_get_alpn_protocol*(ssl: ptr mbedtls_ssl_context): cstring {. + importc, cdecl.} +proc mbedtls_ssl_conf_max_version*(conf: ptr mbedtls_ssl_config; major: cint; + minor: cint) {.importc, cdecl.} +proc mbedtls_ssl_conf_min_version*(conf: ptr mbedtls_ssl_config; major: cint; + minor: cint) {.importc, cdecl.} +proc mbedtls_ssl_conf_encrypt_then_mac*(conf: ptr mbedtls_ssl_config; etm: cchar) {. + importc, cdecl.} +proc mbedtls_ssl_conf_extended_master_secret*(conf: ptr mbedtls_ssl_config; + ems: cchar) {.importc, cdecl.} +proc mbedtls_ssl_conf_cert_req_ca_list*(conf: ptr mbedtls_ssl_config; + cert_req_ca_list: cchar) {.importc, + cdecl.} +proc mbedtls_ssl_conf_max_frag_len*(conf: ptr mbedtls_ssl_config; + mfl_code: byte): cint {.importc, cdecl.} +proc mbedtls_ssl_conf_preference_order*(conf: ptr mbedtls_ssl_config; + order: cint) {.importc, cdecl.} +proc mbedtls_ssl_conf_session_tickets*(conf: ptr mbedtls_ssl_config; + use_tickets: cint) {.importc, cdecl.} +proc mbedtls_ssl_conf_renegotiation*(conf: ptr mbedtls_ssl_config; + renegotiation: cint) {.importc, cdecl.} +proc mbedtls_ssl_conf_legacy_renegotiation*(conf: ptr mbedtls_ssl_config; + allow_legacy: cint) {.importc, cdecl.} +proc mbedtls_ssl_conf_renegotiation_enforced*(conf: ptr mbedtls_ssl_config; + max_records: cint) {.importc, cdecl.} +proc mbedtls_ssl_conf_renegotiation_period*(conf: ptr mbedtls_ssl_config; + period: array[8, byte]) {.importc, cdecl.} +proc mbedtls_ssl_check_pending*(ssl: ptr mbedtls_ssl_context): cint {.importc, + cdecl.} +proc mbedtls_ssl_get_bytes_avail*(ssl: ptr mbedtls_ssl_context): uint {.importc, + cdecl.} +proc mbedtls_ssl_get_verify_result*(ssl: ptr mbedtls_ssl_context): uint32 {. + importc, cdecl.} +proc mbedtls_ssl_get_ciphersuite_id_from_ssl*(ssl: ptr mbedtls_ssl_context): cint {. + importc, cdecl.} +proc mbedtls_ssl_get_ciphersuite*(ssl: ptr mbedtls_ssl_context): cstring {. + importc, cdecl.} +proc mbedtls_ssl_get_version*(ssl: ptr mbedtls_ssl_context): cstring {.importc, + cdecl.} +proc mbedtls_ssl_get_record_expansion*(ssl: ptr mbedtls_ssl_context): cint {. + importc, cdecl.} +proc mbedtls_ssl_get_max_out_record_payload*(ssl: ptr mbedtls_ssl_context): cint {. + importc, cdecl.} +proc mbedtls_ssl_get_max_in_record_payload*(ssl: ptr mbedtls_ssl_context): cint {. + importc, cdecl.} +proc mbedtls_ssl_get_peer_cert*(ssl: ptr mbedtls_ssl_context): ptr mbedtls_x509_crt {. + importc, cdecl.} +proc mbedtls_ssl_get_session*(ssl: ptr mbedtls_ssl_context; + session: ptr mbedtls_ssl_session): cint {.importc, + cdecl.} +proc mbedtls_ssl_handshake*(ssl: ptr mbedtls_ssl_context): cint {.importc, cdecl.} +proc mbedtls_ssl_handshake_step*(ssl: ptr mbedtls_ssl_context): cint {.importc, + cdecl.} +proc mbedtls_ssl_renegotiate*(ssl: ptr mbedtls_ssl_context): cint {.importc, + cdecl.} +proc mbedtls_ssl_read*(ssl: ptr mbedtls_ssl_context; buf: ptr byte; len: uint): cint {. + importc, cdecl.} +proc mbedtls_ssl_write*(ssl: ptr mbedtls_ssl_context; buf: ptr byte; len: uint): cint {. + importc, cdecl.} +proc mbedtls_ssl_send_alert_message*(ssl: ptr mbedtls_ssl_context; + level: byte; message: byte): cint {. + importc, cdecl.} +proc mbedtls_ssl_close_notify*(ssl: ptr mbedtls_ssl_context): cint {.importc, + cdecl.} +proc mbedtls_ssl_free*(ssl: ptr mbedtls_ssl_context) {.importc, cdecl.} +proc mbedtls_ssl_context_save*(ssl: ptr mbedtls_ssl_context; buf: ptr byte; + buf_len: uint; olen: ptr uint): cint {.importc, + cdecl.} +proc mbedtls_ssl_context_load*(ssl: ptr mbedtls_ssl_context; buf: ptr byte; + len: uint): cint {.importc, cdecl.} +proc mbedtls_ssl_config_init*(conf: ptr mbedtls_ssl_config) {.importc, cdecl.} +proc mbedtls_ssl_config_defaults*(conf: ptr mbedtls_ssl_config; endpoint: cint; + transport: cint; preset: cint): cint {. + importc, cdecl.} +proc mbedtls_ssl_config_free*(conf: ptr mbedtls_ssl_config) {.importc, cdecl.} +proc mbedtls_ssl_session_init*(session: ptr mbedtls_ssl_session) {.importc, + cdecl.} +proc mbedtls_ssl_session_free*(session: ptr mbedtls_ssl_session) {.importc, + cdecl.} +proc mbedtls_ssl_tls_prf*(prf: mbedtls_tls_prf_types; secret: ptr byte; + slen: uint; label: cstring; random: ptr byte; + rlen: uint; dstbuf: ptr byte; dlen: uint): cint {. + importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/ssl_cache.nim b/webrtc/mbedtls/ssl_cache.nim new file mode 100644 index 0000000..32d1dfe --- /dev/null +++ b/webrtc/mbedtls/ssl_cache.nim @@ -0,0 +1,90 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "ssl" +import "platform_util" +import "platform_time" +import "bignum" +import "ecp" +import "ssl_ciphersuites" +import "pk" +import "md" +import "rsa" +import "ecdsa" +import "cipher" +import "x509_crt" +import "x509" +import "asn1" +import "x509_crl" +import "dhm" +import "ecdh" +import "md5" +import "ripemd160" +import "sha1" +import "sha256" +import "sha512" +import "cmac" +import "gcm" +import "ccm" +import "chachapoly" +import "poly1305" +import "chacha20" +import "ecjpake" +{.compile: "./mbedtls/library/ssl_cache.c".} +# Generated @ 2023-05-11T11:19:14+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ssl_cache.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT* = 86400 + MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES* = 50 +type + mbedtls_ssl_cache_context* {.bycopy.} = object + private_chain*: ptr mbedtls_ssl_cache_entry + private_timeout*: cint + private_max_entries*: cint + + mbedtls_ssl_cache_entry* {.bycopy.} = object + private_timestamp*: mbedtls_time_t + private_session_id*: array[32, byte] + private_session_id_len*: uint + private_session*: ptr byte + private_session_len*: uint + private_next*: ptr mbedtls_ssl_cache_entry + +proc mbedtls_ssl_cache_init*(cache: ptr mbedtls_ssl_cache_context) {.importc, + cdecl.} +proc mbedtls_ssl_cache_get*(data: pointer; session_id: ptr byte; + session_id_len: uint; + session: ptr mbedtls_ssl_session): cint {.importc, + cdecl.} +proc mbedtls_ssl_cache_set*(data: pointer; session_id: ptr byte; + session_id_len: uint; + session: ptr mbedtls_ssl_session): cint {.importc, + cdecl.} +proc mbedtls_ssl_cache_remove*(data: pointer; session_id: ptr byte; + session_id_len: uint): cint {.importc, cdecl.} +proc mbedtls_ssl_cache_set_timeout*(cache: ptr mbedtls_ssl_cache_context; + timeout: cint) {.importc, cdecl.} +proc mbedtls_ssl_cache_set_max_entries*(cache: ptr mbedtls_ssl_cache_context; + max: cint) {.importc, cdecl.} +proc mbedtls_ssl_cache_free*(cache: ptr mbedtls_ssl_cache_context) {.importc, + cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/ssl_ciphersuites.nim b/webrtc/mbedtls/ssl_ciphersuites.nim new file mode 100644 index 0000000..8c7da00 --- /dev/null +++ b/webrtc/mbedtls/ssl_ciphersuites.nim @@ -0,0 +1,319 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "pk" +import "md" +import "platform_util" +import "platform_time" +import "rsa" +import "bignum" +import "ecp" +import "ecdsa" +import "cipher" +{.compile: "./mbedtls/library/ssl_ciphersuites.c".} +# Generated @ 2023-05-11T11:19:14+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ssl_ciphersuites.h + +# proc 'mbedtls_ssl_ciphersuite_get_name' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_ciphersuite_has_pfs' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_ciphersuite_no_pfs' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_ciphersuite_uses_ecdh' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_ciphersuite_cert_req_allowed' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_ciphersuite_uses_srv_cert' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_ciphersuite_uses_dhe' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_ciphersuite_uses_ecdhe' skipped - static inline procs cannot work with '--noHeader | -H' +# proc 'mbedtls_ssl_ciphersuite_uses_server_signature' skipped - static inline procs cannot work with '--noHeader | -H' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} +import macros + +macro defineEnum(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +defineEnum(mbedtls_key_exchange_type_t) +const + MBEDTLS_TLS_RSA_WITH_NULL_MD5* = 0x00000001 + MBEDTLS_TLS_RSA_WITH_NULL_SHA* = 0x00000002 + MBEDTLS_TLS_PSK_WITH_NULL_SHA* = 0x0000002C + MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA* = 0x0000002D + MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA* = 0x0000002E + MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA* = 0x0000002F + MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA* = 0x00000033 + MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA* = 0x00000035 + MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA* = 0x00000039 + MBEDTLS_TLS_RSA_WITH_NULL_SHA256* = 0x0000003B + MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256* = 0x0000003C + MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256* = 0x0000003D + MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA* = 0x00000041 + MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA* = 0x00000045 + MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256* = 0x00000067 + MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256* = 0x0000006B + MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA* = 0x00000084 + MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA* = 0x00000088 + MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA* = 0x0000008C + MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA* = 0x0000008D + MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA* = 0x00000090 + MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA* = 0x00000091 + MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA* = 0x00000094 + MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA* = 0x00000095 + MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256* = 0x0000009C + MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384* = 0x0000009D + MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256* = 0x0000009E + MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384* = 0x0000009F + MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256* = 0x000000A8 + MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384* = 0x000000A9 + MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256* = 0x000000AA + MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384* = 0x000000AB + MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256* = 0x000000AC + MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384* = 0x000000AD + MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256* = 0x000000AE + MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384* = 0x000000AF + MBEDTLS_TLS_PSK_WITH_NULL_SHA256* = 0x000000B0 + MBEDTLS_TLS_PSK_WITH_NULL_SHA384* = 0x000000B1 + MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256* = 0x000000B2 + MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384* = 0x000000B3 + MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256* = 0x000000B4 + MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384* = 0x000000B5 + MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256* = 0x000000B6 + MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384* = 0x000000B7 + MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256* = 0x000000B8 + MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384* = 0x000000B9 + MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256* = 0x000000BA + MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256* = 0x000000BE + MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256* = 0x000000C0 + MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256* = 0x000000C4 + MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA* = 0x0000C001 + MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA* = 0x0000C004 + MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA* = 0x0000C005 + MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA* = 0x0000C006 + MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA* = 0x0000C009 + MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA* = 0x0000C00A + MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA* = 0x0000C00B + MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA* = 0x0000C00E + MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA* = 0x0000C00F + MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA* = 0x0000C010 + MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA* = 0x0000C013 + MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA* = 0x0000C014 + MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256* = 0x0000C023 + MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384* = 0x0000C024 + MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256* = 0x0000C025 + MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384* = 0x0000C026 + MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256* = 0x0000C027 + MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384* = 0x0000C028 + MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256* = 0x0000C029 + MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384* = 0x0000C02A + MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256* = 0x0000C02B + MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384* = 0x0000C02C + MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256* = 0x0000C02D + MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384* = 0x0000C02E + MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256* = 0x0000C02F + MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384* = 0x0000C030 + MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256* = 0x0000C031 + MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384* = 0x0000C032 + MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA* = 0x0000C035 + MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA* = 0x0000C036 + MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256* = 0x0000C037 + MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384* = 0x0000C038 + MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA* = 0x0000C039 + MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256* = 0x0000C03A + MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384* = 0x0000C03B + MBEDTLS_TLS_RSA_WITH_ARIA_128_CBC_SHA256* = 0x0000C03C + MBEDTLS_TLS_RSA_WITH_ARIA_256_CBC_SHA384* = 0x0000C03D + MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256* = 0x0000C044 + MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384* = 0x0000C045 + MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256* = 0x0000C048 + MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384* = 0x0000C049 + MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256* = 0x0000C04A + MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384* = 0x0000C04B + MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256* = 0x0000C04C + MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384* = 0x0000C04D + MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256* = 0x0000C04E + MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384* = 0x0000C04F + MBEDTLS_TLS_RSA_WITH_ARIA_128_GCM_SHA256* = 0x0000C050 + MBEDTLS_TLS_RSA_WITH_ARIA_256_GCM_SHA384* = 0x0000C051 + MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256* = 0x0000C052 + MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384* = 0x0000C053 + MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256* = 0x0000C05C + MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384* = 0x0000C05D + MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256* = 0x0000C05E + MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384* = 0x0000C05F + MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256* = 0x0000C060 + MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384* = 0x0000C061 + MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256* = 0x0000C062 + MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384* = 0x0000C063 + MBEDTLS_TLS_PSK_WITH_ARIA_128_CBC_SHA256* = 0x0000C064 + MBEDTLS_TLS_PSK_WITH_ARIA_256_CBC_SHA384* = 0x0000C065 + MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256* = 0x0000C066 + MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384* = 0x0000C067 + MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256* = 0x0000C068 + MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384* = 0x0000C069 + MBEDTLS_TLS_PSK_WITH_ARIA_128_GCM_SHA256* = 0x0000C06A + MBEDTLS_TLS_PSK_WITH_ARIA_256_GCM_SHA384* = 0x0000C06B + MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256* = 0x0000C06C + MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384* = 0x0000C06D + MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256* = 0x0000C06E + MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384* = 0x0000C06F + MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256* = 0x0000C070 + MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384* = 0x0000C071 + MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C072 + MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C073 + MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C074 + MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C075 + MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C076 + MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C077 + MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C078 + MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C079 + MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C07A + MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C07B + MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C07C + MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C07D + MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C086 + MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C087 + MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C088 + MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C089 + MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C08A + MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C08B + MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C08C + MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C08D + MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C08E + MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C08F + MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C090 + MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C091 + MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C092 + MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C093 + MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C094 + MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C095 + MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C096 + MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C097 + MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C098 + MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C099 + MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C09A + MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C09B + MBEDTLS_TLS_RSA_WITH_AES_128_CCM* = 0x0000C09C + MBEDTLS_TLS_RSA_WITH_AES_256_CCM* = 0x0000C09D + MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM* = 0x0000C09E + MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM* = 0x0000C09F + MBEDTLS_TLS_RSA_WITH_AES_128_CCM_8* = 0x0000C0A0 + MBEDTLS_TLS_RSA_WITH_AES_256_CCM_8* = 0x0000C0A1 + MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM_8* = 0x0000C0A2 + MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM_8* = 0x0000C0A3 + MBEDTLS_TLS_PSK_WITH_AES_128_CCM* = 0x0000C0A4 + MBEDTLS_TLS_PSK_WITH_AES_256_CCM* = 0x0000C0A5 + MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM* = 0x0000C0A6 + MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM* = 0x0000C0A7 + MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8* = 0x0000C0A8 + MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8* = 0x0000C0A9 + MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM_8* = 0x0000C0AA + MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM_8* = 0x0000C0AB + MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM* = 0x0000C0AC + MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM* = 0x0000C0AD + MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8* = 0x0000C0AE + MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8* = 0x0000C0AF + MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8* = 0x0000C0FF + MBEDTLS_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256* = 0x0000CCA8 + MBEDTLS_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256* = 0x0000CCA9 + MBEDTLS_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256* = 0x0000CCAA + MBEDTLS_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256* = 0x0000CCAB + MBEDTLS_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256* = 0x0000CCAC + MBEDTLS_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256* = 0x0000CCAD + MBEDTLS_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256* = 0x0000CCAE + MBEDTLS_TLS1_3_AES_128_GCM_SHA256* = 0x00001301 + MBEDTLS_TLS1_3_AES_256_GCM_SHA384* = 0x00001302 + MBEDTLS_TLS1_3_CHACHA20_POLY1305_SHA256* = 0x00001303 + MBEDTLS_TLS1_3_AES_128_CCM_SHA256* = 0x00001304 + MBEDTLS_TLS1_3_AES_128_CCM_8_SHA256* = 0x00001305 + MBEDTLS_KEY_EXCHANGE_NONE* = (0).mbedtls_key_exchange_type_t + MBEDTLS_KEY_EXCHANGE_RSA* = (MBEDTLS_KEY_EXCHANGE_NONE + 1).mbedtls_key_exchange_type_t + MBEDTLS_KEY_EXCHANGE_DHE_RSA* = (MBEDTLS_KEY_EXCHANGE_RSA + 1).mbedtls_key_exchange_type_t + MBEDTLS_KEY_EXCHANGE_ECDHE_RSA* = (MBEDTLS_KEY_EXCHANGE_DHE_RSA + 1).mbedtls_key_exchange_type_t + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA* = (MBEDTLS_KEY_EXCHANGE_ECDHE_RSA + 1).mbedtls_key_exchange_type_t + MBEDTLS_KEY_EXCHANGE_PSK* = (MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA + 1).mbedtls_key_exchange_type_t + MBEDTLS_KEY_EXCHANGE_DHE_PSK* = (MBEDTLS_KEY_EXCHANGE_PSK + 1).mbedtls_key_exchange_type_t + MBEDTLS_KEY_EXCHANGE_RSA_PSK* = (MBEDTLS_KEY_EXCHANGE_DHE_PSK + 1).mbedtls_key_exchange_type_t + MBEDTLS_KEY_EXCHANGE_ECDHE_PSK* = (MBEDTLS_KEY_EXCHANGE_RSA_PSK + 1).mbedtls_key_exchange_type_t + MBEDTLS_KEY_EXCHANGE_ECDH_RSA* = (MBEDTLS_KEY_EXCHANGE_ECDHE_PSK + 1).mbedtls_key_exchange_type_t + MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA* = (MBEDTLS_KEY_EXCHANGE_ECDH_RSA + 1).mbedtls_key_exchange_type_t + MBEDTLS_KEY_EXCHANGE_ECJPAKE* = (MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA + 1).mbedtls_key_exchange_type_t + MBEDTLS_CIPHERSUITE_WEAK* = 0x00000001 + MBEDTLS_CIPHERSUITE_SHORT_TAG* = 0x00000002 + MBEDTLS_CIPHERSUITE_NODTLS* = 0x00000004 +type + mbedtls_ssl_ciphersuite_t* {.bycopy.} = object + private_id*: cint + private_name*: cstring + private_cipher*: uint8 + private_mac*: uint8 + private_key_exchange*: uint8 + private_flags*: uint8 + private_min_tls_version*: uint16 + private_max_tls_version*: uint16 + +proc mbedtls_ssl_list_ciphersuites*(): ptr cint {.importc, cdecl.} +proc mbedtls_ssl_ciphersuite_from_string*(ciphersuite_name: cstring): ptr mbedtls_ssl_ciphersuite_t {. + importc, cdecl.} +proc mbedtls_ssl_ciphersuite_from_id*(ciphersuite_id: cint): ptr mbedtls_ssl_ciphersuite_t {. + importc, cdecl.} +proc mbedtls_ssl_get_ciphersuite_sig_pk_alg*(info: ptr mbedtls_ssl_ciphersuite_t): mbedtls_pk_type_t {. + importc, cdecl.} +proc mbedtls_ssl_get_ciphersuite_sig_alg*(info: ptr mbedtls_ssl_ciphersuite_t): mbedtls_pk_type_t {. + importc, cdecl.} +proc mbedtls_ssl_ciphersuite_uses_ec*(info: ptr mbedtls_ssl_ciphersuite_t): cint {. + importc, cdecl.} +proc mbedtls_ssl_ciphersuite_uses_psk*(info: ptr mbedtls_ssl_ciphersuite_t): cint {. + importc, cdecl.} +proc mbedtls_ssl_ciphersuite_get_cipher_key_bitlen*( + info: ptr mbedtls_ssl_ciphersuite_t): uint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/ssl_cookie.nim b/webrtc/mbedtls/ssl_cookie.nim new file mode 100644 index 0000000..449cdb8 --- /dev/null +++ b/webrtc/mbedtls/ssl_cookie.nim @@ -0,0 +1,72 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "ssl" +import "platform_util" +import "platform_time" +import "bignum" +import "ecp" +import "ssl_ciphersuites" +import "pk" +import "md" +import "rsa" +import "ecdsa" +import "cipher" +import "x509_crt" +import "x509" +import "asn1" +import "x509_crl" +import "dhm" +import "ecdh" +import "md5" +import "ripemd160" +import "sha1" +import "sha256" +import "sha512" +import "cmac" +import "gcm" +import "ccm" +import "chachapoly" +import "poly1305" +import "chacha20" +import "ecjpake" +{.compile: "./mbedtls/library/ssl_cookie.c".} +# Generated @ 2023-05-11T11:19:14+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ssl_cookie.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_SSL_COOKIE_TIMEOUT* = 60 +type + mbedtls_ssl_cookie_ctx* {.bycopy.} = object + private_hmac_ctx*: mbedtls_md_context_t + private_timeout*: culong + +var + mbedtls_ssl_cookie_write* {.importc.}: mbedtls_ssl_cookie_write_t + mbedtls_ssl_cookie_check* {.importc.}: mbedtls_ssl_cookie_check_t +proc mbedtls_ssl_cookie_init*(ctx: ptr mbedtls_ssl_cookie_ctx) {.importc, cdecl.} +proc mbedtls_ssl_cookie_setup*(ctx: ptr mbedtls_ssl_cookie_ctx; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_ssl_cookie_set_timeout*(ctx: ptr mbedtls_ssl_cookie_ctx; + delay: culong) {.importc, cdecl.} +proc mbedtls_ssl_cookie_free*(ctx: ptr mbedtls_ssl_cookie_ctx) {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/ssl_ticket.nim b/webrtc/mbedtls/ssl_ticket.nim new file mode 100644 index 0000000..9446a2b --- /dev/null +++ b/webrtc/mbedtls/ssl_ticket.nim @@ -0,0 +1,86 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "ssl" +import "platform_util" +import "platform_time" +import "bignum" +import "ecp" +import "ssl_ciphersuites" +import "pk" +import "md" +import "rsa" +import "ecdsa" +import "cipher" +import "x509_crt" +import "x509" +import "asn1" +import "x509_crl" +import "dhm" +import "ecdh" +import "md5" +import "ripemd160" +import "sha1" +import "sha256" +import "sha512" +import "cmac" +import "gcm" +import "ccm" +import "chachapoly" +import "poly1305" +import "chacha20" +import "ecjpake" +{.compile: "./mbedtls/library/ssl_ticket.c".} +# Generated @ 2023-05-11T11:19:15+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ssl_ticket.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_SSL_TICKET_MAX_KEY_BYTES* = 32 + MBEDTLS_SSL_TICKET_KEY_NAME_BYTES* = 4 +type + mbedtls_ssl_ticket_key* {.bycopy.} = object + private_name*: array[4, byte] + private_generation_time*: mbedtls_time_t + private_ctx*: mbedtls_cipher_context_t + + mbedtls_ssl_ticket_context* {.bycopy.} = object + private_keys*: array[2, mbedtls_ssl_ticket_key] + private_active*: byte + private_ticket_lifetime*: uint32 + private_f_rng*: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.} + private_p_rng*: pointer + +var + mbedtls_ssl_ticket_write* {.importc.}: mbedtls_ssl_ticket_write_t + mbedtls_ssl_ticket_parse* {.importc.}: mbedtls_ssl_ticket_parse_t +proc mbedtls_ssl_ticket_init*(ctx: ptr mbedtls_ssl_ticket_context) {.importc, + cdecl.} +proc mbedtls_ssl_ticket_setup*(ctx: ptr mbedtls_ssl_ticket_context; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; + cipher: mbedtls_cipher_type_t; lifetime: uint32): cint {. + importc, cdecl.} +proc mbedtls_ssl_ticket_rotate*(ctx: ptr mbedtls_ssl_ticket_context; + name: ptr byte; nlength: uint; k: ptr byte; + klength: uint; lifetime: uint32): cint {. + importc, cdecl.} +proc mbedtls_ssl_ticket_free*(ctx: ptr mbedtls_ssl_ticket_context) {.importc, + cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/threading.nim b/webrtc/mbedtls/threading.nim new file mode 100644 index 0000000..4ce3ffe --- /dev/null +++ b/webrtc/mbedtls/threading.nim @@ -0,0 +1,28 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +# Generated @ 2023-05-11T11:19:15+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/threading.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_ERR_THREADING_BAD_INPUT_DATA* = -0x0000001C + MBEDTLS_ERR_THREADING_MUTEX_ERROR* = -0x0000001E +{.pop.} diff --git a/webrtc/mbedtls/timing.nim b/webrtc/mbedtls/timing.nim new file mode 100644 index 0000000..f05a1dd --- /dev/null +++ b/webrtc/mbedtls/timing.nim @@ -0,0 +1,42 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +{.compile: "./mbedtls/library/timing.c".} +# Generated @ 2023-05-11T11:19:15+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/timing.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +type + mbedtls_timing_hr_time* {.bycopy.} = object + private_opaque*: array[4, uint64] + + mbedtls_timing_delay_context* {.bycopy.} = object + private_timer*: mbedtls_timing_hr_time + private_int_ms*: uint32 + private_fin_ms*: uint32 + +proc mbedtls_timing_get_timer*(val: ptr mbedtls_timing_hr_time; reset: cint): culong {. + importc, cdecl.} +proc mbedtls_timing_set_delay*(data: pointer; int_ms: uint32; fin_ms: uint32) {. + importc, cdecl.} +proc mbedtls_timing_get_delay*(data: pointer): cint {.importc, cdecl.} +proc mbedtls_timing_get_final_delay*(data: ptr mbedtls_timing_delay_context): uint32 {. + importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/version.nim b/webrtc/mbedtls/version.nim new file mode 100644 index 0000000..9770bfb --- /dev/null +++ b/webrtc/mbedtls/version.nim @@ -0,0 +1,30 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +{.compile: "./mbedtls/library/version.c".} +{.compile: "./mbedtls/library/version_features.c".} +# Generated @ 2023-05-11T11:19:15+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/version.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +proc mbedtls_version_get_number*(): cuint {.importc, cdecl.} +proc mbedtls_version_get_string*(string: cstring) {.importc, cdecl.} +proc mbedtls_version_get_string_full*(string: cstring) {.importc, cdecl.} +proc mbedtls_version_check_feature*(feature: cstring): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/x509.nim b/webrtc/mbedtls/x509.nim new file mode 100644 index 0000000..5de4e6b --- /dev/null +++ b/webrtc/mbedtls/x509.nim @@ -0,0 +1,239 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "asn1" +import "platform_util" +import "platform_time" +import "bignum" +import "pk" +import "md" +import "rsa" +import "ecp" +import "ecdsa" +import "oid" +import "hmac_drbg" +import "asn1write" +import "nist_kw" +import "hash_info" +{.compile: "./mbedtls/library/rsa_alt_helpers.c".} +{.compile: "./mbedtls/library/x509.c".} +{.compile: "./mbedtls/library/x509_create.c".} +# Generated @ 2023-05-11T11:19:15+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/x509.h + +# const 'MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER' has unsupported value 'MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER' +# const 'MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER' has unsupported value 'MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER' +# const 'MBEDTLS_X509_EXT_KEY_USAGE' has unsupported value 'MBEDTLS_OID_X509_EXT_KEY_USAGE' +# const 'MBEDTLS_X509_EXT_CERTIFICATE_POLICIES' has unsupported value 'MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES' +# const 'MBEDTLS_X509_EXT_POLICY_MAPPINGS' has unsupported value 'MBEDTLS_OID_X509_EXT_POLICY_MAPPINGS' +# const 'MBEDTLS_X509_EXT_SUBJECT_ALT_NAME' has unsupported value 'MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME' +# const 'MBEDTLS_X509_EXT_ISSUER_ALT_NAME' has unsupported value 'MBEDTLS_OID_X509_EXT_ISSUER_ALT_NAME' +# const 'MBEDTLS_X509_EXT_SUBJECT_DIRECTORY_ATTRS' has unsupported value 'MBEDTLS_OID_X509_EXT_SUBJECT_DIRECTORY_ATTRS' +# const 'MBEDTLS_X509_EXT_BASIC_CONSTRAINTS' has unsupported value 'MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS' +# const 'MBEDTLS_X509_EXT_NAME_CONSTRAINTS' has unsupported value 'MBEDTLS_OID_X509_EXT_NAME_CONSTRAINTS' +# const 'MBEDTLS_X509_EXT_POLICY_CONSTRAINTS' has unsupported value 'MBEDTLS_OID_X509_EXT_POLICY_CONSTRAINTS' +# const 'MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE' has unsupported value 'MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE' +# const 'MBEDTLS_X509_EXT_CRL_DISTRIBUTION_POINTS' has unsupported value 'MBEDTLS_OID_X509_EXT_CRL_DISTRIBUTION_POINTS' +# const 'MBEDTLS_X509_EXT_INIHIBIT_ANYPOLICY' has unsupported value 'MBEDTLS_OID_X509_EXT_INIHIBIT_ANYPOLICY' +# const 'MBEDTLS_X509_EXT_FRESHEST_CRL' has unsupported value 'MBEDTLS_OID_X509_EXT_FRESHEST_CRL' +# const 'MBEDTLS_X509_EXT_NS_CERT_TYPE' has unsupported value 'MBEDTLS_OID_X509_EXT_NS_CERT_TYPE' +# proc 'mbedtls_x509_dn_get_next' skipped - static inline procs cannot work with '--noHeader | -H' +# const 'MBEDTLS_X509_SAFE_SNPRINTF' has unsupported value 'do { if (ret < 0 || (size_t) ret >= n) return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL; n -= (size_t) ret; p += (size_t) ret; } while (0)' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_X509_MAX_INTERMEDIATE_CA* = 8 + MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE* = -0x00002080 + MBEDTLS_ERR_X509_UNKNOWN_OID* = -0x00002100 + MBEDTLS_ERR_X509_INVALID_FORMAT* = -0x00002180 + MBEDTLS_ERR_X509_INVALID_VERSION* = -0x00002200 + MBEDTLS_ERR_X509_INVALID_SERIAL* = -0x00002280 + MBEDTLS_ERR_X509_INVALID_ALG* = -0x00002300 + MBEDTLS_ERR_X509_INVALID_NAME* = -0x00002380 + MBEDTLS_ERR_X509_INVALID_DATE* = -0x00002400 + MBEDTLS_ERR_X509_INVALID_SIGNATURE* = -0x00002480 + MBEDTLS_ERR_X509_INVALID_EXTENSIONS* = -0x00002500 + MBEDTLS_ERR_X509_UNKNOWN_VERSION* = -0x00002580 + MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG* = -0x00002600 + MBEDTLS_ERR_X509_SIG_MISMATCH* = -0x00002680 + MBEDTLS_ERR_X509_CERT_VERIFY_FAILED* = -0x00002700 + MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT* = -0x00002780 + MBEDTLS_ERR_X509_BAD_INPUT_DATA* = -0x00002800 + MBEDTLS_ERR_X509_ALLOC_FAILED* = -0x00002880 + MBEDTLS_ERR_X509_FILE_IO_ERROR* = -0x00002900 + MBEDTLS_ERR_X509_BUFFER_TOO_SMALL* = -0x00002980 + MBEDTLS_ERR_X509_FATAL_ERROR* = -0x00003000 + MBEDTLS_X509_BADCERT_EXPIRED* = 0x00000001 + MBEDTLS_X509_BADCERT_REVOKED* = 0x00000002 + MBEDTLS_X509_BADCERT_CN_MISMATCH* = 0x00000004 + MBEDTLS_X509_BADCERT_NOT_TRUSTED* = 0x00000008 + MBEDTLS_X509_BADCRL_NOT_TRUSTED* = 0x00000010 + MBEDTLS_X509_BADCRL_EXPIRED* = 0x00000020 + MBEDTLS_X509_BADCERT_MISSING* = 0x00000040 + MBEDTLS_X509_BADCERT_SKIP_VERIFY* = 0x00000080 + MBEDTLS_X509_BADCERT_OTHER* = 0x00000100 + MBEDTLS_X509_BADCERT_FUTURE* = 0x00000200 + MBEDTLS_X509_BADCRL_FUTURE* = 0x00000400 + MBEDTLS_X509_BADCERT_KEY_USAGE* = 0x00000800 + MBEDTLS_X509_BADCERT_EXT_KEY_USAGE* = 0x00001000 + MBEDTLS_X509_BADCERT_NS_CERT_TYPE* = 0x00002000 + MBEDTLS_X509_BADCERT_BAD_MD* = 0x00004000 + MBEDTLS_X509_BADCERT_BAD_PK* = 0x00008000 + MBEDTLS_X509_BADCERT_BAD_KEY* = 0x00010000 + MBEDTLS_X509_BADCRL_BAD_MD* = 0x00020000 + MBEDTLS_X509_BADCRL_BAD_PK* = 0x00040000 + MBEDTLS_X509_BADCRL_BAD_KEY* = 0x00080000 + MBEDTLS_X509_SAN_OTHER_NAME* = 0 + MBEDTLS_X509_SAN_RFC822_NAME* = 1 + MBEDTLS_X509_SAN_DNS_NAME* = 2 + MBEDTLS_X509_SAN_X400_ADDRESS_NAME* = 3 + MBEDTLS_X509_SAN_DIRECTORY_NAME* = 4 + MBEDTLS_X509_SAN_EDI_PARTY_NAME* = 5 + MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER* = 6 + MBEDTLS_X509_SAN_IP_ADDRESS* = 7 + MBEDTLS_X509_SAN_REGISTERED_ID* = 8 + MBEDTLS_X509_KU_DIGITAL_SIGNATURE* = (0x00000080) + MBEDTLS_X509_KU_NON_REPUDIATION* = (0x00000040) + MBEDTLS_X509_KU_KEY_ENCIPHERMENT* = (0x00000020) + MBEDTLS_X509_KU_DATA_ENCIPHERMENT* = (0x00000010) + MBEDTLS_X509_KU_KEY_AGREEMENT* = (0x00000008) + MBEDTLS_X509_KU_KEY_CERT_SIGN* = (0x00000004) + MBEDTLS_X509_KU_CRL_SIGN* = (0x00000002) + MBEDTLS_X509_KU_ENCIPHER_ONLY* = (0x00000001) + MBEDTLS_X509_KU_DECIPHER_ONLY* = (0x00008000) + MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT* = (0x00000080) + MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER* = (0x00000040) + MBEDTLS_X509_NS_CERT_TYPE_EMAIL* = (0x00000020) + MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING* = (0x00000010) + MBEDTLS_X509_NS_CERT_TYPE_RESERVED* = (0x00000008) + MBEDTLS_X509_NS_CERT_TYPE_SSL_CA* = (0x00000004) + MBEDTLS_X509_NS_CERT_TYPE_EMAIL_CA* = (0x00000002) + MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING_CA* = (0x00000001) + MBEDTLS_X509_FORMAT_DER* = 1 + MBEDTLS_X509_FORMAT_PEM* = 2 + MBEDTLS_X509_MAX_DN_NAME_SIZE* = 256 +type + mbedtls_x509_buf* = mbedtls_asn1_buf + mbedtls_x509_bitstring* = mbedtls_asn1_bitstring + mbedtls_x509_name* = mbedtls_asn1_named_data + mbedtls_x509_sequence* = mbedtls_asn1_sequence + mbedtls_x509_time* {.bycopy.} = object + year*: cint + mon*: cint + day*: cint + hour*: cint + min*: cint + sec*: cint + + Type_x509h1* {.bycopy.} = object + oid*: mbedtls_x509_buf + val*: mbedtls_x509_buf + + Union_x509h1* {.union, bycopy.} = object + hardware_module_name*: Type_x509h1 + + mbedtls_x509_san_other_name* {.bycopy.} = object + type_id*: mbedtls_x509_buf + value*: Union_x509h1 + + Union_x509h2* {.union, bycopy.} = object + other_name*: mbedtls_x509_san_other_name + directory_name*: mbedtls_x509_name + unstructured_name*: mbedtls_x509_buf + + mbedtls_x509_subject_alternative_name* {.bycopy.} = object + `type`*: cint + san*: Union_x509h2 + +proc mbedtls_x509_dn_gets*(buf: cstring; size: uint; dn: ptr mbedtls_x509_name): cint {. + importc, cdecl.} +proc mbedtls_x509_serial_gets*(buf: cstring; size: uint; + serial: ptr mbedtls_x509_buf): cint {.importc, + cdecl.} +proc mbedtls_x509_time_is_past*(to: ptr mbedtls_x509_time): cint {.importc, + cdecl.} +proc mbedtls_x509_time_is_future*(`from`: ptr mbedtls_x509_time): cint {. + importc, cdecl.} +proc mbedtls_x509_parse_subject_alt_name*(san_buf: ptr mbedtls_x509_buf; + san: ptr mbedtls_x509_subject_alternative_name): cint {.importc, cdecl.} +proc mbedtls_x509_free_subject_alt_name*( + san: ptr mbedtls_x509_subject_alternative_name) {.importc, cdecl.} +proc mbedtls_x509_get_name*(p: ptr ptr byte; `end`: ptr byte; + cur: ptr mbedtls_x509_name): cint {.importc, cdecl.} +proc mbedtls_x509_get_alg_null*(p: ptr ptr byte; `end`: ptr byte; + alg: ptr mbedtls_x509_buf): cint {.importc, + cdecl.} +proc mbedtls_x509_get_alg*(p: ptr ptr byte; `end`: ptr byte; + alg: ptr mbedtls_x509_buf; + params: ptr mbedtls_x509_buf): cint {.importc, cdecl.} +proc mbedtls_x509_get_rsassa_pss_params*(params: ptr mbedtls_x509_buf; + md_alg: ptr mbedtls_md_type_t; mgf_md: ptr mbedtls_md_type_t; + salt_len: ptr cint): cint {.importc, cdecl.} +proc mbedtls_x509_get_sig*(p: ptr ptr byte; `end`: ptr byte; + sig: ptr mbedtls_x509_buf): cint {.importc, cdecl.} +proc mbedtls_x509_get_sig_alg*(sig_oid: ptr mbedtls_x509_buf; + sig_params: ptr mbedtls_x509_buf; + md_alg: ptr mbedtls_md_type_t; + pk_alg: ptr mbedtls_pk_type_t; + sig_opts: ptr pointer): cint {.importc, cdecl.} +proc mbedtls_x509_get_time*(p: ptr ptr byte; `end`: ptr byte; + t: ptr mbedtls_x509_time): cint {.importc, cdecl.} +proc mbedtls_x509_get_serial*(p: ptr ptr byte; `end`: ptr byte; + serial: ptr mbedtls_x509_buf): cint {.importc, + cdecl.} +proc mbedtls_x509_get_ext*(p: ptr ptr byte; `end`: ptr byte; + ext: ptr mbedtls_x509_buf; tag: cint): cint {. + importc, cdecl.} +proc mbedtls_x509_sig_alg_gets*(buf: cstring; size: uint; + sig_oid: ptr mbedtls_x509_buf; + pk_alg: mbedtls_pk_type_t; + md_alg: mbedtls_md_type_t; sig_opts: pointer): cint {. + importc, cdecl.} +proc mbedtls_x509_key_size_helper*(buf: cstring; buf_size: uint; name: cstring): cint {. + importc, cdecl.} +proc mbedtls_x509_string_to_names*(head: ptr ptr mbedtls_asn1_named_data; + name: cstring): cint {.importc, cdecl.} +proc mbedtls_x509_set_extension*(head: ptr ptr mbedtls_asn1_named_data; + oid: cstring; oid_len: uint; critical: cint; + val: ptr byte; val_len: uint): cint {. + importc, cdecl.} +proc mbedtls_x509_write_extensions*(p: ptr ptr byte; start: ptr byte; + first: ptr mbedtls_asn1_named_data): cint {. + importc, cdecl.} +proc mbedtls_x509_write_names*(p: ptr ptr byte; start: ptr byte; + first: ptr mbedtls_asn1_named_data): cint {. + importc, cdecl.} +proc mbedtls_x509_write_sig*(p: ptr ptr byte; start: ptr byte; oid: cstring; + oid_len: uint; sig: ptr byte; size: uint): cint {. + importc, cdecl.} +proc mbedtls_x509_get_ns_cert_type*(p: ptr ptr byte; `end`: ptr byte; + ns_cert_type: ptr byte): cint {.importc, + cdecl.} +proc mbedtls_x509_get_key_usage*(p: ptr ptr byte; `end`: ptr byte; + key_usage: ptr cuint): cint {.importc, cdecl.} +proc mbedtls_x509_get_subject_alt_name*(p: ptr ptr byte; `end`: ptr byte; + subject_alt_name: ptr mbedtls_x509_sequence): cint {.importc, cdecl.} +proc mbedtls_x509_info_subject_alt_name*(buf: ptr cstring; size: ptr uint; + subject_alt_name: ptr mbedtls_x509_sequence; prefix: cstring): cint {. + importc, cdecl.} +proc mbedtls_x509_info_cert_type*(buf: ptr cstring; size: ptr uint; + ns_cert_type: byte): cint {.importc, cdecl.} +proc mbedtls_x509_info_key_usage*(buf: ptr cstring; size: ptr uint; + key_usage: cuint): cint {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/x509_crl.nim b/webrtc/mbedtls/x509_crl.nim new file mode 100644 index 0000000..4e309b9 --- /dev/null +++ b/webrtc/mbedtls/x509_crl.nim @@ -0,0 +1,72 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "x509" +import "asn1" +import "platform_util" +import "platform_time" +import "bignum" +import "pk" +import "md" +import "rsa" +import "ecp" +import "ecdsa" +{.compile: "./mbedtls/library/x509_crl.c".} +# Generated @ 2023-05-11T11:19:15+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/x509_crl.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +type + mbedtls_x509_crl_entry* {.bycopy.} = object + raw*: mbedtls_x509_buf + serial*: mbedtls_x509_buf + revocation_date*: mbedtls_x509_time + entry_ext*: mbedtls_x509_buf + next*: ptr mbedtls_x509_crl_entry + + mbedtls_x509_crl* {.bycopy.} = object + raw*: mbedtls_x509_buf + tbs*: mbedtls_x509_buf + version*: cint + sig_oid*: mbedtls_x509_buf + issuer_raw*: mbedtls_x509_buf + issuer*: mbedtls_x509_name + this_update*: mbedtls_x509_time + next_update*: mbedtls_x509_time + entry*: mbedtls_x509_crl_entry + crl_ext*: mbedtls_x509_buf + private_sig_oid2*: mbedtls_x509_buf + private_sig*: mbedtls_x509_buf + private_sig_md*: mbedtls_md_type_t + private_sig_pk*: mbedtls_pk_type_t + private_sig_opts*: pointer + next*: ptr mbedtls_x509_crl + +proc mbedtls_x509_crl_parse_der*(chain: ptr mbedtls_x509_crl; buf: ptr byte; + buflen: uint): cint {.importc, cdecl.} +proc mbedtls_x509_crl_parse*(chain: ptr mbedtls_x509_crl; buf: ptr byte; + buflen: uint): cint {.importc, cdecl.} +proc mbedtls_x509_crl_parse_file*(chain: ptr mbedtls_x509_crl; path: cstring): cint {. + importc, cdecl.} +proc mbedtls_x509_crl_info*(buf: cstring; size: uint; prefix: cstring; + crl: ptr mbedtls_x509_crl): cint {.importc, cdecl.} +proc mbedtls_x509_crl_init*(crl: ptr mbedtls_x509_crl) {.importc, cdecl.} +proc mbedtls_x509_crl_free*(crl: ptr mbedtls_x509_crl) {.importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/x509_crt.nim b/webrtc/mbedtls/x509_crt.nim new file mode 100644 index 0000000..89336b6 --- /dev/null +++ b/webrtc/mbedtls/x509_crt.nim @@ -0,0 +1,214 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "x509" +import "asn1" +import "platform_util" +import "platform_time" +import "bignum" +import "pk" +import "md" +import "rsa" +import "ecp" +import "ecdsa" +import "x509_crl" +{.compile: "./mbedtls/library/x509_crt.c".} +{.compile: "./mbedtls/library/x509write_crt.c".} +# Generated @ 2023-05-11T11:19:15+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/x509_crt.h + +# const 'MBEDTLS_X509_CRT_ERROR_INFO_LIST' has unsupported value 'X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_EXPIRED, "MBEDTLS_X509_BADCERT_EXPIRED", "The certificate validity has expired") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_REVOKED, "MBEDTLS_X509_BADCERT_REVOKED", "The certificate has been revoked (is on a CRL)") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_CN_MISMATCH, "MBEDTLS_X509_BADCERT_CN_MISMATCH", "The certificate Common Name (CN) does not match with the expected CN") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_NOT_TRUSTED, "MBEDTLS_X509_BADCERT_NOT_TRUSTED", "The certificate is not correctly signed by the trusted CA") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_NOT_TRUSTED, "MBEDTLS_X509_BADCRL_NOT_TRUSTED", "The CRL is not correctly signed by the trusted CA") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_EXPIRED, "MBEDTLS_X509_BADCRL_EXPIRED", "The CRL is expired") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_MISSING, "MBEDTLS_X509_BADCERT_MISSING", "Certificate was missing") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_SKIP_VERIFY, "MBEDTLS_X509_BADCERT_SKIP_VERIFY", "Certificate verification was skipped") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_OTHER, "MBEDTLS_X509_BADCERT_OTHER", "Other reason (can be used by verify callback)") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_FUTURE, "MBEDTLS_X509_BADCERT_FUTURE", "The certificate validity starts in the future") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_FUTURE, "MBEDTLS_X509_BADCRL_FUTURE", "The CRL is from the future") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_KEY_USAGE, "MBEDTLS_X509_BADCERT_KEY_USAGE", "Usage does not match the keyUsage extension") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_EXT_KEY_USAGE, "MBEDTLS_X509_BADCERT_EXT_KEY_USAGE", "Usage does not match the extendedKeyUsage extension") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_NS_CERT_TYPE, "MBEDTLS_X509_BADCERT_NS_CERT_TYPE", "Usage does not match the nsCertType extension") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_MD, "MBEDTLS_X509_BADCERT_BAD_MD", "The certificate is signed with an unacceptable hash.") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_PK, "MBEDTLS_X509_BADCERT_BAD_PK", "The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA).") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_KEY, "MBEDTLS_X509_BADCERT_BAD_KEY", "The certificate is signed with an unacceptable key (eg bad curve, RSA too short).") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_MD, "MBEDTLS_X509_BADCRL_BAD_MD", "The CRL is signed with an unacceptable hash.") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_PK, "MBEDTLS_X509_BADCRL_BAD_PK", "The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA).") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_KEY, "MBEDTLS_X509_BADCRL_BAD_KEY", "The CRL is signed with an unacceptable key (eg bad curve, RSA too short).")' +# const 'MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE' has unsupported value '(MBEDTLS_X509_MAX_INTERMEDIATE_CA + 2)' +# proc 'mbedtls_x509_crt_has_ext_type' skipped - static inline procs cannot work with '--noHeader | -H' +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +const + MBEDTLS_X509_CRT_VERSION_1* = 0 + MBEDTLS_X509_CRT_VERSION_2* = 1 + MBEDTLS_X509_CRT_VERSION_3* = 2 + MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN* = 20 + MBEDTLS_X509_RFC5280_UTC_TIME_LEN* = 15 + MBEDTLS_X509_MAX_FILE_PATH_LEN* = 512 +type + mbedtls_x509_crt* {.bycopy.} = object + private_own_buffer*: cint + raw*: mbedtls_x509_buf + tbs*: mbedtls_x509_buf + version*: cint + serial*: mbedtls_x509_buf + sig_oid*: mbedtls_x509_buf + issuer_raw*: mbedtls_x509_buf + subject_raw*: mbedtls_x509_buf + issuer*: mbedtls_x509_name + subject*: mbedtls_x509_name + valid_from*: mbedtls_x509_time + valid_to*: mbedtls_x509_time + pk_raw*: mbedtls_x509_buf + pk*: mbedtls_pk_context + issuer_id*: mbedtls_x509_buf + subject_id*: mbedtls_x509_buf + v3_ext*: mbedtls_x509_buf + subject_alt_names*: mbedtls_x509_sequence + certificate_policies*: mbedtls_x509_sequence + private_ext_types*: cint + private_ca_istrue*: cint + private_max_pathlen*: cint + private_key_usage*: cuint + ext_key_usage*: mbedtls_x509_sequence + private_ns_cert_type*: byte + private_sig*: mbedtls_x509_buf + private_sig_md*: mbedtls_md_type_t + private_sig_pk*: mbedtls_pk_type_t + private_sig_opts*: pointer + next*: ptr mbedtls_x509_crt + + mbedtls_x509_crt_profile* {.bycopy.} = object + allowed_mds*: uint32 + allowed_pks*: uint32 + allowed_curves*: uint32 + rsa_min_bitlen*: uint32 + + mbedtls_x509write_cert* {.bycopy.} = object + private_version*: cint + private_serial*: array[20, byte] + private_serial_len*: uint + private_subject_key*: ptr mbedtls_pk_context + private_issuer_key*: ptr mbedtls_pk_context + private_subject*: ptr mbedtls_asn1_named_data + private_issuer*: ptr mbedtls_asn1_named_data + private_md_alg*: mbedtls_md_type_t + private_not_before*: array[15 + typeof(15)(1), cchar] + private_not_after*: array[15 + typeof(15)(1), cchar] + private_extensions*: ptr mbedtls_asn1_named_data + + mbedtls_x509_crt_verify_chain_item* {.bycopy.} = object + private_crt*: ptr mbedtls_x509_crt + private_flags*: uint32 + + mbedtls_x509_crt_verify_chain* {.bycopy.} = object + private_items*: array[(8 + typeof(8)(2)), mbedtls_x509_crt_verify_chain_item] + private_len*: cuint + + mbedtls_x509_crt_restart_ctx* = object + mbedtls_x509_crt_ext_cb_t* = proc (p_ctx: pointer; crt: ptr mbedtls_x509_crt; + oid: ptr mbedtls_x509_buf; critical: cint; + p: ptr byte; `end`: ptr byte): cint {. + cdecl.} + mbedtls_x509_crt_ca_cb_t* = proc (p_ctx: pointer; child: ptr mbedtls_x509_crt; + candidate_cas: ptr ptr mbedtls_x509_crt): cint {. + cdecl.} +var + mbedtls_x509_crt_profile_default* {.importc.}: mbedtls_x509_crt_profile + mbedtls_x509_crt_profile_next* {.importc.}: mbedtls_x509_crt_profile + mbedtls_x509_crt_profile_suiteb* {.importc.}: mbedtls_x509_crt_profile + mbedtls_x509_crt_profile_none* {.importc.}: mbedtls_x509_crt_profile +proc mbedtls_x509_crt_parse_der*(chain: ptr mbedtls_x509_crt; buf: ptr byte; + buflen: uint): cint {.importc, cdecl.} +proc mbedtls_x509_crt_parse_der_with_ext_cb*(chain: ptr mbedtls_x509_crt; + buf: ptr byte; buflen: uint; make_copy: cint; + cb: mbedtls_x509_crt_ext_cb_t; p_ctx: pointer): cint {.importc, cdecl.} +proc mbedtls_x509_crt_parse_der_nocopy*(chain: ptr mbedtls_x509_crt; + buf: ptr byte; buflen: uint): cint {. + importc, cdecl.} +proc mbedtls_x509_crt_parse*(chain: ptr mbedtls_x509_crt; buf: ptr byte; + buflen: uint): cint {.importc, cdecl.} +proc mbedtls_x509_crt_parse_file*(chain: ptr mbedtls_x509_crt; path: cstring): cint {. + importc, cdecl.} +proc mbedtls_x509_crt_parse_path*(chain: ptr mbedtls_x509_crt; path: cstring): cint {. + importc, cdecl.} +proc mbedtls_x509_crt_info*(buf: cstring; size: uint; prefix: cstring; + crt: ptr mbedtls_x509_crt): cint {.importc, cdecl.} +proc mbedtls_x509_crt_verify_info*(buf: cstring; size: uint; prefix: cstring; + flags: uint32): cint {.importc, cdecl.} +proc mbedtls_x509_crt_verify*(crt: ptr mbedtls_x509_crt; + trust_ca: ptr mbedtls_x509_crt; + ca_crl: ptr mbedtls_x509_crl; cn: cstring; + flags: ptr uint32; f_vrfy: proc (a1: pointer; + a2: ptr mbedtls_x509_crt; a3: cint; a4: ptr uint32): cint {.cdecl.}; + p_vrfy: pointer): cint {.importc, cdecl.} +proc mbedtls_x509_crt_verify_with_profile*(crt: ptr mbedtls_x509_crt; + trust_ca: ptr mbedtls_x509_crt; ca_crl: ptr mbedtls_x509_crl; + profile: ptr mbedtls_x509_crt_profile; cn: cstring; flags: ptr uint32; + f_vrfy: proc (a1: pointer; a2: ptr mbedtls_x509_crt; a3: cint; + a4: ptr uint32): cint {.cdecl.}; p_vrfy: pointer): cint {. + importc, cdecl.} +proc mbedtls_x509_crt_verify_restartable*(crt: ptr mbedtls_x509_crt; + trust_ca: ptr mbedtls_x509_crt; ca_crl: ptr mbedtls_x509_crl; + profile: ptr mbedtls_x509_crt_profile; cn: cstring; flags: ptr uint32; + f_vrfy: proc (a1: pointer; a2: ptr mbedtls_x509_crt; a3: cint; + a4: ptr uint32): cint {.cdecl.}; p_vrfy: pointer; + rs_ctx: ptr mbedtls_x509_crt_restart_ctx): cint {.importc, cdecl.} +proc mbedtls_x509_crt_check_key_usage*(crt: ptr mbedtls_x509_crt; usage: cuint): cint {. + importc, cdecl.} +proc mbedtls_x509_crt_check_extended_key_usage*(crt: ptr mbedtls_x509_crt; + usage_oid: cstring; usage_len: uint): cint {.importc, cdecl.} +proc mbedtls_x509_crt_is_revoked*(crt: ptr mbedtls_x509_crt; + crl: ptr mbedtls_x509_crl): cint {.importc, + cdecl.} +proc mbedtls_x509_crt_init*(crt: ptr mbedtls_x509_crt) {.importc, cdecl.} +proc mbedtls_x509_crt_free*(crt: ptr mbedtls_x509_crt) {.importc, cdecl.} +proc mbedtls_x509write_crt_init*(ctx: ptr mbedtls_x509write_cert) {.importc, + cdecl.} +proc mbedtls_x509write_crt_set_version*(ctx: ptr mbedtls_x509write_cert; + version: cint) {.importc, cdecl.} +proc mbedtls_x509write_crt_set_serial*(ctx: ptr mbedtls_x509write_cert; + serial: ptr mbedtls_mpi): cint {.importc, + cdecl.} +proc mbedtls_x509write_crt_set_serial_raw*(ctx: ptr mbedtls_x509write_cert; + serial: ptr byte; serial_len: uint): cint {.importc, cdecl.} +proc mbedtls_x509write_crt_set_validity*(ctx: ptr mbedtls_x509write_cert; + not_before: cstring; not_after: cstring): cint {.importc, cdecl.} +proc mbedtls_x509write_crt_set_issuer_name*(ctx: ptr mbedtls_x509write_cert; + issuer_name: cstring): cint {.importc, cdecl.} +proc mbedtls_x509write_crt_set_subject_name*(ctx: ptr mbedtls_x509write_cert; + subject_name: cstring): cint {.importc, cdecl.} +proc mbedtls_x509write_crt_set_subject_key*(ctx: ptr mbedtls_x509write_cert; + key: ptr mbedtls_pk_context) {.importc, cdecl.} +proc mbedtls_x509write_crt_set_issuer_key*(ctx: ptr mbedtls_x509write_cert; + key: ptr mbedtls_pk_context) {.importc, cdecl.} +proc mbedtls_x509write_crt_set_md_alg*(ctx: ptr mbedtls_x509write_cert; + md_alg: mbedtls_md_type_t) {.importc, + cdecl.} +proc mbedtls_x509write_crt_set_extension*(ctx: ptr mbedtls_x509write_cert; + oid: cstring; oid_len: uint; critical: cint; val: ptr byte; val_len: uint): cint {. + importc, cdecl.} +proc mbedtls_x509write_crt_set_basic_constraints*( + ctx: ptr mbedtls_x509write_cert; is_ca: cint; max_pathlen: cint): cint {. + importc, cdecl.} +proc mbedtls_x509write_crt_set_subject_key_identifier*( + ctx: ptr mbedtls_x509write_cert): cint {.importc, cdecl.} +proc mbedtls_x509write_crt_set_authority_key_identifier*( + ctx: ptr mbedtls_x509write_cert): cint {.importc, cdecl.} +proc mbedtls_x509write_crt_set_key_usage*(ctx: ptr mbedtls_x509write_cert; + key_usage: cuint): cint {.importc, cdecl.} +proc mbedtls_x509write_crt_set_ext_key_usage*(ctx: ptr mbedtls_x509write_cert; + exts: ptr mbedtls_asn1_sequence): cint {.importc, cdecl.} +proc mbedtls_x509write_crt_set_ns_cert_type*(ctx: ptr mbedtls_x509write_cert; + ns_cert_type: byte): cint {.importc, cdecl.} +proc mbedtls_x509write_crt_free*(ctx: ptr mbedtls_x509write_cert) {.importc, + cdecl.} +proc mbedtls_x509write_crt_der*(ctx: ptr mbedtls_x509write_cert; + buf: ptr byte; size: uint; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +proc mbedtls_x509write_crt_pem*(ctx: ptr mbedtls_x509write_cert; + buf: ptr byte; size: uint; f_rng: proc ( + a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. + importc, cdecl.} +{.pop.} diff --git a/webrtc/mbedtls/x509_csr.nim b/webrtc/mbedtls/x509_csr.nim new file mode 100644 index 0000000..dac044f --- /dev/null +++ b/webrtc/mbedtls/x509_csr.nim @@ -0,0 +1,105 @@ +#import strformat, os +# +## C include directory +#const root = currentSourcePath.parentDir +#const mbedtlsInclude = root/"mbedtls"/"include" +#const mbedtlsLibrary = root/"mbedtls"/"library" +# +#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} +# +import "private_access" +import "build_info" +import "mbedtls_config" +import "config_psa" +import "check_config" +import "x509" +import "asn1" +import "platform_util" +import "platform_time" +import "bignum" +import "pk" +import "md" +import "rsa" +import "ecp" +import "ecdsa" +{.compile: "./mbedtls/library/x509_csr.c".} +{.compile: "./mbedtls/library/x509write_csr.c".} +# Generated @ 2023-05-11T11:19:15+02:00 +# Command line: +# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/x509_csr.h + +{.push hint[ConvFromXtoItselfNotNeeded]: off.} + + +{.experimental: "codeReordering".} +{.passc: "-I./mbedtls/include".} +{.passc: "-I./mbedtls/library".} +type + mbedtls_x509_csr* {.bycopy.} = object + raw*: mbedtls_x509_buf + cri*: mbedtls_x509_buf + version*: cint + subject_raw*: mbedtls_x509_buf + subject*: mbedtls_x509_name + pk*: mbedtls_pk_context + key_usage*: cuint + ns_cert_type*: byte + subject_alt_names*: mbedtls_x509_sequence + private_ext_types*: cint + sig_oid*: mbedtls_x509_buf + private_sig*: mbedtls_x509_buf + private_sig_md*: mbedtls_md_type_t + private_sig_pk*: mbedtls_pk_type_t + private_sig_opts*: pointer + + mbedtls_x509write_csr* {.bycopy.} = object + private_key*: ptr mbedtls_pk_context + private_subject*: ptr mbedtls_asn1_named_data + private_md_alg*: mbedtls_md_type_t + private_extensions*: ptr mbedtls_asn1_named_data + + mbedtls_x509_san_list* {.bycopy.} = object + node*: mbedtls_x509_subject_alternative_name + next*: ptr mbedtls_x509_san_list + +proc mbedtls_x509_csr_parse_der*(csr: ptr mbedtls_x509_csr; buf: ptr byte; + buflen: uint): cint {.importc, cdecl.} +proc mbedtls_x509_csr_parse*(csr: ptr mbedtls_x509_csr; buf: ptr byte; + buflen: uint): cint {.importc, cdecl.} +proc mbedtls_x509_csr_parse_file*(csr: ptr mbedtls_x509_csr; path: cstring): cint {. + importc, cdecl.} +proc mbedtls_x509_csr_info*(buf: cstring; size: uint; prefix: cstring; + csr: ptr mbedtls_x509_csr): cint {.importc, cdecl.} +proc mbedtls_x509_csr_init*(csr: ptr mbedtls_x509_csr) {.importc, cdecl.} +proc mbedtls_x509_csr_free*(csr: ptr mbedtls_x509_csr) {.importc, cdecl.} +proc mbedtls_x509write_csr_init*(ctx: ptr mbedtls_x509write_csr) {.importc, + cdecl.} +proc mbedtls_x509write_csr_set_subject_name*(ctx: ptr mbedtls_x509write_csr; + subject_name: cstring): cint {.importc, cdecl.} +proc mbedtls_x509write_csr_set_key*(ctx: ptr mbedtls_x509write_csr; + key: ptr mbedtls_pk_context) {.importc, + cdecl.} +proc mbedtls_x509write_csr_set_md_alg*(ctx: ptr mbedtls_x509write_csr; + md_alg: mbedtls_md_type_t) {.importc, + cdecl.} +proc mbedtls_x509write_csr_set_key_usage*(ctx: ptr mbedtls_x509write_csr; + key_usage: byte): cint {.importc, cdecl.} +proc mbedtls_x509write_csr_set_subject_alternative_name*( + ctx: ptr mbedtls_x509write_csr; san_list: ptr mbedtls_x509_san_list): cint {. + importc, cdecl.} +proc mbedtls_x509write_csr_set_ns_cert_type*(ctx: ptr mbedtls_x509write_csr; + ns_cert_type: byte): cint {.importc, cdecl.} +proc mbedtls_x509write_csr_set_extension*(ctx: ptr mbedtls_x509write_csr; + oid: cstring; oid_len: uint; critical: cint; val: ptr byte; val_len: uint): cint {. + importc, cdecl.} +proc mbedtls_x509write_csr_free*(ctx: ptr mbedtls_x509write_csr) {.importc, + cdecl.} +proc mbedtls_x509write_csr_der*(ctx: ptr mbedtls_x509write_csr; buf: ptr byte; + size: uint; f_rng: proc (a1: pointer; + a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, + cdecl.} +proc mbedtls_x509write_csr_pem*(ctx: ptr mbedtls_x509write_csr; buf: ptr byte; + size: uint; f_rng: proc (a1: pointer; + a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, + cdecl.} +{.pop.} From e69b25bbf1702d48fccb54e5004908f640271010 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Tue, 16 May 2023 16:12:15 +0200 Subject: [PATCH 12/66] mbedtls wrapper done --- webrtc/mbedtls/aes.nim | 22 +---- webrtc/mbedtls/aria.nim | 15 +-- webrtc/mbedtls/asn1.nim | 15 +-- webrtc/mbedtls/asn1write.nim | 16 +--- webrtc/mbedtls/base64.nim | 19 +--- webrtc/mbedtls/bignum.nim | 59 +----------- webrtc/mbedtls/build_info.nim | 15 +-- webrtc/mbedtls/camellia.nim | 15 +-- webrtc/mbedtls/ccm.nim | 21 +---- webrtc/mbedtls/chacha20.nim | 15 +-- webrtc/mbedtls/chachapoly.nim | 59 +----------- webrtc/mbedtls/check_config.nim | 22 ----- webrtc/mbedtls/cipher.nim | 62 ++----------- webrtc/mbedtls/cmac.nim | 16 +--- webrtc/mbedtls/compat_2_x.nim | 42 --------- webrtc/mbedtls/config_psa.nim | 15 +-- webrtc/mbedtls/constant_time.nim | 15 +-- webrtc/mbedtls/ctr_drbg.nim | 24 +---- webrtc/mbedtls/debug.nim | 89 +----------------- webrtc/mbedtls/des.nim | 21 +---- webrtc/mbedtls/dhm.nim | 60 +----------- webrtc/mbedtls/ecdh.nim | 64 +------------ webrtc/mbedtls/ecdsa.nim | 18 +--- webrtc/mbedtls/ecjpake.nim | 59 +----------- webrtc/mbedtls/ecp.nim | 64 +------------ webrtc/mbedtls/entropy.nim | 23 +---- webrtc/mbedtls/error.nim | 19 +--- webrtc/mbedtls/gcm.nim | 22 +---- webrtc/mbedtls/hash_info.nim | 1 + webrtc/mbedtls/hkdf.nim | 22 +---- webrtc/mbedtls/hmac_drbg.nim | 22 +---- webrtc/mbedtls/lms.nim | 59 +----------- webrtc/mbedtls/mbedtls_config.nim | 15 +-- webrtc/mbedtls/md.nim | 65 +------------ webrtc/mbedtls/md5.nim | 15 +-- webrtc/mbedtls/memory_buffer_alloc.nim | 18 +--- webrtc/mbedtls/net_sockets.nim | 48 +--------- webrtc/mbedtls/nist_kw.nim | 65 +------------ webrtc/mbedtls/oid.nim | 15 +-- webrtc/mbedtls/pem.nim | 17 +--- webrtc/mbedtls/pk.nim | 64 +------------ webrtc/mbedtls/pkcs12.nim | 15 +-- webrtc/mbedtls/pkcs5.nim | 17 +--- webrtc/mbedtls/pkcs7.nim | 65 +------------ webrtc/mbedtls/platform.nim | 21 +---- webrtc/mbedtls/platform_time.nim | 18 +--- webrtc/mbedtls/platform_util.nim | 23 +---- webrtc/mbedtls/poly1305.nim | 15 +-- webrtc/mbedtls/private_access.nim | 20 ---- webrtc/mbedtls/psa/crypto.nim | 72 +-------------- .../mbedtls/psa/crypto_builtin_composites.nim | 16 +--- .../mbedtls/psa/crypto_builtin_primitives.nim | 20 +--- webrtc/mbedtls/psa/crypto_compat.nim | 20 ---- webrtc/mbedtls/psa/crypto_config.nim | 15 +-- webrtc/mbedtls/psa/crypto_driver_common.nim | 62 +------------ .../psa/crypto_driver_contexts_composites.nim | 27 ------ .../crypto_driver_contexts_key_derivation.nim | 26 ------ .../psa/crypto_driver_contexts_primitives.nim | 27 ------ webrtc/mbedtls/psa/crypto_extra.nim | 23 ----- webrtc/mbedtls/psa/crypto_platform.nim | 22 ----- webrtc/mbedtls/psa/crypto_se_driver.nim | 62 +------------ webrtc/mbedtls/psa/crypto_sizes.nim | 16 +--- webrtc/mbedtls/psa/crypto_struct.nim | 24 +---- webrtc/mbedtls/psa/crypto_types.nim | 58 +----------- webrtc/mbedtls/psa/crypto_values.nim | 15 +-- webrtc/mbedtls/psa_util.nim | 16 +--- webrtc/mbedtls/ripemd160.nim | 15 +-- webrtc/mbedtls/rsa.nim | 16 +--- webrtc/mbedtls/sha1.nim | 15 +-- webrtc/mbedtls/sha256.nim | 15 +-- webrtc/mbedtls/sha512.nim | 15 +-- webrtc/mbedtls/ssl.nim | 92 ++----------------- webrtc/mbedtls/ssl_cache.nim | 47 +--------- webrtc/mbedtls/ssl_ciphersuites.nim | 73 +-------------- webrtc/mbedtls/ssl_cookie.nim | 47 +--------- webrtc/mbedtls/ssl_ticket.nim | 45 +-------- webrtc/mbedtls/threading.nim | 20 +--- webrtc/mbedtls/timing.nim | 19 +--- webrtc/mbedtls/version.nim | 18 +--- webrtc/mbedtls/x509.nim | 33 +------ webrtc/mbedtls/x509_crl.nim | 27 +----- webrtc/mbedtls/x509_crt.nim | 34 ++----- webrtc/mbedtls/x509_csr.nim | 26 +----- 83 files changed, 195 insertions(+), 2409 deletions(-) delete mode 100644 webrtc/mbedtls/check_config.nim delete mode 100644 webrtc/mbedtls/compat_2_x.nim delete mode 100644 webrtc/mbedtls/private_access.nim delete mode 100644 webrtc/mbedtls/psa/crypto_compat.nim delete mode 100644 webrtc/mbedtls/psa/crypto_driver_contexts_composites.nim delete mode 100644 webrtc/mbedtls/psa/crypto_driver_contexts_key_derivation.nim delete mode 100644 webrtc/mbedtls/psa/crypto_driver_contexts_primitives.nim delete mode 100644 webrtc/mbedtls/psa/crypto_extra.nim delete mode 100644 webrtc/mbedtls/psa/crypto_platform.nim diff --git a/webrtc/mbedtls/aes.nim b/webrtc/mbedtls/aes.nim index 73cfa32..71d8367 100644 --- a/webrtc/mbedtls/aes.nim +++ b/webrtc/mbedtls/aes.nim @@ -1,32 +1,14 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} - -# Included but not used -# import "private_access" -# import "build_info" -# import "mbedtls_config" -# import "config_psa" -# import "check_config" -# import "platform_time" import "platform_time" + {.compile: "./mbedtls/library/aes.c".} {.compile: "./mbedtls/library/aesni.c".} -# Generated @ 2023-05-11T11:19:07+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/aes.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_AES_ENCRYPT* = 1 MBEDTLS_AES_DECRYPT* = 0 diff --git a/webrtc/mbedtls/aria.nim b/webrtc/mbedtls/aria.nim index 8930d13..015420a 100644 --- a/webrtc/mbedtls/aria.nim +++ b/webrtc/mbedtls/aria.nim @@ -1,24 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "platform_time" + {.compile: "./mbedtls/library/aria.c".} -# Generated @ 2023-05-11T11:19:07+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/aria.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ARIA_ENCRYPT* = 1 MBEDTLS_ARIA_DECRYPT* = 0 diff --git a/webrtc/mbedtls/asn1.nim b/webrtc/mbedtls/asn1.nim index 6912d77..58bd3b5 100644 --- a/webrtc/mbedtls/asn1.nim +++ b/webrtc/mbedtls/asn1.nim @@ -1,24 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "bignum" + {.compile: "./mbedtls/library/asn1parse.c".} -# Generated @ 2023-05-11T11:19:07+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/asn1.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_ASN1_OUT_OF_DATA* = -0x00000060 MBEDTLS_ERR_ASN1_UNEXPECTED_TAG* = -0x00000062 diff --git a/webrtc/mbedtls/asn1write.nim b/webrtc/mbedtls/asn1write.nim index 035c9e1..be962c6 100644 --- a/webrtc/mbedtls/asn1write.nim +++ b/webrtc/mbedtls/asn1write.nim @@ -1,26 +1,14 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "asn1" -import "platform_time" import "bignum" + {.compile: "./mbedtls/library/asn1write.c".} -# Generated @ 2023-05-11T11:19:07+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/asn1write.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + proc mbedtls_asn1_write_len*(p: ptr ptr byte; start: ptr byte; len: uint): cint {. importc, cdecl.} proc mbedtls_asn1_write_tag*(p: ptr ptr byte; start: ptr byte; tag: byte): cint {. diff --git a/webrtc/mbedtls/base64.nim b/webrtc/mbedtls/base64.nim index f652a61..f77896e 100644 --- a/webrtc/mbedtls/base64.nim +++ b/webrtc/mbedtls/base64.nim @@ -1,28 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -# import "build_info" -# import "mbedtls_config" -# import "config_psa" -# import "check_config" import "constant_time" + {.compile: "./mbedtls/library/base64.c".} -# Generated @ 2023-05-11T11:19:07+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/base64.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL* = -0x0000002A MBEDTLS_ERR_BASE64_INVALID_CHARACTER* = -0x0000002C diff --git a/webrtc/mbedtls/bignum.nim b/webrtc/mbedtls/bignum.nim index 72e7eae..2df9958 100644 --- a/webrtc/mbedtls/bignum.nim +++ b/webrtc/mbedtls/bignum.nim @@ -1,69 +1,18 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "md" +import "utils" + {.compile: "./mbedtls/library/bignum.c".} {.compile: "./mbedtls/library/bignum_core.c".} {.compile: "./mbedtls/library/constant_time.c".} -# Generated @ 2023-05-11T11:19:07+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/bignum.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(mbedtls_mpi_gen_prime_flag_t) + const MBEDTLS_ERR_MPI_FILE_IO_ERROR* = -0x00000002 MBEDTLS_ERR_MPI_BAD_INPUT_DATA* = -0x00000004 diff --git a/webrtc/mbedtls/build_info.nim b/webrtc/mbedtls/build_info.nim index 1cf7e72..3e73b60 100644 --- a/webrtc/mbedtls/build_info.nim +++ b/webrtc/mbedtls/build_info.nim @@ -1,22 +1,9 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -# Generated @ 2023-05-11T11:19:08+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/build_info.h - {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_VERSION_MAJOR* = 3 MBEDTLS_VERSION_MINOR* = 4 diff --git a/webrtc/mbedtls/camellia.nim b/webrtc/mbedtls/camellia.nim index d67bf18..6e13573 100644 --- a/webrtc/mbedtls/camellia.nim +++ b/webrtc/mbedtls/camellia.nim @@ -1,24 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "platform_time" + {.compile: "./mbedtls/library/camellia.c".} -# Generated @ 2023-05-11T11:19:08+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/camellia.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_CAMELLIA_ENCRYPT* = 1 MBEDTLS_CAMELLIA_DECRYPT* = 0 diff --git a/webrtc/mbedtls/ccm.nim b/webrtc/mbedtls/ccm.nim index 8366a69..1695358 100644 --- a/webrtc/mbedtls/ccm.nim +++ b/webrtc/mbedtls/ccm.nim @@ -1,30 +1,11 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -# import "private_access" -# import "build_info" -# import "mbedtls_config" -# import "config_psa" -# import "check_config" import "cipher" -# import "platform_util" -import "platform_time" -# Generated @ 2023-05-11T11:19:08+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ccm.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_CCM_DECRYPT* = 0 MBEDTLS_CCM_ENCRYPT* = 1 diff --git a/webrtc/mbedtls/chacha20.nim b/webrtc/mbedtls/chacha20.nim index d9c5806..c6ee624 100644 --- a/webrtc/mbedtls/chacha20.nim +++ b/webrtc/mbedtls/chacha20.nim @@ -1,24 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "platform_time" + {.compile: "./mbedtls/library/chacha20.c".} -# Generated @ 2023-05-11T11:19:08+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/chacha20.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA* = -0x00000051 type diff --git a/webrtc/mbedtls/chachapoly.nim b/webrtc/mbedtls/chachapoly.nim index 9cb4046..9c8860e 100644 --- a/webrtc/mbedtls/chachapoly.nim +++ b/webrtc/mbedtls/chachapoly.nim @@ -1,68 +1,17 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "poly1305" import "chacha20" +import "utils" + {.compile: "./mbedtls/library/chachapoly.c".} -# Generated @ 2023-05-11T11:19:08+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/chachapoly.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(mbedtls_chachapoly_mode_t) + const MBEDTLS_ERR_CHACHAPOLY_BAD_STATE* = -0x00000054 MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED* = -0x00000056 diff --git a/webrtc/mbedtls/check_config.nim b/webrtc/mbedtls/check_config.nim deleted file mode 100644 index 4e4b8f8..0000000 --- a/webrtc/mbedtls/check_config.nim +++ /dev/null @@ -1,22 +0,0 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -# Generated @ 2023-05-11T11:19:08+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/check_config.h - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} -type - mbedtls_iso_c_forbids_empty_translation_units* = cint -{.pop.} diff --git a/webrtc/mbedtls/cipher.nim b/webrtc/mbedtls/cipher.nim index 4715188..9ba99f5 100644 --- a/webrtc/mbedtls/cipher.nim +++ b/webrtc/mbedtls/cipher.nim @@ -1,27 +1,16 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "aes" import "aria" import "camellia" import "chachapoly" import "des" import "constant_time" -import "platform_time" +import "utils" + {.compile: "./mbedtls/library/ccm.c".} {.compile: "./mbedtls/library/gcm.c".} {.compile: "./mbedtls/library/nist_kw.c".} {.compile: "./mbedtls/library/cipher_wrap.c".} {.compile: "./mbedtls/library/cipher.c".} -# Generated @ 2023-05-11T11:19:08+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/cipher.h # proc 'mbedtls_cipher_info_get_type' skipped - static inline procs cannot work with '--noHeader | -H' # proc 'mbedtls_cipher_info_get_mode' skipped - static inline procs cannot work with '--noHeader | -H' @@ -38,60 +27,21 @@ import "platform_time" # proc 'mbedtls_cipher_get_name' skipped - static inline procs cannot work with '--noHeader | -H' # proc 'mbedtls_cipher_get_key_bitlen' skipped - static inline procs cannot work with '--noHeader | -H' # proc 'mbedtls_cipher_get_operation' skipped - static inline procs cannot work with '--noHeader | -H' + + {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(mbedtls_cipher_id_t) defineEnum(mbedtls_cipher_type_t) defineEnum(mbedtls_cipher_mode_t) defineEnum(mbedtls_cipher_padding_t) defineEnum(mbedtls_operation_t) defineEnum(Enum_cipherh1) + const MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE* = -0x00006080 MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA* = -0x00006100 diff --git a/webrtc/mbedtls/cmac.nim b/webrtc/mbedtls/cmac.nim index 3fa8e08..b186ecc 100644 --- a/webrtc/mbedtls/cmac.nim +++ b/webrtc/mbedtls/cmac.nim @@ -1,25 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "cipher" -import "platform_time" + {.compile: "./mbedtls/library/cmac.c".} -# Generated @ 2023-05-11T11:19:09+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/cmac.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_AES_BLOCK_SIZE* = 16 MBEDTLS_DES3_BLOCK_SIZE* = 8 diff --git a/webrtc/mbedtls/compat_2_x.nim b/webrtc/mbedtls/compat_2_x.nim deleted file mode 100644 index 94a6779..0000000 --- a/webrtc/mbedtls/compat_2_x.nim +++ /dev/null @@ -1,42 +0,0 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -# Generated @ 2023-05-11T11:19:09+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/compat-2.x.h - -# const 'mbedtls_ctr_drbg_update_ret' has unsupported value 'mbedtls_ctr_drbg_update' -# const 'mbedtls_hmac_drbg_update_ret' has unsupported value 'mbedtls_hmac_drbg_update' -# const 'mbedtls_md5_starts_ret' has unsupported value 'mbedtls_md5_starts' -# const 'mbedtls_md5_update_ret' has unsupported value 'mbedtls_md5_update' -# const 'mbedtls_md5_finish_ret' has unsupported value 'mbedtls_md5_finish' -# const 'mbedtls_md5_ret' has unsupported value 'mbedtls_md5' -# const 'mbedtls_ripemd160_starts_ret' has unsupported value 'mbedtls_ripemd160_starts' -# const 'mbedtls_ripemd160_update_ret' has unsupported value 'mbedtls_ripemd160_update' -# const 'mbedtls_ripemd160_finish_ret' has unsupported value 'mbedtls_ripemd160_finish' -# const 'mbedtls_ripemd160_ret' has unsupported value 'mbedtls_ripemd160' -# const 'mbedtls_sha1_starts_ret' has unsupported value 'mbedtls_sha1_starts' -# const 'mbedtls_sha1_update_ret' has unsupported value 'mbedtls_sha1_update' -# const 'mbedtls_sha1_finish_ret' has unsupported value 'mbedtls_sha1_finish' -# const 'mbedtls_sha1_ret' has unsupported value 'mbedtls_sha1' -# const 'mbedtls_sha256_starts_ret' has unsupported value 'mbedtls_sha256_starts' -# const 'mbedtls_sha256_update_ret' has unsupported value 'mbedtls_sha256_update' -# const 'mbedtls_sha256_finish_ret' has unsupported value 'mbedtls_sha256_finish' -# const 'mbedtls_sha256_ret' has unsupported value 'mbedtls_sha256' -# const 'mbedtls_sha512_starts_ret' has unsupported value 'mbedtls_sha512_starts' -# const 'mbedtls_sha512_update_ret' has unsupported value 'mbedtls_sha512_update' -# const 'mbedtls_sha512_finish_ret' has unsupported value 'mbedtls_sha512_finish' -# const 'mbedtls_sha512_ret' has unsupported value 'mbedtls_sha512' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} -{.pop.} diff --git a/webrtc/mbedtls/config_psa.nim b/webrtc/mbedtls/config_psa.nim index 3e22681..d4ba28a 100644 --- a/webrtc/mbedtls/config_psa.nim +++ b/webrtc/mbedtls/config_psa.nim @@ -1,22 +1,9 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -# Generated @ 2023-05-11T11:19:09+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/config_psa.h - {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_PSA_BUILTIN_ALG_HMAC* = 1 PSA_WANT_ALG_HMAC* = 1 diff --git a/webrtc/mbedtls/constant_time.nim b/webrtc/mbedtls/constant_time.nim index a39047a..d03626d 100644 --- a/webrtc/mbedtls/constant_time.nim +++ b/webrtc/mbedtls/constant_time.nim @@ -1,21 +1,8 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "bignum" -# {.compile: "./mbedtls/library/constant_time.c".} -# Generated @ 2023-05-11T11:19:09+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/constant_time.h +# TODO: Remove bignum, it's not used in this file. {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} diff --git a/webrtc/mbedtls/ctr_drbg.nim b/webrtc/mbedtls/ctr_drbg.nim index de4498b..3095af6 100644 --- a/webrtc/mbedtls/ctr_drbg.nim +++ b/webrtc/mbedtls/ctr_drbg.nim @@ -1,33 +1,15 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "aes" -import "platform_util" -import "platform_time" import "entropy" -import "md" +# TODO: Remove entropy, it's not used in this file. + {.compile: "./mbedtls/library/ctr_drbg.c".} -# Generated @ 2023-05-11T11:19:09+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ctr_drbg.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED* = -0x00000034 MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG* = -0x00000036 diff --git a/webrtc/mbedtls/debug.nim b/webrtc/mbedtls/debug.nim index 2a25f66..0dd9a9e 100644 --- a/webrtc/mbedtls/debug.nim +++ b/webrtc/mbedtls/debug.nim @@ -1,101 +1,20 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "ssl" -import "platform_util" -import "platform_time" -import "private_access" import "bignum" import "ecp" -import "ssl_ciphersuites" -import "pk" -import "md" -import "rsa" -import "ecdsa" -import "cipher" import "x509_crt" -import "x509" -import "asn1" -import "x509_crl" -import "dhm" import "ecdh" -import "md5" -import "ripemd160" -import "sha1" -import "sha256" -import "sha512" -import "cmac" -import "gcm" -import "ccm" -import "chachapoly" -import "poly1305" -import "chacha20" -import "ecjpake" -{.compile: "./mbedtls/library/debug.c".} -# Generated @ 2023-05-11T11:19:09+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/debug.h +import "utils" # const 'MBEDTLS_PRINTF_MS_TIME' has unsupported value 'PRId64' + {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(mbedtls_debug_ecdh_attr) + const MBEDTLS_PRINTF_SIZET* = "zu" MBEDTLS_PRINTF_LONGLONG* = "lld" diff --git a/webrtc/mbedtls/des.nim b/webrtc/mbedtls/des.nim index d1e4196..7ec04b0 100644 --- a/webrtc/mbedtls/des.nim +++ b/webrtc/mbedtls/des.nim @@ -1,30 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" -import "platform_util" import "platform_time" + {.compile: "./mbedtls/library/des.c".} -# Generated @ 2023-05-11T11:19:09+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/des.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_DES_ENCRYPT* = 1 MBEDTLS_DES_DECRYPT* = 0 diff --git a/webrtc/mbedtls/dhm.nim b/webrtc/mbedtls/dhm.nim index f839722..7aaab62 100644 --- a/webrtc/mbedtls/dhm.nim +++ b/webrtc/mbedtls/dhm.nim @@ -1,19 +1,9 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "asn1" import "pem" import "bignum" +import "utils" + {.compile: "./mbedtls/library/dhm.c".} -# Generated @ 2023-05-11T11:19:09+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/dhm.h # const 'MBEDTLS_DHM_RFC3526_MODP_2048_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' # const 'MBEDTLS_DHM_RFC3526_MODP_2048_G_BIN' has unsupported value '{ 0x02 }' @@ -31,55 +21,15 @@ import "bignum" # const 'MBEDTLS_DHM_RFC7919_FFDHE6144_G_BIN' has unsupported value '{ 0x02 }' # const 'MBEDTLS_DHM_RFC7919_FFDHE8192_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02, 0x0B, 0xFD, 0x64, 0xB6, 0x45, 0x03, 0x6C, 0x7A, 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A, 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6, 0x3B, 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8, 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C, 0xB3, 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, 0x3A, 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71, 0x9B, 0x1F, 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F, 0x38, 0x81, 0x47, 0xFB, 0x4C, 0xFD, 0xB4, 0x77, 0xA5, 0x24, 0x71, 0xF7, 0xA9, 0xA9, 0x69, 0x10, 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8, 0xA0, 0x0E, 0xF0, 0x92, 0x35, 0x05, 0x11, 0xE3, 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E, 0x7F, 0xB2, 0x9F, 0x8C, 0x18, 0x30, 0x23, 0xC3, 0x58, 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4, 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, 0xBB, 0xC1, 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, 0x92, 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, 0xF6, 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82, 0x0A, 0xE8, 0xDB, 0x58, 0x47, 0xA6, 0x7C, 0xBE, 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C, 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E, 0x62, 0x29, 0x2C, 0x31, 0x15, 0x62, 0xA8, 0x46, 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A, 0xE4, 0x9F, 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17, 0x8C, 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03, 0xEC, 0x9D, 0x18, 0x10, 0xC6, 0x27, 0x2B, 0x04, 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, 0xD6, 0x3F, 0xDD, 0x4A, 0x8E, 0x9A, 0xDB, 0x1E, 0x69, 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1, 0xA4, 0x1D, 0x57, 0x0D, 0x79, 0x38, 0xDA, 0xD4, 0xA4, 0x0E, 0x32, 0x9C, 0xCF, 0xF4, 0x6A, 0xAA, 0x36, 0xAD, 0x00, 0x4C, 0xF6, 0x00, 0xC8, 0x38, 0x1E, 0x42, 0x5A, 0x31, 0xD9, 0x51, 0xAE, 0x64, 0xFD, 0xB2, 0x3F, 0xCE, 0xC9, 0x50, 0x9D, 0x43, 0x68, 0x7F, 0xEB, 0x69, 0xED, 0xD1, 0xCC, 0x5E, 0x0B, 0x8C, 0xC3, 0xBD, 0xF6, 0x4B, 0x10, 0xEF, 0x86, 0xB6, 0x31, 0x42, 0xA3, 0xAB, 0x88, 0x29, 0x55, 0x5B, 0x2F, 0x74, 0x7C, 0x93, 0x26, 0x65, 0xCB, 0x2C, 0x0F, 0x1C, 0xC0, 0x1B, 0xD7, 0x02, 0x29, 0x38, 0x88, 0x39, 0xD2, 0xAF, 0x05, 0xE4, 0x54, 0x50, 0x4A, 0xC7, 0x8B, 0x75, 0x82, 0x82, 0x28, 0x46, 0xC0, 0xBA, 0x35, 0xC3, 0x5F, 0x5C, 0x59, 0x16, 0x0C, 0xC0, 0x46, 0xFD, 0x82, 0x51, 0x54, 0x1F, 0xC6, 0x8C, 0x9C, 0x86, 0xB0, 0x22, 0xBB, 0x70, 0x99, 0x87, 0x6A, 0x46, 0x0E, 0x74, 0x51, 0xA8, 0xA9, 0x31, 0x09, 0x70, 0x3F, 0xEE, 0x1C, 0x21, 0x7E, 0x6C, 0x38, 0x26, 0xE5, 0x2C, 0x51, 0xAA, 0x69, 0x1E, 0x0E, 0x42, 0x3C, 0xFC, 0x99, 0xE9, 0xE3, 0x16, 0x50, 0xC1, 0x21, 0x7B, 0x62, 0x48, 0x16, 0xCD, 0xAD, 0x9A, 0x95, 0xF9, 0xD5, 0xB8, 0x01, 0x94, 0x88, 0xD9, 0xC0, 0xA0, 0xA1, 0xFE, 0x30, 0x75, 0xA5, 0x77, 0xE2, 0x31, 0x83, 0xF8, 0x1D, 0x4A, 0x3F, 0x2F, 0xA4, 0x57, 0x1E, 0xFC, 0x8C, 0xE0, 0xBA, 0x8A, 0x4F, 0xE8, 0xB6, 0x85, 0x5D, 0xFE, 0x72, 0xB0, 0xA6, 0x6E, 0xDE, 0xD2, 0xFB, 0xAB, 0xFB, 0xE5, 0x8A, 0x30, 0xFA, 0xFA, 0xBE, 0x1C, 0x5D, 0x71, 0xA8, 0x7E, 0x2F, 0x74, 0x1E, 0xF8, 0xC1, 0xFE, 0x86, 0xFE, 0xA6, 0xBB, 0xFD, 0xE5, 0x30, 0x67, 0x7F, 0x0D, 0x97, 0xD1, 0x1D, 0x49, 0xF7, 0xA8, 0x44, 0x3D, 0x08, 0x22, 0xE5, 0x06, 0xA9, 0xF4, 0x61, 0x4E, 0x01, 0x1E, 0x2A, 0x94, 0x83, 0x8F, 0xF8, 0x8C, 0xD6, 0x8C, 0x8B, 0xB7, 0xC5, 0xC6, 0x42, 0x4C, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' # const 'MBEDTLS_DHM_RFC7919_FFDHE8192_G_BIN' has unsupported value '{ 0x02 }' + {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(mbedtls_dhm_parameter) + const MBEDTLS_ERR_DHM_BAD_INPUT_DATA* = -0x00003080 MBEDTLS_ERR_DHM_READ_PARAMS_FAILED* = -0x00003100 diff --git a/webrtc/mbedtls/ecdh.nim b/webrtc/mbedtls/ecdh.nim index 18148b9..bea624e 100644 --- a/webrtc/mbedtls/ecdh.nim +++ b/webrtc/mbedtls/ecdh.nim @@ -1,74 +1,18 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "ecp" import "bignum" +import "utils" + {.compile: "./mbedtls/library/ecdh.c".} -# Generated @ 2023-05-11T11:19:09+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ecdh.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(mbedtls_ecdh_side) defineEnum(mbedtls_ecdh_variant) + const MBEDTLS_ECDH_OURS* = (0).mbedtls_ecdh_side MBEDTLS_ECDH_THEIRS* = (MBEDTLS_ECDH_OURS + 1).mbedtls_ecdh_side diff --git a/webrtc/mbedtls/ecdsa.nim b/webrtc/mbedtls/ecdsa.nim index 90edde1..93d2a27 100644 --- a/webrtc/mbedtls/ecdsa.nim +++ b/webrtc/mbedtls/ecdsa.nim @@ -1,31 +1,17 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "ecp" import "bignum" import "md" -import "platform_time" import "hmac_drbg" -import "asn1" import "asn1write" + {.compile: "./mbedtls/library/ecdsa.c".} -# Generated @ 2023-05-11T11:19:10+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ecdsa.h -# const 'MBEDTLS_ECDSA_MAX_LEN' has unsupported value 'MBEDTLS_ECDSA_MAX_SIG_LEN(MBEDTLS_ECP_MAX_BITS)' {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + type mbedtls_ecdsa_context* = mbedtls_ecp_keypair mbedtls_ecdsa_restart_ctx* = object diff --git a/webrtc/mbedtls/ecjpake.nim b/webrtc/mbedtls/ecjpake.nim index aff083e..a161a55 100644 --- a/webrtc/mbedtls/ecjpake.nim +++ b/webrtc/mbedtls/ecjpake.nim @@ -1,71 +1,20 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "ecp" import "bignum" import "md" import "hash_info" import "platform_time" +import "utils" + {.compile: "./mbedtls/library/ecjpake.c".} -# Generated @ 2023-05-11T11:19:10+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ecjpake.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(mbedtls_ecjpake_role) + const MBEDTLS_ECJPAKE_CLIENT* = (0).mbedtls_ecjpake_role MBEDTLS_ECJPAKE_SERVER* = (MBEDTLS_ECJPAKE_CLIENT + 1).mbedtls_ecjpake_role diff --git a/webrtc/mbedtls/ecp.nim b/webrtc/mbedtls/ecp.nim index beb0884..fe7a88f 100644 --- a/webrtc/mbedtls/ecp.nim +++ b/webrtc/mbedtls/ecp.nim @@ -1,75 +1,19 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "bignum" +import "utils" + {.compile: "./mbedtls/library/ecp.c".} {.compile: "./mbedtls/library/ecp_curves.c".} -# Generated @ 2023-05-11T11:19:10+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ecp.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(mbedtls_ecp_group_id) defineEnum(mbedtls_ecp_curve_type) defineEnum(mbedtls_ecp_modulus_type) + const MBEDTLS_ERR_ECP_BAD_INPUT_DATA* = -0x00004F80 MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL* = -0x00004F00 diff --git a/webrtc/mbedtls/entropy.nim b/webrtc/mbedtls/entropy.nim index db307a2..fd6281e 100644 --- a/webrtc/mbedtls/entropy.nim +++ b/webrtc/mbedtls/entropy.nim @@ -1,34 +1,17 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "md" -import "platform_util" -import "platform_time" + {.compile: "./mbedtls/library/entropy.c".} {.compile: "./mbedtls/library/entropy_poll.c".} -# Generated @ 2023-05-11T11:19:10+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/entropy.h # const 'MBEDTLS_ENTROPY_MD' has unsupported value 'MBEDTLS_MD_SHA512' # const 'MBEDTLS_ENTROPY_SOURCE_MANUAL' has unsupported value 'MBEDTLS_ENTROPY_MAX_SOURCES' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.push hint[ConvFromXtoItselfNotNeeded]: off.} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ENTROPY_BLOCK_SIZE* = 64 MBEDTLS_ERR_ENTROPY_SOURCE_FAILED* = -0x0000003C diff --git a/webrtc/mbedtls/error.nim b/webrtc/mbedtls/error.nim index cf0242e..5b0f608 100644 --- a/webrtc/mbedtls/error.nim +++ b/webrtc/mbedtls/error.nim @@ -1,28 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" {.compile: "./mbedtls/library/error.c".} -# Generated @ 2023-05-11T11:19:10+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/error.h # proc 'mbedtls_error_add' skipped - static inline procs cannot work with '--noHeader | -H' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.push hint[ConvFromXtoItselfNotNeeded]: off.} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_ERROR_GENERIC_ERROR* = -0x00000001 MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED* = -0x0000006E diff --git a/webrtc/mbedtls/gcm.nim b/webrtc/mbedtls/gcm.nim index 0e3b790..21e29c4 100644 --- a/webrtc/mbedtls/gcm.nim +++ b/webrtc/mbedtls/gcm.nim @@ -1,31 +1,11 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "cipher" -import "platform_util" -import "platform_time" -#{.compile: "./mbedtls/library/gcm.c".} -# Generated @ 2023-05-11T11:19:10+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/gcm.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_GCM_ENCRYPT* = 1 MBEDTLS_GCM_DECRYPT* = 0 diff --git a/webrtc/mbedtls/hash_info.nim b/webrtc/mbedtls/hash_info.nim index 202cd21..536b204 100644 --- a/webrtc/mbedtls/hash_info.nim +++ b/webrtc/mbedtls/hash_info.nim @@ -1,3 +1,4 @@ +# TODO: Put the .compile. pragma in one of the file using it without breaking everything {.compile: "./mbedtls/library/hash_info.c".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} diff --git a/webrtc/mbedtls/hkdf.nim b/webrtc/mbedtls/hkdf.nim index c3c685b..2b2e3cf 100644 --- a/webrtc/mbedtls/hkdf.nim +++ b/webrtc/mbedtls/hkdf.nim @@ -1,31 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "md" -import "private_access" -import "platform_util" -import "platform_time" + {.compile: "./mbedtls/library/hkdf.c".} -# Generated @ 2023-05-11T11:19:10+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/hkdf.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_HKDF_BAD_INPUT_DATA* = -0x00005F80 proc mbedtls_hkdf*(md: ptr mbedtls_md_info_t; salt: ptr byte; salt_len: uint; diff --git a/webrtc/mbedtls/hmac_drbg.nim b/webrtc/mbedtls/hmac_drbg.nim index b456271..009d96f 100644 --- a/webrtc/mbedtls/hmac_drbg.nim +++ b/webrtc/mbedtls/hmac_drbg.nim @@ -1,31 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "md" -import "platform_util" -import "platform_time" + {.compile: "./mbedtls/library/hmac_drbg.c".} -# Generated @ 2023-05-11T11:19:11+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/hmac_drbg.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG* = -0x00000003 MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG* = -0x00000005 diff --git a/webrtc/mbedtls/lms.nim b/webrtc/mbedtls/lms.nim index 8eacfda..8713064 100644 --- a/webrtc/mbedtls/lms.nim +++ b/webrtc/mbedtls/lms.nim @@ -1,69 +1,18 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "psa/crypto" +import "utils" + {.compile: "./mbedtls/library/lms.c".} {.compile: "./mbedtls/library/lmots.c".} -# Generated @ 2023-05-11T11:19:11+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/lms.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(mbedtls_lms_algorithm_type_t) defineEnum(mbedtls_lmots_algorithm_type_t) + const MBEDTLS_ERR_LMS_BAD_INPUT_DATA* = -0x00000011 MBEDTLS_ERR_LMS_OUT_OF_PRIVATE_KEYS* = -0x00000013 diff --git a/webrtc/mbedtls/mbedtls_config.nim b/webrtc/mbedtls/mbedtls_config.nim index b5c38ca..808f7ff 100644 --- a/webrtc/mbedtls/mbedtls_config.nim +++ b/webrtc/mbedtls/mbedtls_config.nim @@ -1,22 +1,9 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -# Generated @ 2023-05-11T11:19:11+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/mbedtls_config.h - {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT* = 0 MBEDTLS_SSL_MAX_EARLY_DATA_SIZE* = 1024 diff --git a/webrtc/mbedtls/md.nim b/webrtc/mbedtls/md.nim index f1fb65e..1b7e588 100644 --- a/webrtc/mbedtls/md.nim +++ b/webrtc/mbedtls/md.nim @@ -1,78 +1,21 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "platform_time" import "ripemd160" import "sha1" import "sha256" import "sha512" import "md5" -# {.compile: "./mbedtls/library/ripemd160.c".} -# {.compile: "./mbedtls/library/sha1.c".} -# {.compile: "./mbedtls/library/sha256.c".} -# {.compile: "./mbedtls/library/sha512.c".} -# {.compile: "./mbedtls/library/md5.c".} +import "utils" + {.compile: "./mbedtls/library/md.c".} -# Generated @ 2023-05-11T11:19:11+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/md.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(mbedtls_md_type_t) defineEnum(mbedtls_md_engine_t) + const MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE* = -0x00005080 MBEDTLS_ERR_MD_BAD_INPUT_DATA* = -0x00005100 diff --git a/webrtc/mbedtls/md5.nim b/webrtc/mbedtls/md5.nim index 3e1c747..50974bd 100644 --- a/webrtc/mbedtls/md5.nim +++ b/webrtc/mbedtls/md5.nim @@ -1,24 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "platform_time" + {.compile: "./mbedtls/library/md5.c".} -# Generated @ 2023-05-11T11:19:11+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/md5.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + type mbedtls_md5_context* {.bycopy.} = object private_total*: array[2, uint32] diff --git a/webrtc/mbedtls/memory_buffer_alloc.nim b/webrtc/mbedtls/memory_buffer_alloc.nim index b1ca866..5ef0373 100644 --- a/webrtc/mbedtls/memory_buffer_alloc.nim +++ b/webrtc/mbedtls/memory_buffer_alloc.nim @@ -1,27 +1,11 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" {.compile: "./mbedtls/library/memory_buffer_alloc.c".} -# Generated @ 2023-05-11T11:19:11+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/memory_buffer_alloc.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_MEMORY_ALIGN_MULTIPLE* = 4 MBEDTLS_MEMORY_VERIFY_NONE* = 0 diff --git a/webrtc/mbedtls/net_sockets.nim b/webrtc/mbedtls/net_sockets.nim index 588e55c..38dcc7d 100644 --- a/webrtc/mbedtls/net_sockets.nim +++ b/webrtc/mbedtls/net_sockets.nim @@ -1,57 +1,11 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" -import "ssl" -import "platform_util" -import "platform_time" -import "bignum" -import "ecp" -import "ssl_ciphersuites" -import "pk" -import "md" -import "rsa" -import "ecdsa" -import "cipher" -import "x509_crt" -import "x509" -import "asn1" -import "x509_crl" -import "dhm" -import "ecdh" -import "md5" -import "ripemd160" -import "sha1" -import "sha256" -import "sha512" -import "cmac" -import "gcm" -import "ccm" -import "chachapoly" -import "poly1305" -import "chacha20" -import "ecjpake" {.compile: "./mbedtls/library/net_sockets.c".} -# Generated @ 2023-05-11T11:19:11+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/net_sockets.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_NET_SOCKET_FAILED* = -0x00000042 MBEDTLS_ERR_NET_CONNECT_FAILED* = -0x00000044 diff --git a/webrtc/mbedtls/nist_kw.nim b/webrtc/mbedtls/nist_kw.nim index f610f92..b35c31a 100644 --- a/webrtc/mbedtls/nist_kw.nim +++ b/webrtc/mbedtls/nist_kw.nim @@ -1,73 +1,14 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "cipher" -import "platform_util" -import "platform_time" -# Generated @ 2023-05-11T11:19:11+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/nist_kw.h +import "utils" {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(mbedtls_nist_kw_mode_t) + const MBEDTLS_KW_MODE_KW* = (0).mbedtls_nist_kw_mode_t MBEDTLS_KW_MODE_KWP* = (1).mbedtls_nist_kw_mode_t diff --git a/webrtc/mbedtls/oid.nim b/webrtc/mbedtls/oid.nim index de7cc44..39ae8e3 100644 --- a/webrtc/mbedtls/oid.nim +++ b/webrtc/mbedtls/oid.nim @@ -1,20 +1,8 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "asn1" import "pk" import "md" import "ecp" import "cipher" -# Generated @ 2023-05-11T11:19:12+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/oid.h # const 'MBEDTLS_OID_RSA_COMPANY' has unsupported value 'MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US MBEDTLS_OID_ORG_RSA_DATA_SECURITY' # const 'MBEDTLS_OID_ANSI_X9_62' has unsupported value 'MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US MBEDTLS_OID_ORG_ANSI_X9_62' @@ -167,12 +155,13 @@ import "cipher" # const 'MBEDTLS_OID_ECDSA_SHA256' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x02"' # const 'MBEDTLS_OID_ECDSA_SHA384' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x03"' # const 'MBEDTLS_OID_ECDSA_SHA512' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x04"' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.push hint[ConvFromXtoItselfNotNeeded]: off.} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_OID_NOT_FOUND* = -0x0000002E MBEDTLS_ERR_OID_BUF_TOO_SMALL* = -0x0000000B diff --git a/webrtc/mbedtls/pem.nim b/webrtc/mbedtls/pem.nim index f927b76..8654fb0 100644 --- a/webrtc/mbedtls/pem.nim +++ b/webrtc/mbedtls/pem.nim @@ -1,28 +1,17 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "aes" import "base64" import "des" -import "constant_time" + {.compile: "./mbedtls/library/pem.c".} -# Generated @ 2023-05-11T11:19:12+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/pem.h # proc 'mbedtls_pem_get_buffer' skipped - static inline procs cannot work with '--noHeader | -H' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.push hint[ConvFromXtoItselfNotNeeded]: off.} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT* = -0x00001080 MBEDTLS_ERR_PEM_INVALID_DATA* = -0x00001100 diff --git a/webrtc/mbedtls/pk.nim b/webrtc/mbedtls/pk.nim index fe8e9e4..2a33ec4 100644 --- a/webrtc/mbedtls/pk.nim +++ b/webrtc/mbedtls/pk.nim @@ -1,83 +1,29 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "pem" import "md" -import "platform_time" -import "rsa" -import "ecp" -import "ecdh" import "ecdsa" import "psa_util" import "psa/crypto" +import "utils" + {.compile: "./mbedtls/library/pk_wrap.c".} {.compile: "./mbedtls/library/pk.c".} {.compile: "./mbedtls/library/pkparse.c".} {.compile: "./mbedtls/library/pkwrite.c".} -# Generated @ 2023-05-11T11:19:12+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/pk.h # const 'MBEDTLS_PK_SIGNATURE_MAX_SIZE' has unsupported value 'MBEDTLS_MPI_MAX_SIZE' # proc 'mbedtls_pk_get_len' skipped - static inline procs cannot work with '--noHeader | -H' # proc 'mbedtls_pk_rsa' skipped - static inline procs cannot work with '--noHeader | -H' # proc 'mbedtls_pk_ec' skipped - static inline procs cannot work with '--noHeader | -H' + {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(mbedtls_pk_type_t) defineEnum(mbedtls_pk_debug_type) + const MBEDTLS_ERR_PK_ALLOC_FAILED* = -0x00003F80 MBEDTLS_ERR_PK_TYPE_MISMATCH* = -0x00003F00 diff --git a/webrtc/mbedtls/pkcs12.nim b/webrtc/mbedtls/pkcs12.nim index b082ba0..e3c2d54 100644 --- a/webrtc/mbedtls/pkcs12.nim +++ b/webrtc/mbedtls/pkcs12.nim @@ -1,29 +1,18 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "md" import "platform_time" import "cipher" import "asn1" import "ctr_drbg" import "hash_info" + {.compile: "./mbedtls/library/pkcs12.c".} -# Generated @ 2023-05-11T11:19:12+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/pkcs12.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA* = -0x00001F80 MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE* = -0x00001F00 diff --git a/webrtc/mbedtls/pkcs5.nim b/webrtc/mbedtls/pkcs5.nim index 275f8e3..36986c4 100644 --- a/webrtc/mbedtls/pkcs5.nim +++ b/webrtc/mbedtls/pkcs5.nim @@ -1,30 +1,17 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "asn1" -import "platform_time" import "md" import "cipher" import "ctr_drbg" import "rsa" -import "hash_info" + {.compile: "./mbedtls/library/pkcs5.c".} -# Generated @ 2023-05-11T11:19:12+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/pkcs5.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA* = -0x00002F80 MBEDTLS_ERR_PKCS5_INVALID_FORMAT* = -0x00002F00 diff --git a/webrtc/mbedtls/pkcs7.nim b/webrtc/mbedtls/pkcs7.nim index 7bad6b6..217b1f2 100644 --- a/webrtc/mbedtls/pkcs7.nim +++ b/webrtc/mbedtls/pkcs7.nim @@ -1,76 +1,19 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "asn1" -import "platform_time" import "x509" -import "pk" -import "md" -import "rsa" -import "ecp" -import "ecdsa" import "x509_crt" import "x509_crl" +import "utils" + {.compile: "./mbedtls/library/pkcs7.c".} -# Generated @ 2023-05-11T11:19:12+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/pkcs7.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(mbedtls_pkcs7_type) + const MBEDTLS_ERR_PKCS7_INVALID_FORMAT* = -0x00005300 MBEDTLS_ERR_PKCS7_FEATURE_UNAVAILABLE* = -0x00005380 diff --git a/webrtc/mbedtls/platform.nim b/webrtc/mbedtls/platform.nim index c28a78d..7bc2b60 100644 --- a/webrtc/mbedtls/platform.nim +++ b/webrtc/mbedtls/platform.nim @@ -1,22 +1,6 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "platform_time" + {.compile: "./mbedtls/library/platform.c".} -# Generated @ 2023-05-11T11:19:12+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/platform.h # const 'MBEDTLS_PLATFORM_STD_SNPRINTF' has unsupported value 'snprintf' # const 'MBEDTLS_PLATFORM_STD_VSNPRINTF' has unsupported value 'vsnprintf' @@ -41,12 +25,13 @@ import "platform_time" # const 'mbedtls_exit' has unsupported value 'exit' # const 'MBEDTLS_EXIT_SUCCESS' has unsupported value 'MBEDTLS_PLATFORM_STD_EXIT_SUCCESS' # const 'MBEDTLS_EXIT_FAILURE' has unsupported value 'MBEDTLS_PLATFORM_STD_EXIT_FAILURE' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.push hint[ConvFromXtoItselfNotNeeded]: off.} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_PLATFORM_STD_NV_SEED_FILE* = "seedfile" type diff --git a/webrtc/mbedtls/platform_time.nim b/webrtc/mbedtls/platform_time.nim index db439b7..dff2cec 100644 --- a/webrtc/mbedtls/platform_time.nim +++ b/webrtc/mbedtls/platform_time.nim @@ -1,21 +1,5 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -# import "build_info" -# import "mbedtls_config" -# import "config_psa" -# import "check_config" {.used.} {.compile: "./mbedtls/library/platform_util.c".} -# Generated @ 2023-05-11T11:19:12+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/platform_time.h # const 'mbedtls_time' has unsupported value 'time' {.push hint[ConvFromXtoItselfNotNeeded]: off.} @@ -23,10 +7,10 @@ import std/time_t as std_time_t type time_t* = std_time_t.Time - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + type mbedtls_time_t* = time_t mbedtls_ms_time_t* = int64 diff --git a/webrtc/mbedtls/platform_util.nim b/webrtc/mbedtls/platform_util.nim index b79f2a4..354694b 100644 --- a/webrtc/mbedtls/platform_util.nim +++ b/webrtc/mbedtls/platform_util.nim @@ -1,31 +1,16 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -type tm {.importc: "struct tm", header: "".} = object -# import "build_info" -# import "mbedtls_config" -# import "config_psa" -# import "check_config" import "platform_time" -# {.compile: "./mbedtls/library/platform_util.c".} -# Generated @ 2023-05-11T11:19:12+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/platform_util.h # const 'MBEDTLS_CHECK_RETURN' has unsupported value '__attribute__((__warn_unused_result__))' # const 'MBEDTLS_CHECK_RETURN_CRITICAL' has unsupported value 'MBEDTLS_CHECK_RETURN' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.push hint[ConvFromXtoItselfNotNeeded]: off.} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + +type tm {.importc: "struct tm", header: "".} = object + proc mbedtls_platform_zeroize*(buf: pointer; len: uint) {.importc, cdecl.} proc mbedtls_platform_gmtime_r*(tt: ptr mbedtls_time_t; tm_buf: ptr tm): ptr tm {. importc, cdecl.} diff --git a/webrtc/mbedtls/poly1305.nim b/webrtc/mbedtls/poly1305.nim index 98c5188..e3a35ec 100644 --- a/webrtc/mbedtls/poly1305.nim +++ b/webrtc/mbedtls/poly1305.nim @@ -1,24 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "md" + {.compile: "./mbedtls/library/poly1305.c".} -# Generated @ 2023-05-11T11:19:12+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/poly1305.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA* = -0x00000057 type diff --git a/webrtc/mbedtls/private_access.nim b/webrtc/mbedtls/private_access.nim deleted file mode 100644 index cfdc0e1..0000000 --- a/webrtc/mbedtls/private_access.nim +++ /dev/null @@ -1,20 +0,0 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -# Generated @ 2023-05-11T11:19:13+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/private_access.h - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto.nim b/webrtc/mbedtls/psa/crypto.nim index 4ab1c00..39ba003 100644 --- a/webrtc/mbedtls/psa/crypto.nim +++ b/webrtc/mbedtls/psa/crypto.nim @@ -1,30 +1,11 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "crypto_types" -import "crypto_values" -import "crypto_sizes" import "crypto_struct" -import "crypto_driver_contexts_primitives" -import "crypto_driver_common" -import "crypto_sizes" -import "crypto_builtin_primitives" -import "crypto_driver_contexts_composites" -import "crypto_builtin_composites" -import "crypto_driver_contexts_key_derivation" import "../pk" import "../ecp" -import "../rsa" import "../ecdh" import "../cmac" -import "../cipher" -import "../ctr_drbg" +import "../utils" + {.compile: "./mbedtls/library/psa_crypto.c".} {.compile: "./mbedtls/library/psa_crypto_hash.c".} {.compile: "./mbedtls/library/psa_crypto_slot_management.c".} @@ -37,65 +18,22 @@ import "../ctr_drbg" {.compile: "./mbedtls/library/psa_crypto_ecp.c".} {.compile: "./mbedtls/library/psa_crypto_aead.c".} {.compile: "./mbedtls/library/psa_crypto_cipher.c".} -# Generated @ 2023-05-12T13:12:42+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.pragma: impcryptoHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto.h".} {.pragma: impcrypto_compatHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_compat.h".} {.pragma: impcrypto_extraHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_extra.h".} + {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(psa_jpake_step) defineEnum(psa_jpake_state) defineEnum(psa_jpake_sequence) defineEnum(psa_crypto_driver_pake_step) + const PSA_CRYPTO_API_VERSION_MAJOR* = 1 PSA_CRYPTO_API_VERSION_MINOR* = 0 diff --git a/webrtc/mbedtls/psa/crypto_builtin_composites.nim b/webrtc/mbedtls/psa/crypto_builtin_composites.nim index 47551bf..16147af 100644 --- a/webrtc/mbedtls/psa/crypto_builtin_composites.nim +++ b/webrtc/mbedtls/psa/crypto_builtin_composites.nim @@ -1,27 +1,17 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -# Generated @ 2023-05-12T13:12:43+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_builtin_composites.h - # const 'MBEDTLS_PSA_HMAC_OPERATION_INIT' has unsupported value '{ 0, PSA_HASH_OPERATION_INIT, { 0 } }' # const 'MBEDTLS_PSA_MAC_OPERATION_INIT' has unsupported value '{ 0, { 0 } }' # const 'MBEDTLS_PSA_AEAD_OPERATION_INIT' has unsupported value '{ 0, 0, 0, 0, { 0 } }' # const 'MBEDTLS_PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT' has unsupported value '{ 0 }' # const 'MBEDTLS_VERIFY_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT' has unsupported value '{ 0 }' # const 'MBEDTLS_PSA_PAKE_OPERATION_INIT' has unsupported value '{ { 0 } }' + {.push hint[ConvFromXtoItselfNotNeeded]: off.} + {.pragma: impcrypto_builtin_compositesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_builtin_composites.h".} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_PSA_BUILTIN_AEAD* = 1 MBEDTLS_PSA_BUILTIN_PAKE* = 1 diff --git a/webrtc/mbedtls/psa/crypto_builtin_primitives.nim b/webrtc/mbedtls/psa/crypto_builtin_primitives.nim index 415add7..155cf05 100644 --- a/webrtc/mbedtls/psa/crypto_builtin_primitives.nim +++ b/webrtc/mbedtls/psa/crypto_builtin_primitives.nim @@ -1,28 +1,12 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "crypto_driver_common" -import "crypto_types" -import "crypto_platform" -import "crypto_values" -import "crypto_sizes" -# Generated @ 2023-05-12T13:12:43+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_builtin_primitives.h - # const 'MBEDTLS_PSA_HASH_OPERATION_INIT' has unsupported value '{ 0, { 0 } }' # const 'MBEDTLS_PSA_CIPHER_OPERATION_INIT' has unsupported value '{ 0, 0, 0, { 0 } }' + {.push hint[ConvFromXtoItselfNotNeeded]: off.} {.pragma: impcrypto_builtin_primitivesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_builtin_primitives.h".} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_PSA_BUILTIN_CIPHER* = 1 {.pop.} diff --git a/webrtc/mbedtls/psa/crypto_compat.nim b/webrtc/mbedtls/psa/crypto_compat.nim deleted file mode 100644 index 7bbb30c..0000000 --- a/webrtc/mbedtls/psa/crypto_compat.nim +++ /dev/null @@ -1,20 +0,0 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -# Generated @ 2023-05-12T13:12:43+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_compat.h - -# const 'PSA_KEY_HANDLE_INIT' has unsupported value 'MBEDTLS_SVC_KEY_ID_INIT' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} -{.pragma: impcrypto_compatHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_compat.h".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_config.nim b/webrtc/mbedtls/psa/crypto_config.nim index f17e15d..c6641ab 100644 --- a/webrtc/mbedtls/psa/crypto_config.nim +++ b/webrtc/mbedtls/psa/crypto_config.nim @@ -1,24 +1,11 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -# Generated @ 2023-05-12T13:12:43+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_config.h - {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.pragma: impcrypto_configHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_config.h".} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const PSA_WANT_ALG_CBC_NO_PADDING* = 1 PSA_WANT_ALG_CBC_PKCS7* = 1 diff --git a/webrtc/mbedtls/psa/crypto_driver_common.nim b/webrtc/mbedtls/psa/crypto_driver_common.nim index 67653f4..638f6cd 100644 --- a/webrtc/mbedtls/psa/crypto_driver_common.nim +++ b/webrtc/mbedtls/psa/crypto_driver_common.nim @@ -1,70 +1,14 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "crypto_types" -import "crypto_platform" -import "crypto_values" -import "crypto_sizes" -# Generated @ 2023-05-12T13:12:43+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_driver_common.h +import "../utils" {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.pragma: impcrypto_driver_commonHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_driver_common.h".} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(psa_encrypt_or_decrypt_t) + const PSA_CRYPTO_DRIVER_DECRYPT* = (0).psa_encrypt_or_decrypt_t PSA_CRYPTO_DRIVER_ENCRYPT* = (PSA_CRYPTO_DRIVER_DECRYPT + 1).psa_encrypt_or_decrypt_t diff --git a/webrtc/mbedtls/psa/crypto_driver_contexts_composites.nim b/webrtc/mbedtls/psa/crypto_driver_contexts_composites.nim deleted file mode 100644 index c4d3a20..0000000 --- a/webrtc/mbedtls/psa/crypto_driver_contexts_composites.nim +++ /dev/null @@ -1,27 +0,0 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "crypto_driver_common" -import "crypto_types" -import "crypto_platform" -import "crypto_values" -import "crypto_sizes" -import "crypto_builtin_composites" -# Generated @ 2023-05-12T13:12:43+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_driver_contexts_composites.h - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - - -{.pragma: impcrypto_driver_contexts_compositesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_driver_contexts_composites.h".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_driver_contexts_key_derivation.nim b/webrtc/mbedtls/psa/crypto_driver_contexts_key_derivation.nim deleted file mode 100644 index 3e99495..0000000 --- a/webrtc/mbedtls/psa/crypto_driver_contexts_key_derivation.nim +++ /dev/null @@ -1,26 +0,0 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "crypto_driver_common" -import "crypto_types" -import "crypto_platform" -import "crypto_values" -import "crypto_sizes" -# Generated @ 2023-05-12T13:12:43+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_driver_contexts_key_derivation.h - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - - -{.pragma: impcrypto_driver_contexts_key_derivationHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_driver_contexts_key_derivation.h".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_driver_contexts_primitives.nim b/webrtc/mbedtls/psa/crypto_driver_contexts_primitives.nim deleted file mode 100644 index c015dcd..0000000 --- a/webrtc/mbedtls/psa/crypto_driver_contexts_primitives.nim +++ /dev/null @@ -1,27 +0,0 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "crypto_driver_common" -import "crypto_types" -import "crypto_platform" -import "crypto_values" -import "crypto_sizes" -import "crypto_builtin_primitives" -# Generated @ 2023-05-12T13:12:43+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_driver_contexts_primitives.h - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - - -{.pragma: impcrypto_driver_contexts_primitivesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_driver_contexts_primitives.h".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_extra.nim b/webrtc/mbedtls/psa/crypto_extra.nim deleted file mode 100644 index 9168adb..0000000 --- a/webrtc/mbedtls/psa/crypto_extra.nim +++ /dev/null @@ -1,23 +0,0 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -# Generated @ 2023-05-12T13:12:43+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_extra.h - -# const 'PSA_ALG_DSA_DETERMINISTIC_FLAG' has unsupported value 'PSA_ALG_ECDSA_DETERMINISTIC_FLAG' -# const 'PSA_PAKE_CIPHER_SUITE_INIT' has unsupported value '{ PSA_ALG_NONE, 0, 0, 0, PSA_ALG_NONE }' -# const 'PSA_PAKE_OPERATION_INIT' has unsupported value '{ 0, PSA_ALG_NONE, 0, PSA_PAKE_OPERATION_STAGE_SETUP, { 0 }, { { 0 } } }' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} -{.pragma: impcrypto_extraHdr, - header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_extra.h".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_platform.nim b/webrtc/mbedtls/psa/crypto_platform.nim deleted file mode 100644 index b73f92d..0000000 --- a/webrtc/mbedtls/psa/crypto_platform.nim +++ /dev/null @@ -1,22 +0,0 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -# Generated @ 2023-05-12T13:12:43+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_platform.h - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - - -{.pragma: impcrypto_platformHdr, - header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_platform.h".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_se_driver.nim b/webrtc/mbedtls/psa/crypto_se_driver.nim index d480aaa..995fc6f 100644 --- a/webrtc/mbedtls/psa/crypto_se_driver.nim +++ b/webrtc/mbedtls/psa/crypto_se_driver.nim @@ -1,73 +1,19 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "crypto_driver_common" import "crypto_types" -import "crypto_platform" -import "crypto_values" -import "crypto_sizes" +import "../utils" + {.compile: "./mbedtls/library/psa_crypto_se.c".} -# Generated @ 2023-05-12T13:12:44+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_se_driver.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.pragma: impcrypto_se_driverHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_se_driver.h".} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(psa_key_creation_method_t) + const PSA_KEY_CREATION_IMPORT* = (0).psa_key_creation_method_t PSA_KEY_CREATION_GENERATE* = (PSA_KEY_CREATION_IMPORT + 1).psa_key_creation_method_t diff --git a/webrtc/mbedtls/psa/crypto_sizes.nim b/webrtc/mbedtls/psa/crypto_sizes.nim index f039f20..63fdd09 100644 --- a/webrtc/mbedtls/psa/crypto_sizes.nim +++ b/webrtc/mbedtls/psa/crypto_sizes.nim @@ -1,16 +1,3 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -# Generated @ 2023-05-12T13:12:44+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_sizes.h - # const 'PSA_MAC_MAX_SIZE' has unsupported value 'PSA_HASH_MAX_SIZE' # const 'PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE' has unsupported value 'PSA_ECDSA_SIGNATURE_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)' # const 'PSA_SIGNATURE_MAX_SIZE' has unsupported value '(PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS) > PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE ? PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS) : PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE)' @@ -19,14 +6,15 @@ # const 'PSA_EXPORT_KEY_PAIR_MAX_SIZE' has unsupported value '(PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) > PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS) ? PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) : PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS))' # const 'PSA_EXPORT_PUBLIC_KEY_MAX_SIZE' has unsupported value '(PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) > PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS) ? PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) : PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS))' # const 'PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE' has unsupported value '(PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS))' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.push hint[ConvFromXtoItselfNotNeeded]: off.} {.pragma: impcrypto_sizesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_sizes.h".} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const PSA_HASH_MAX_SIZE* = 64 PSA_HMAC_MAX_HASH_BLOCK_SIZE* = 128 diff --git a/webrtc/mbedtls/psa/crypto_struct.nim b/webrtc/mbedtls/psa/crypto_struct.nim index f46b1e9..70ebb39 100644 --- a/webrtc/mbedtls/psa/crypto_struct.nim +++ b/webrtc/mbedtls/psa/crypto_struct.nim @@ -1,26 +1,5 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "crypto_driver_contexts_primitives" -import "crypto_driver_common" import "crypto_types" -import "crypto_platform" -import "crypto_values" -import "crypto_sizes" -import "crypto_builtin_primitives" -import "crypto_driver_contexts_composites" -import "crypto_builtin_composites" -import "crypto_driver_contexts_key_derivation" {.compile: "./mbedtls/library/psa_crypto_client.c".} -# Generated @ 2023-05-12T13:12:44+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_struct.h # const 'PSA_HASH_OPERATION_INIT' has unsupported value '{ 0, { 0 } }' # const 'PSA_CIPHER_OPERATION_INIT' has unsupported value '{ 0, 0, 0, 0, { 0 } }' @@ -33,14 +12,15 @@ import "crypto_driver_contexts_key_derivation" # const 'PSA_KEY_ATTRIBUTES_INIT' has unsupported value '{ PSA_CORE_KEY_ATTRIBUTES_INIT, NULL, 0 }' # const 'PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT' has unsupported value '{ 0, { 0 }, 0, 0 }' # const 'PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT' has unsupported value '{ 0, { 0 }, 0, 0 }' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.push hint[ConvFromXtoItselfNotNeeded]: off.} {.pragma: impcrypto_structHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_struct.h".} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const PSA_MAX_KEY_BITS* = 0x0000FFF8 MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER* = ( diff --git a/webrtc/mbedtls/psa/crypto_types.nim b/webrtc/mbedtls/psa/crypto_types.nim index 7fdc6ab..a0a2428 100644 --- a/webrtc/mbedtls/psa/crypto_types.nim +++ b/webrtc/mbedtls/psa/crypto_types.nim @@ -1,13 +1,3 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "crypto_platform" import "../md5" import "../ripemd160" import "../sha1" @@ -18,59 +8,17 @@ import "../ccm" import "../gcm" import "../chachapoly" import "../ecjpake" -# Generated @ 2023-05-12T13:12:44+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_types.h +import "../utils" {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.pragma: impcrypto_builtin_key_derivationHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_builtin_key_derivation.h".} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(psa_tls12_prf_key_derivation_state_t) + const PSA_TLS12_PRF_STATE_INIT* = (0).psa_tls12_prf_key_derivation_state_t PSA_TLS12_PRF_STATE_SEED_SET* = (PSA_TLS12_PRF_STATE_INIT + 1).psa_tls12_prf_key_derivation_state_t diff --git a/webrtc/mbedtls/psa/crypto_values.nim b/webrtc/mbedtls/psa/crypto_values.nim index 171a837..1718ee5 100644 --- a/webrtc/mbedtls/psa/crypto_values.nim +++ b/webrtc/mbedtls/psa/crypto_values.nim @@ -1,16 +1,4 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} import "crypto_types" -# -# Generated @ 2023-05-12T13:12:44+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/psa/crypto_values.h # const 'PSA_ERROR_GENERIC_ERROR' has unsupported value '((psa_status_t)-132)' # const 'PSA_ERROR_NOT_SUPPORTED' has unsupported value '((psa_status_t)-134)' @@ -37,14 +25,15 @@ import "crypto_types" # const 'PSA_ALG_RSA_PKCS1V15_SIGN_RAW' has unsupported value 'PSA_ALG_RSA_PKCS1V15_SIGN_BASE' # const 'PSA_ALG_ECDSA_ANY' has unsupported value 'PSA_ALG_ECDSA_BASE' # const 'PSA_INTERRUPTIBLE_MAX_OPS_UNLIMITED' has unsupported value 'UINT32_MAX' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.push hint[ConvFromXtoItselfNotNeeded]: off.} {.pragma: impcrypto_valuesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_values.h".} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const PSA_SUCCESS* = (cast[psa_status_t](0)) PSA_KEY_TYPE_NONE* = (cast[psa_key_type_t](0x00000000)) diff --git a/webrtc/mbedtls/psa_util.nim b/webrtc/mbedtls/psa_util.nim index fc8d8de..a0340ae 100644 --- a/webrtc/mbedtls/psa_util.nim +++ b/webrtc/mbedtls/psa_util.nim @@ -1,20 +1,9 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "ctr_drbg" import "pkcs5" import "pkcs12" +# TODO: Remove pkcs5 and pkcs12, they're not used in this file. import "psa/crypto_types" {.compile: "./mbedtls/library/psa_util.c".} -# Generated @ 2023-05-11T11:19:13+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/psa_util.h # proc 'mbedtls_psa_translate_cipher_type' skipped - static inline procs cannot work with '--noHeader | -H' # proc 'mbedtls_psa_translate_cipher_mode' skipped - static inline procs cannot work with '--noHeader | -H' @@ -24,12 +13,13 @@ import "psa/crypto_types" # const 'MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH' has unsupported value 'PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)' # const 'MBEDTLS_PSA_MAX_EC_KEY_PAIR_LENGTH' has unsupported value 'PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)' # const 'MBEDTLS_PSA_RANDOM_STATE' has unsupported value 'mbedtls_psa_random_state' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.push hint[ConvFromXtoItselfNotNeeded]: off.} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + type mbedtls_f_rng_t* = proc (p_rng: pointer; output: ptr byte; output_size: uint): cint {. cdecl.} diff --git a/webrtc/mbedtls/ripemd160.nim b/webrtc/mbedtls/ripemd160.nim index 78f3885..85a0db8 100644 --- a/webrtc/mbedtls/ripemd160.nim +++ b/webrtc/mbedtls/ripemd160.nim @@ -1,24 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "platform_time" + {.compile: "./mbedtls/library/ripemd160.c".} -# Generated @ 2023-05-11T11:19:13+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ripemd160.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + type mbedtls_ripemd160_context* {.bycopy.} = object private_total*: array[2, uint32] diff --git a/webrtc/mbedtls/rsa.nim b/webrtc/mbedtls/rsa.nim index b6f77bd..43c2c1a 100644 --- a/webrtc/mbedtls/rsa.nim +++ b/webrtc/mbedtls/rsa.nim @@ -1,29 +1,17 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "hash_info" import "bignum" import "md" -import "platform_time" + {.compile: "./mbedtls/library/oid.c"} {.compile: "./mbedtls/library/rsa.c"} {.compile: "./mbedtls/library/rsa_alt_helpers.c"} -# Generated @ 2023-05-11T11:19:13+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/rsa.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_RSA_BAD_INPUT_DATA* = -0x00004080 MBEDTLS_ERR_RSA_INVALID_PADDING* = -0x00004100 diff --git a/webrtc/mbedtls/sha1.nim b/webrtc/mbedtls/sha1.nim index a1b1e2e..087d7fc 100644 --- a/webrtc/mbedtls/sha1.nim +++ b/webrtc/mbedtls/sha1.nim @@ -1,24 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "platform_time" + {.compile: "./mbedtls/library/sha1.c".} -# Generated @ 2023-05-11T11:19:13+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/sha1.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_SHA1_BAD_INPUT_DATA* = -0x00000073 type diff --git a/webrtc/mbedtls/sha256.nim b/webrtc/mbedtls/sha256.nim index edfe16c..9f845c0 100644 --- a/webrtc/mbedtls/sha256.nim +++ b/webrtc/mbedtls/sha256.nim @@ -1,24 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "platform_time" + {.compile: "./mbedtls/library/sha256.c".} -# Generated @ 2023-05-11T11:19:13+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/sha256.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_SHA256_BAD_INPUT_DATA* = -0x00000074 type diff --git a/webrtc/mbedtls/sha512.nim b/webrtc/mbedtls/sha512.nim index 90a3939..b675262 100644 --- a/webrtc/mbedtls/sha512.nim +++ b/webrtc/mbedtls/sha512.nim @@ -1,24 +1,13 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# import "platform_time" + {.compile: "./mbedtls/library/sha512.c".} -# Generated @ 2023-05-11T11:19:13+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/sha512.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_SHA512_BAD_INPUT_DATA* = -0x00000075 type diff --git a/webrtc/mbedtls/ssl.nim b/webrtc/mbedtls/ssl.nim index 5591ee6..4f7049e 100644 --- a/webrtc/mbedtls/ssl.nim +++ b/webrtc/mbedtls/ssl.nim @@ -1,52 +1,20 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "platform_util" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" +import "ssl_ciphersuites" import "platform_time" -import "private_access" import "bignum" import "ecp" -import "ssl_ciphersuites" import "pk" -import "md" -import "rsa" -import "ecdsa" -import "cipher" import "x509_crt" -import "x509" -import "asn1" import "x509_crl" import "dhm" -import "ecdh" -import "md5" -import "ripemd160" -import "sha1" -import "sha256" -import "sha512" -import "cmac" -import "gcm" -import "ccm" -import "chachapoly" -import "poly1305" -import "chacha20" -import "ecjpake" -{.compile: "./mbedtls/library/ssl_ciphersuites.c".} +import "utils" + +{.compile: "./mbedtls/library/debug.c".} +{.compile: "./mbedtls/library/ssl_debug_helpers_generated.c".} {.compile: "./mbedtls/library/ssl_msg.c".} {.compile: "./mbedtls/library/ssl_tls12_server.c".} {.compile: "./mbedtls/library/ssl_tls.c".} -# Generated @ 2023-05-11T11:19:14+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ssl.h +{.compile: "./mbedtls/library/ssl_client.c".} +{.compile: "./mbedtls/library/ssl_tls12_client.c".} # const 'MBEDTLS_PREMASTER_SIZE' has unsupported value 'sizeof(union mbedtls_ssl_premaster_secret)' # const 'MBEDTLS_TLS1_3_MD_MAX_SIZE' has unsupported value 'PSA_HASH_MAX_SIZE' @@ -65,58 +33,18 @@ import "ecjpake" # proc 'mbedtls_ssl_conf_min_tls_version' skipped - static inline procs cannot work with '--noHeader | -H' # proc 'mbedtls_ssl_get_version_number' skipped - static inline procs cannot work with '--noHeader | -H' # proc 'mbedtls_ssl_is_handshake_over' skipped - static inline procs cannot work with '--noHeader | -H' + {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(mbedtls_ssl_states) defineEnum(mbedtls_ssl_protocol_version) defineEnum(mbedtls_tls_prf_types) defineEnum(mbedtls_ssl_key_export_type) + const MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS* = -0x00007000 MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE* = -0x00007080 diff --git a/webrtc/mbedtls/ssl_cache.nim b/webrtc/mbedtls/ssl_cache.nim index 32d1dfe..b073669 100644 --- a/webrtc/mbedtls/ssl_cache.nim +++ b/webrtc/mbedtls/ssl_cache.nim @@ -1,57 +1,14 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "ssl" -import "platform_util" import "platform_time" -import "bignum" -import "ecp" -import "ssl_ciphersuites" -import "pk" -import "md" -import "rsa" -import "ecdsa" -import "cipher" -import "x509_crt" -import "x509" -import "asn1" -import "x509_crl" -import "dhm" -import "ecdh" -import "md5" -import "ripemd160" -import "sha1" -import "sha256" -import "sha512" -import "cmac" -import "gcm" -import "ccm" -import "chachapoly" -import "poly1305" -import "chacha20" -import "ecjpake" + {.compile: "./mbedtls/library/ssl_cache.c".} -# Generated @ 2023-05-11T11:19:14+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ssl_cache.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT* = 86400 MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES* = 50 diff --git a/webrtc/mbedtls/ssl_ciphersuites.nim b/webrtc/mbedtls/ssl_ciphersuites.nim index 8c7da00..5517a46 100644 --- a/webrtc/mbedtls/ssl_ciphersuites.nim +++ b/webrtc/mbedtls/ssl_ciphersuites.nim @@ -1,30 +1,7 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "pk" -import "md" -import "platform_util" -import "platform_time" -import "rsa" -import "bignum" -import "ecp" -import "ecdsa" -import "cipher" +import "utils" + {.compile: "./mbedtls/library/ssl_ciphersuites.c".} -# Generated @ 2023-05-11T11:19:14+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ssl_ciphersuites.h # proc 'mbedtls_ssl_ciphersuite_get_name' skipped - static inline procs cannot work with '--noHeader | -H' # proc 'mbedtls_ssl_ciphersuite_has_pfs' skipped - static inline procs cannot work with '--noHeader | -H' @@ -35,55 +12,15 @@ import "cipher" # proc 'mbedtls_ssl_ciphersuite_uses_dhe' skipped - static inline procs cannot work with '--noHeader | -H' # proc 'mbedtls_ssl_ciphersuite_uses_ecdhe' skipped - static inline procs cannot work with '--noHeader | -H' # proc 'mbedtls_ssl_ciphersuite_uses_server_signature' skipped - static inline procs cannot work with '--noHeader | -H' + {.push hint[ConvFromXtoItselfNotNeeded]: off.} -import macros - -macro defineEnum(typ: untyped): untyped = - result = newNimNode(nnkStmtList) - - # Enum mapped to distinct cint - result.add quote do: - type `typ`* = distinct cint - - for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: - let - ni = newIdentNode(i) - typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool - if i[0] == '>': # cannot borrow `>` and `>=` from templates - let - nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) - proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) - proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) - else: - result.add quote do: - proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} - proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} - proc `ni`*(x, y: `typ`): `typout` {.borrow.} - result.add quote do: - proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) - proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) - - let - divop = newIdentNode("/") # `/`() - dlrop = newIdentNode("$") # `$`() - notop = newIdentNode("not") # `not`() - result.add quote do: - proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) - proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) - proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) - proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) - proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) - - proc `dlrop`*(x: `typ`): string {.borrow.} - proc `notop`*(x: `typ`): `typ` {.borrow.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + defineEnum(mbedtls_key_exchange_type_t) + const MBEDTLS_TLS_RSA_WITH_NULL_MD5* = 0x00000001 MBEDTLS_TLS_RSA_WITH_NULL_SHA* = 0x00000002 diff --git a/webrtc/mbedtls/ssl_cookie.nim b/webrtc/mbedtls/ssl_cookie.nim index 449cdb8..214b466 100644 --- a/webrtc/mbedtls/ssl_cookie.nim +++ b/webrtc/mbedtls/ssl_cookie.nim @@ -1,57 +1,14 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "ssl" -import "platform_util" -import "platform_time" -import "bignum" -import "ecp" -import "ssl_ciphersuites" -import "pk" import "md" -import "rsa" -import "ecdsa" -import "cipher" -import "x509_crt" -import "x509" -import "asn1" -import "x509_crl" -import "dhm" -import "ecdh" -import "md5" -import "ripemd160" -import "sha1" -import "sha256" -import "sha512" -import "cmac" -import "gcm" -import "ccm" -import "chachapoly" -import "poly1305" -import "chacha20" -import "ecjpake" + {.compile: "./mbedtls/library/ssl_cookie.c".} -# Generated @ 2023-05-11T11:19:14+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ssl_cookie.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_SSL_COOKIE_TIMEOUT* = 60 type diff --git a/webrtc/mbedtls/ssl_ticket.nim b/webrtc/mbedtls/ssl_ticket.nim index 9446a2b..2dce02e 100644 --- a/webrtc/mbedtls/ssl_ticket.nim +++ b/webrtc/mbedtls/ssl_ticket.nim @@ -1,57 +1,16 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "ssl" -import "platform_util" import "platform_time" -import "bignum" -import "ecp" import "ssl_ciphersuites" -import "pk" -import "md" -import "rsa" -import "ecdsa" import "cipher" -import "x509_crt" -import "x509" -import "asn1" -import "x509_crl" -import "dhm" -import "ecdh" -import "md5" -import "ripemd160" -import "sha1" -import "sha256" -import "sha512" -import "cmac" -import "gcm" -import "ccm" -import "chachapoly" -import "poly1305" -import "chacha20" -import "ecjpake" + {.compile: "./mbedtls/library/ssl_ticket.c".} -# Generated @ 2023-05-11T11:19:15+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/ssl_ticket.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_SSL_TICKET_MAX_KEY_BYTES* = 32 MBEDTLS_SSL_TICKET_KEY_NAME_BYTES* = 4 diff --git a/webrtc/mbedtls/threading.nim b/webrtc/mbedtls/threading.nim index 4ce3ffe..e4a193d 100644 --- a/webrtc/mbedtls/threading.nim +++ b/webrtc/mbedtls/threading.nim @@ -1,27 +1,9 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" -# Generated @ 2023-05-11T11:19:15+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/threading.h - {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_ERR_THREADING_BAD_INPUT_DATA* = -0x0000001C MBEDTLS_ERR_THREADING_MUTEX_ERROR* = -0x0000001E diff --git a/webrtc/mbedtls/timing.nim b/webrtc/mbedtls/timing.nim index f05a1dd..557a188 100644 --- a/webrtc/mbedtls/timing.nim +++ b/webrtc/mbedtls/timing.nim @@ -1,28 +1,11 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" {.compile: "./mbedtls/library/timing.c".} -# Generated @ 2023-05-11T11:19:15+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/timing.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + type mbedtls_timing_hr_time* {.bycopy.} = object private_opaque*: array[4, uint64] diff --git a/webrtc/mbedtls/version.nim b/webrtc/mbedtls/version.nim index 9770bfb..1851677 100644 --- a/webrtc/mbedtls/version.nim +++ b/webrtc/mbedtls/version.nim @@ -1,28 +1,12 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" {.compile: "./mbedtls/library/version.c".} {.compile: "./mbedtls/library/version_features.c".} -# Generated @ 2023-05-11T11:19:15+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/version.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + proc mbedtls_version_get_number*(): cuint {.importc, cdecl.} proc mbedtls_version_get_string*(string: cstring) {.importc, cdecl.} proc mbedtls_version_get_string_full*(string: cstring) {.importc, cdecl.} diff --git a/webrtc/mbedtls/x509.nim b/webrtc/mbedtls/x509.nim index 5de4e6b..4ea1f6b 100644 --- a/webrtc/mbedtls/x509.nim +++ b/webrtc/mbedtls/x509.nim @@ -1,37 +1,9 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "asn1" -import "platform_util" -import "platform_time" -import "bignum" import "pk" import "md" -import "rsa" -import "ecp" -import "ecdsa" -import "oid" -import "hmac_drbg" -import "asn1write" -import "nist_kw" -import "hash_info" -{.compile: "./mbedtls/library/rsa_alt_helpers.c".} + {.compile: "./mbedtls/library/x509.c".} {.compile: "./mbedtls/library/x509_create.c".} -# Generated @ 2023-05-11T11:19:15+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/x509.h # const 'MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER' has unsupported value 'MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER' # const 'MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER' has unsupported value 'MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER' @@ -51,12 +23,13 @@ import "hash_info" # const 'MBEDTLS_X509_EXT_NS_CERT_TYPE' has unsupported value 'MBEDTLS_OID_X509_EXT_NS_CERT_TYPE' # proc 'mbedtls_x509_dn_get_next' skipped - static inline procs cannot work with '--noHeader | -H' # const 'MBEDTLS_X509_SAFE_SNPRINTF' has unsupported value 'do { if (ret < 0 || (size_t) ret >= n) return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL; n -= (size_t) ret; p += (size_t) ret; } while (0)' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.push hint[ConvFromXtoItselfNotNeeded]: off.} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_X509_MAX_INTERMEDIATE_CA* = 8 MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE* = -0x00002080 diff --git a/webrtc/mbedtls/x509_crl.nim b/webrtc/mbedtls/x509_crl.nim index 4e309b9..f9b7a1d 100644 --- a/webrtc/mbedtls/x509_crl.nim +++ b/webrtc/mbedtls/x509_crl.nim @@ -1,38 +1,15 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "x509" -import "asn1" -import "platform_util" -import "platform_time" -import "bignum" import "pk" import "md" -import "rsa" -import "ecp" -import "ecdsa" + {.compile: "./mbedtls/library/x509_crl.c".} -# Generated @ 2023-05-11T11:19:15+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/x509_crl.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + type mbedtls_x509_crl_entry* {.bycopy.} = object raw*: mbedtls_x509_buf diff --git a/webrtc/mbedtls/x509_crt.nim b/webrtc/mbedtls/x509_crt.nim index 89336b6..bdd055c 100644 --- a/webrtc/mbedtls/x509_crt.nim +++ b/webrtc/mbedtls/x509_crt.nim @@ -1,43 +1,23 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "x509" -import "asn1" -import "platform_util" -import "platform_time" -import "bignum" -import "pk" -import "md" -import "rsa" -import "ecp" -import "ecdsa" import "x509_crl" +import "asn1" +import "bignum" +import "md" +import "pk" + {.compile: "./mbedtls/library/x509_crt.c".} {.compile: "./mbedtls/library/x509write_crt.c".} -# Generated @ 2023-05-11T11:19:15+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/x509_crt.h # const 'MBEDTLS_X509_CRT_ERROR_INFO_LIST' has unsupported value 'X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_EXPIRED, "MBEDTLS_X509_BADCERT_EXPIRED", "The certificate validity has expired") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_REVOKED, "MBEDTLS_X509_BADCERT_REVOKED", "The certificate has been revoked (is on a CRL)") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_CN_MISMATCH, "MBEDTLS_X509_BADCERT_CN_MISMATCH", "The certificate Common Name (CN) does not match with the expected CN") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_NOT_TRUSTED, "MBEDTLS_X509_BADCERT_NOT_TRUSTED", "The certificate is not correctly signed by the trusted CA") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_NOT_TRUSTED, "MBEDTLS_X509_BADCRL_NOT_TRUSTED", "The CRL is not correctly signed by the trusted CA") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_EXPIRED, "MBEDTLS_X509_BADCRL_EXPIRED", "The CRL is expired") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_MISSING, "MBEDTLS_X509_BADCERT_MISSING", "Certificate was missing") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_SKIP_VERIFY, "MBEDTLS_X509_BADCERT_SKIP_VERIFY", "Certificate verification was skipped") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_OTHER, "MBEDTLS_X509_BADCERT_OTHER", "Other reason (can be used by verify callback)") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_FUTURE, "MBEDTLS_X509_BADCERT_FUTURE", "The certificate validity starts in the future") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_FUTURE, "MBEDTLS_X509_BADCRL_FUTURE", "The CRL is from the future") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_KEY_USAGE, "MBEDTLS_X509_BADCERT_KEY_USAGE", "Usage does not match the keyUsage extension") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_EXT_KEY_USAGE, "MBEDTLS_X509_BADCERT_EXT_KEY_USAGE", "Usage does not match the extendedKeyUsage extension") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_NS_CERT_TYPE, "MBEDTLS_X509_BADCERT_NS_CERT_TYPE", "Usage does not match the nsCertType extension") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_MD, "MBEDTLS_X509_BADCERT_BAD_MD", "The certificate is signed with an unacceptable hash.") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_PK, "MBEDTLS_X509_BADCERT_BAD_PK", "The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA).") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_KEY, "MBEDTLS_X509_BADCERT_BAD_KEY", "The certificate is signed with an unacceptable key (eg bad curve, RSA too short).") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_MD, "MBEDTLS_X509_BADCRL_BAD_MD", "The CRL is signed with an unacceptable hash.") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_PK, "MBEDTLS_X509_BADCRL_BAD_PK", "The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA).") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_KEY, "MBEDTLS_X509_BADCRL_BAD_KEY", "The CRL is signed with an unacceptable key (eg bad curve, RSA too short).")' # const 'MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE' has unsupported value '(MBEDTLS_X509_MAX_INTERMEDIATE_CA + 2)' # proc 'mbedtls_x509_crt_has_ext_type' skipped - static inline procs cannot work with '--noHeader | -H' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} +{.push hint[ConvFromXtoItselfNotNeeded]: off.} {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + const MBEDTLS_X509_CRT_VERSION_1* = 0 MBEDTLS_X509_CRT_VERSION_2* = 1 diff --git a/webrtc/mbedtls/x509_csr.nim b/webrtc/mbedtls/x509_csr.nim index dac044f..99be885 100644 --- a/webrtc/mbedtls/x509_csr.nim +++ b/webrtc/mbedtls/x509_csr.nim @@ -1,39 +1,17 @@ -#import strformat, os -# -## C include directory -#const root = currentSourcePath.parentDir -#const mbedtlsInclude = root/"mbedtls"/"include" -#const mbedtlsLibrary = root/"mbedtls"/"library" -# -#{.passc: fmt"-I{mbedtlsInclude} -I{mbedtlsLibrary}".} -# -import "private_access" -import "build_info" -import "mbedtls_config" -import "config_psa" -import "check_config" import "x509" import "asn1" -import "platform_util" -import "platform_time" -import "bignum" import "pk" import "md" -import "rsa" -import "ecp" -import "ecdsa" + {.compile: "./mbedtls/library/x509_csr.c".} {.compile: "./mbedtls/library/x509write_csr.c".} -# Generated @ 2023-05-11T11:19:15+02:00 -# Command line: -# /home/lchenut/.nimble/pkgs/nimterop-0.6.13/nimterop/toast --pnim --preprocess --nocomment --noHeader --replace=_pms_rsa=u_pms_rsa --replace=_pms_dhm=u_pms_dhm --replace=_pms_ecdh=u_pms_ecdh --replace=_pms_psk=u_pms_psk --replace=_pms_dhe_psk=u_pms_dhe_psk --replace=_pms_rsa_psk=u_pms_rsa_psk --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk --replace=_pms_ecjpake=u_pms_ecjpake --replace=private_xm1=private_xm1_1 --replace=private_xm2=private_xm2_1 --includeDirs=./mbedtls/include --includeDirs=./mbedtls/library ./mbedtls/include/mbedtls/x509_csr.h {.push hint[ConvFromXtoItselfNotNeeded]: off.} - {.experimental: "codeReordering".} {.passc: "-I./mbedtls/include".} {.passc: "-I./mbedtls/library".} + type mbedtls_x509_csr* {.bycopy.} = object raw*: mbedtls_x509_buf From cd6aba3b667474c2a86edb4517bebb52196155f2 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Tue, 30 May 2023 11:24:54 +0200 Subject: [PATCH 13/66] Removed mbedtls wrapper --- .gitmodules | 3 - build_mbedtls.sh | 100 --- mbedtls | 1 - prelude_mbedtls.nim | 13 - webrtc.nimble | 7 +- webrtc/mbedtls/aes.nim | 78 -- webrtc/mbedtls/aria.nim | 47 - webrtc/mbedtls/asn1.nim | 107 --- webrtc/mbedtls/asn1write.nim | 57 -- webrtc/mbedtls/base64.nim | 19 - webrtc/mbedtls/bignum.nim | 144 --- webrtc/mbedtls/build_info.nim | 14 - webrtc/mbedtls/camellia.nim | 48 - webrtc/mbedtls/ccm.nim | 69 -- webrtc/mbedtls/chacha20.nim | 33 - webrtc/mbedtls/chachapoly.nim | 57 -- webrtc/mbedtls/cipher.nim | 269 ------ webrtc/mbedtls/cmac.nim | 38 - webrtc/mbedtls/config_psa.nim | 14 - webrtc/mbedtls/constant_time.nim | 10 - webrtc/mbedtls/ctr_drbg.nim | 74 -- webrtc/mbedtls/debug.nim | 47 - webrtc/mbedtls/des.nim | 64 -- webrtc/mbedtls/dhm.nim | 94 -- webrtc/mbedtls/ecdh.nim | 72 -- webrtc/mbedtls/ecdsa.nim | 83 -- webrtc/mbedtls/ecjpake.nim | 73 -- webrtc/mbedtls/ecp.nim | 200 ----- webrtc/mbedtls/entropy.nim | 64 -- webrtc/mbedtls/error.nim | 20 - webrtc/mbedtls/gcm.nim | 55 -- webrtc/mbedtls/hash_info.nim | 4 - webrtc/mbedtls/hkdf.nim | 23 - webrtc/mbedtls/hmac_drbg.nim | 70 -- webrtc/mbedtls/lms.nim | 63 -- webrtc/mbedtls/mbedtls_config.nim | 13 - webrtc/mbedtls/md.nim | 83 -- webrtc/mbedtls/md5.nim | 32 - webrtc/mbedtls/memory_buffer_alloc.nim | 23 - webrtc/mbedtls/net_sockets.nim | 55 -- webrtc/mbedtls/nist_kw.nim | 35 - webrtc/mbedtls/oid.nim | 256 ------ webrtc/mbedtls/pem.nim | 41 - webrtc/mbedtls/pk.nim | 172 ---- webrtc/mbedtls/pkcs12.nim | 36 - webrtc/mbedtls/pkcs5.nim | 37 - webrtc/mbedtls/pkcs7.nim | 78 -- webrtc/mbedtls/platform.nim | 45 - webrtc/mbedtls/platform_time.nim | 18 - webrtc/mbedtls/platform_util.nim | 17 - webrtc/mbedtls/poly1305.nim | 34 - webrtc/mbedtls/psa/crypto.nim | 589 ------------- .../mbedtls/psa/crypto_builtin_composites.nim | 24 - .../mbedtls/psa/crypto_builtin_primitives.nim | 12 - webrtc/mbedtls/psa/crypto_config.nim | 70 -- webrtc/mbedtls/psa/crypto_driver_common.nim | 15 - webrtc/mbedtls/psa/crypto_se_driver.nim | 206 ----- webrtc/mbedtls/psa/crypto_sizes.nim | 33 - webrtc/mbedtls/psa/crypto_struct.nim | 85 -- webrtc/mbedtls/psa/crypto_types.nim | 295 ------- webrtc/mbedtls/psa/crypto_values.nim | 199 ----- webrtc/mbedtls/psa_util.nim | 43 - webrtc/mbedtls/ripemd160.nim | 36 - webrtc/mbedtls/rsa.nim | 165 ---- webrtc/mbedtls/sha1.nim | 34 - webrtc/mbedtls/sha256.nim | 37 - webrtc/mbedtls/sha512.nim | 37 - webrtc/mbedtls/ssl.nim | 821 ------------------ webrtc/mbedtls/ssl_cache.nim | 47 - webrtc/mbedtls/ssl_ciphersuites.nim | 256 ------ webrtc/mbedtls/ssl_cookie.nim | 29 - webrtc/mbedtls/ssl_ticket.nim | 45 - webrtc/mbedtls/threading.nim | 10 - webrtc/mbedtls/timing.nim | 25 - webrtc/mbedtls/version.nim | 14 - webrtc/mbedtls/x509.nim | 212 ----- webrtc/mbedtls/x509_crl.nim | 49 -- webrtc/mbedtls/x509_crt.nim | 194 ----- webrtc/mbedtls/x509_csr.nim | 83 -- 79 files changed, 6 insertions(+), 6768 deletions(-) delete mode 100755 build_mbedtls.sh delete mode 160000 mbedtls delete mode 100644 prelude_mbedtls.nim delete mode 100644 webrtc/mbedtls/aes.nim delete mode 100644 webrtc/mbedtls/aria.nim delete mode 100644 webrtc/mbedtls/asn1.nim delete mode 100644 webrtc/mbedtls/asn1write.nim delete mode 100644 webrtc/mbedtls/base64.nim delete mode 100644 webrtc/mbedtls/bignum.nim delete mode 100644 webrtc/mbedtls/build_info.nim delete mode 100644 webrtc/mbedtls/camellia.nim delete mode 100644 webrtc/mbedtls/ccm.nim delete mode 100644 webrtc/mbedtls/chacha20.nim delete mode 100644 webrtc/mbedtls/chachapoly.nim delete mode 100644 webrtc/mbedtls/cipher.nim delete mode 100644 webrtc/mbedtls/cmac.nim delete mode 100644 webrtc/mbedtls/config_psa.nim delete mode 100644 webrtc/mbedtls/constant_time.nim delete mode 100644 webrtc/mbedtls/ctr_drbg.nim delete mode 100644 webrtc/mbedtls/debug.nim delete mode 100644 webrtc/mbedtls/des.nim delete mode 100644 webrtc/mbedtls/dhm.nim delete mode 100644 webrtc/mbedtls/ecdh.nim delete mode 100644 webrtc/mbedtls/ecdsa.nim delete mode 100644 webrtc/mbedtls/ecjpake.nim delete mode 100644 webrtc/mbedtls/ecp.nim delete mode 100644 webrtc/mbedtls/entropy.nim delete mode 100644 webrtc/mbedtls/error.nim delete mode 100644 webrtc/mbedtls/gcm.nim delete mode 100644 webrtc/mbedtls/hash_info.nim delete mode 100644 webrtc/mbedtls/hkdf.nim delete mode 100644 webrtc/mbedtls/hmac_drbg.nim delete mode 100644 webrtc/mbedtls/lms.nim delete mode 100644 webrtc/mbedtls/mbedtls_config.nim delete mode 100644 webrtc/mbedtls/md.nim delete mode 100644 webrtc/mbedtls/md5.nim delete mode 100644 webrtc/mbedtls/memory_buffer_alloc.nim delete mode 100644 webrtc/mbedtls/net_sockets.nim delete mode 100644 webrtc/mbedtls/nist_kw.nim delete mode 100644 webrtc/mbedtls/oid.nim delete mode 100644 webrtc/mbedtls/pem.nim delete mode 100644 webrtc/mbedtls/pk.nim delete mode 100644 webrtc/mbedtls/pkcs12.nim delete mode 100644 webrtc/mbedtls/pkcs5.nim delete mode 100644 webrtc/mbedtls/pkcs7.nim delete mode 100644 webrtc/mbedtls/platform.nim delete mode 100644 webrtc/mbedtls/platform_time.nim delete mode 100644 webrtc/mbedtls/platform_util.nim delete mode 100644 webrtc/mbedtls/poly1305.nim delete mode 100644 webrtc/mbedtls/psa/crypto.nim delete mode 100644 webrtc/mbedtls/psa/crypto_builtin_composites.nim delete mode 100644 webrtc/mbedtls/psa/crypto_builtin_primitives.nim delete mode 100644 webrtc/mbedtls/psa/crypto_config.nim delete mode 100644 webrtc/mbedtls/psa/crypto_driver_common.nim delete mode 100644 webrtc/mbedtls/psa/crypto_se_driver.nim delete mode 100644 webrtc/mbedtls/psa/crypto_sizes.nim delete mode 100644 webrtc/mbedtls/psa/crypto_struct.nim delete mode 100644 webrtc/mbedtls/psa/crypto_types.nim delete mode 100644 webrtc/mbedtls/psa/crypto_values.nim delete mode 100644 webrtc/mbedtls/psa_util.nim delete mode 100644 webrtc/mbedtls/ripemd160.nim delete mode 100644 webrtc/mbedtls/rsa.nim delete mode 100644 webrtc/mbedtls/sha1.nim delete mode 100644 webrtc/mbedtls/sha256.nim delete mode 100644 webrtc/mbedtls/sha512.nim delete mode 100644 webrtc/mbedtls/ssl.nim delete mode 100644 webrtc/mbedtls/ssl_cache.nim delete mode 100644 webrtc/mbedtls/ssl_ciphersuites.nim delete mode 100644 webrtc/mbedtls/ssl_cookie.nim delete mode 100644 webrtc/mbedtls/ssl_ticket.nim delete mode 100644 webrtc/mbedtls/threading.nim delete mode 100644 webrtc/mbedtls/timing.nim delete mode 100644 webrtc/mbedtls/version.nim delete mode 100644 webrtc/mbedtls/x509.nim delete mode 100644 webrtc/mbedtls/x509_crl.nim delete mode 100644 webrtc/mbedtls/x509_crt.nim delete mode 100644 webrtc/mbedtls/x509_csr.nim diff --git a/.gitmodules b/.gitmodules index 6ba4614..b04bc21 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "usrsctp"] path = usrsctp url = git@github.com:sctplab/usrsctp.git -[submodule "mbedtls"] - path = mbedtls - url = git@github.com:Mbed-TLS/mbedtls.git diff --git a/build_mbedtls.sh b/build_mbedtls.sh deleted file mode 100755 index 29d8e44..0000000 --- a/build_mbedtls.sh +++ /dev/null @@ -1,100 +0,0 @@ -#!/bin/bash -root=$(dirname "$0") -outputDirectory="${root}/webrtc/mbedtls" -genDirectory="${root}/gen" - -mkdir -p "${outputDirectory}" "${genDirectory}" - -# install nimterop, if not already installed -if ! [ -x "$(command -v toast)" ]; then - nimble install -y nimterop@0.6.11 -fi - -# run make on usrsctp sources -cd "${root}/mbedtls" && make && cd - - -# assemble list of C files to be compiled -for file in `find ${root}/mbedtls/library -name '*.c'`; do - compile="${compile} --compile=${file}" -done - -# rm -r generatedmbedtls.h -# for inc in $(for file in ${root}/mbedtls/include/mbedtls/*.h; do gcc -H "${file}" -I mbedtls/include/ 2>&1 | grep '^\.* mbedtls/include/mbedtls'; echo "- ${file}"; done | LC_COLLATE=C sort -r | awk '{$0=$2}!seen[$0]++'); do -# cat "$inc" | sed '/^#include ".*"/d' >> generatedmbedtls.h -# echo "" >> generatedmbedtls.h -# done -# cat "${root}/prelude_mbedtls.nim" > generatedmbedtls.nim -# echo 'type tm {.importc: "struct tm", header: "".} = object' >> generatedmbedtls.nim -# toast \ -# $compile \ -# --pnim \ -# --preprocess \ -# --nocomment \ -# --replace=_pms_rsa=u_pms_rsa \ -# --replace=_pms_dhm=u_pms_dhm \ -# --replace=_pms_ecdh=u_pms_ecdh \ -# --replace=_pms_psk=u_pms_psk \ -# --replace=_pms_dhe_psk=u_pms_dhe_psk \ -# --replace=_pms_rsa_psk=u_pms_rsa_psk \ -# --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk \ -# --replace=_pms_ecjpake=u_pms_ecjpake \ -# --includeDirs="${root}/mbedtls/include" \ -# --includeDirs="${root}/mbedtls/library" \ -# generatedmbedtls.h >> generatedmbedtls.nim - -# generate nim wrapper with nimterop -errorProc=() -for inc in ${root}/mbedtls/include/mbedtls/*.h; do - bname="$(basename "${inc}" | tr -- -. __)" - outputFile="${outputDirectory}/${bname%_h}.nim" - genFile="${genDirectory}/${bname%_h}.nim" - - echo "=======> ${outputFile}" - # add prelude - cat "${root}/prelude_mbedtls.nim" > "${outputFile}" - - if [ "${bname}" = "platform_util_h" ]; then - echo 'type tm {.importc: "struct tm", header: "".} = object' >> "${outputFile}" - fi - # add include - gcc -H "${inc}" -I"${root}/mbedtls/include" 2>&1 | - grep "^\.* ${root}/mbedtls/include/mbedtls" | - sed 's/^.*\/\(.*\)\.h/import "\1"/' >> "${outputFile}" -# grep "^#include \"mbedtls/.*\.h\".*$" "${inc}" | -# sed "s/.*\"mbedtls\/\(.*\).h\".*$/import \1/" >> "${outputFile}" - - toast \ - --pnim \ - --preprocess \ - --nocomment \ - --noHeader \ - --replace=_pms_rsa=u_pms_rsa \ - --replace=_pms_dhm=u_pms_dhm \ - --replace=_pms_ecdh=u_pms_ecdh \ - --replace=_pms_psk=u_pms_psk \ - --replace=_pms_dhe_psk=u_pms_dhe_psk \ - --replace=_pms_rsa_psk=u_pms_rsa_psk \ - --replace=_pms_ecdhe_psk=u_pms_ecdhe_psk \ - --replace=_pms_ecjpake=u_pms_ecjpake \ - --replace=private_xm1=private_xm1_1 \ - --replace=private_xm2=private_xm2_1 \ - --includeDirs="${root}/mbedtls/include" \ - --includeDirs="${root}/mbedtls/library" \ - "${inc}" > "${genFile}" - sed -i \ - -e 's/\bpassC\b/passc/g' \ - -e 's/cuchar/byte/g' \ - "${genFile}" - while read -r procLine; do - proc="$(sed 's/^proc \(.*\)\*(.*/\1/' <<< "${procLine}")" - matches="$(grep "\\<${proc}\\>" "${root}/mbedtls/tags" | sed '/library/!d')" - if [ $? -ne 0 ]; then - errorProc+=("${proc} in ${outputFile}") - continue - fi - if ! [ -z "${matches}" ]; then - echo "${matches}" | awk '{$0="{.compile: \"'"${root}"'/mbedtls/"$2"\".}"}1' - fi - done <<< "$(grep '^proc .*\*(' "${genFile}")" | sort | uniq >> "${outputFile}" - cat "${genFile}" >> "${outputFile}" -done diff --git a/mbedtls b/mbedtls deleted file mode 160000 index 8e076e4..0000000 --- a/mbedtls +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8e076e4132acd81e038288e10912e144593d32cb diff --git a/prelude_mbedtls.nim b/prelude_mbedtls.nim deleted file mode 100644 index b130ffa..0000000 --- a/prelude_mbedtls.nim +++ /dev/null @@ -1,13 +0,0 @@ -import strformat, os - -# Socket definitions -import nativesockets - -# C include directory -const root = currentSourcePath.parentDir -const mbedtlsInclude = root/"mbedtls"/"include" -const mbedtlsLibrary = root/"mbedtls"/"library" - -{.passc: fmt"-I{mbedtlsInclude}".} -{.passc: fmt"-I{mbedtlsLibrary}".} - diff --git a/webrtc.nimble b/webrtc.nimble index 11c781d..4d0acf6 100644 --- a/webrtc.nimble +++ b/webrtc.nimble @@ -8,4 +8,9 @@ license = "MIT" requires "nim >= 1.2.0", "chronicles >= 0.10.2", "chronos >= 3.0.6", - "https://github.com/status-im/nim-binary-serialization.git" + "https://github.com/status-im/nim-binary-serialization.git", + "https://github.com/status-im/nim-mbedtls.git" + + +proc runTest(filename: string) = + discard diff --git a/webrtc/mbedtls/aes.nim b/webrtc/mbedtls/aes.nim deleted file mode 100644 index 71d8367..0000000 --- a/webrtc/mbedtls/aes.nim +++ /dev/null @@ -1,78 +0,0 @@ -import "platform_time" - -{.compile: "./mbedtls/library/aes.c".} -{.compile: "./mbedtls/library/aesni.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_AES_ENCRYPT* = 1 - MBEDTLS_AES_DECRYPT* = 0 - MBEDTLS_ERR_AES_INVALID_KEY_LENGTH* = -0x00000020 - MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH* = -0x00000022 - MBEDTLS_ERR_AES_BAD_INPUT_DATA* = -0x00000021 -type - mbedtls_aes_context* {.bycopy.} = object - private_nr*: cint - private_rk_offset*: uint - private_buf*: array[68, uint32] - - mbedtls_aes_xts_context* {.bycopy.} = object - private_crypt*: mbedtls_aes_context - private_tweak*: mbedtls_aes_context - -proc mbedtls_aes_init*(ctx: ptr mbedtls_aes_context) {.importc, cdecl.} -proc mbedtls_aes_free*(ctx: ptr mbedtls_aes_context) {.importc, cdecl.} -proc mbedtls_aes_xts_init*(ctx: ptr mbedtls_aes_xts_context) {.importc, cdecl.} -proc mbedtls_aes_xts_free*(ctx: ptr mbedtls_aes_xts_context) {.importc, cdecl.} -proc mbedtls_aes_setkey_enc*(ctx: ptr mbedtls_aes_context; key: ptr byte; - keybits: cuint): cint {.importc, cdecl.} -proc mbedtls_aes_setkey_dec*(ctx: ptr mbedtls_aes_context; key: ptr byte; - keybits: cuint): cint {.importc, cdecl.} -proc mbedtls_aes_xts_setkey_enc*(ctx: ptr mbedtls_aes_xts_context; - key: ptr byte; keybits: cuint): cint {. - importc, cdecl.} -proc mbedtls_aes_xts_setkey_dec*(ctx: ptr mbedtls_aes_xts_context; - key: ptr byte; keybits: cuint): cint {. - importc, cdecl.} -proc mbedtls_aes_crypt_ecb*(ctx: ptr mbedtls_aes_context; mode: cint; - input: array[16, byte]; output: array[16, byte]): cint {. - importc, cdecl.} -proc mbedtls_aes_crypt_cbc*(ctx: ptr mbedtls_aes_context; mode: cint; - length: uint; iv: array[16, byte]; - input: ptr byte; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_aes_crypt_xts*(ctx: ptr mbedtls_aes_xts_context; mode: cint; - length: uint; data_unit: array[16, byte]; - input: ptr byte; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_aes_crypt_cfb128*(ctx: ptr mbedtls_aes_context; mode: cint; - length: uint; iv_off: ptr uint; - iv: array[16, byte]; input: ptr byte; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_aes_crypt_cfb8*(ctx: ptr mbedtls_aes_context; mode: cint; - length: uint; iv: array[16, byte]; - input: ptr byte; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_aes_crypt_ofb*(ctx: ptr mbedtls_aes_context; length: uint; - iv_off: ptr uint; iv: array[16, byte]; - input: ptr byte; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_aes_crypt_ctr*(ctx: ptr mbedtls_aes_context; length: uint; - nc_off: ptr uint; nonce_counter: array[16, byte]; - stream_block: array[16, byte]; input: ptr byte; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_internal_aes_encrypt*(ctx: ptr mbedtls_aes_context; - input: array[16, byte]; - output: array[16, byte]): cint {.importc, - cdecl.} -proc mbedtls_internal_aes_decrypt*(ctx: ptr mbedtls_aes_context; - input: array[16, byte]; - output: array[16, byte]): cint {.importc, - cdecl.} -proc mbedtls_aes_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/aria.nim b/webrtc/mbedtls/aria.nim deleted file mode 100644 index 015420a..0000000 --- a/webrtc/mbedtls/aria.nim +++ /dev/null @@ -1,47 +0,0 @@ -import "platform_time" - -{.compile: "./mbedtls/library/aria.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ARIA_ENCRYPT* = 1 - MBEDTLS_ARIA_DECRYPT* = 0 - MBEDTLS_ARIA_BLOCKSIZE* = 16 - MBEDTLS_ARIA_MAX_ROUNDS* = 16 - MBEDTLS_ARIA_MAX_KEYSIZE* = 32 - MBEDTLS_ERR_ARIA_BAD_INPUT_DATA* = -0x0000005C - MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH* = -0x0000005E -type - mbedtls_aria_context* {.bycopy.} = object - private_nr*: byte - private_rk*: array[16 + typeof(16)(1), - array[typeof(16)(16 / typeof(16)(4)), uint32]] - -proc mbedtls_aria_init*(ctx: ptr mbedtls_aria_context) {.importc, cdecl.} -proc mbedtls_aria_free*(ctx: ptr mbedtls_aria_context) {.importc, cdecl.} -proc mbedtls_aria_setkey_enc*(ctx: ptr mbedtls_aria_context; key: ptr byte; - keybits: cuint): cint {.importc, cdecl.} -proc mbedtls_aria_setkey_dec*(ctx: ptr mbedtls_aria_context; key: ptr byte; - keybits: cuint): cint {.importc, cdecl.} -proc mbedtls_aria_crypt_ecb*(ctx: ptr mbedtls_aria_context; - input: array[16, byte]; output: array[16, byte]): cint {. - importc, cdecl.} -proc mbedtls_aria_crypt_cbc*(ctx: ptr mbedtls_aria_context; mode: cint; - length: uint; iv: array[16, byte]; - input: ptr byte; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_aria_crypt_cfb128*(ctx: ptr mbedtls_aria_context; mode: cint; - length: uint; iv_off: ptr uint; - iv: array[16, byte]; input: ptr byte; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_aria_crypt_ctr*(ctx: ptr mbedtls_aria_context; length: uint; - nc_off: ptr uint; nonce_counter: array[16, byte]; - stream_block: array[16, byte]; input: ptr byte; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_aria_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/asn1.nim b/webrtc/mbedtls/asn1.nim deleted file mode 100644 index 58bd3b5..0000000 --- a/webrtc/mbedtls/asn1.nim +++ /dev/null @@ -1,107 +0,0 @@ -import "bignum" - -{.compile: "./mbedtls/library/asn1parse.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_ASN1_OUT_OF_DATA* = -0x00000060 - MBEDTLS_ERR_ASN1_UNEXPECTED_TAG* = -0x00000062 - MBEDTLS_ERR_ASN1_INVALID_LENGTH* = -0x00000064 - MBEDTLS_ERR_ASN1_LENGTH_MISMATCH* = -0x00000066 - MBEDTLS_ERR_ASN1_INVALID_DATA* = -0x00000068 - MBEDTLS_ERR_ASN1_ALLOC_FAILED* = -0x0000006A - MBEDTLS_ERR_ASN1_BUF_TOO_SMALL* = -0x0000006C - MBEDTLS_ASN1_BOOLEAN* = 0x00000001 - MBEDTLS_ASN1_INTEGER* = 0x00000002 - MBEDTLS_ASN1_BIT_STRING* = 0x00000003 - MBEDTLS_ASN1_OCTET_STRING* = 0x00000004 - MBEDTLS_ASN1_NULL* = 0x00000005 - MBEDTLS_ASN1_OID* = 0x00000006 - MBEDTLS_ASN1_ENUMERATED* = 0x0000000A - MBEDTLS_ASN1_UTF8_STRING* = 0x0000000C - MBEDTLS_ASN1_SEQUENCE* = 0x00000010 - MBEDTLS_ASN1_SET* = 0x00000011 - MBEDTLS_ASN1_PRINTABLE_STRING* = 0x00000013 - MBEDTLS_ASN1_T61_STRING* = 0x00000014 - MBEDTLS_ASN1_IA5_STRING* = 0x00000016 - MBEDTLS_ASN1_UTC_TIME* = 0x00000017 - MBEDTLS_ASN1_GENERALIZED_TIME* = 0x00000018 - MBEDTLS_ASN1_UNIVERSAL_STRING* = 0x0000001C - MBEDTLS_ASN1_BMP_STRING* = 0x0000001E - MBEDTLS_ASN1_PRIMITIVE* = 0x00000000 - MBEDTLS_ASN1_CONSTRUCTED* = 0x00000020 - MBEDTLS_ASN1_CONTEXT_SPECIFIC* = 0x00000080 - MBEDTLS_ASN1_TAG_CLASS_MASK* = 0x000000C0 - MBEDTLS_ASN1_TAG_PC_MASK* = 0x00000020 - MBEDTLS_ASN1_TAG_VALUE_MASK* = 0x0000001F -type - mbedtls_asn1_buf* {.bycopy.} = object - tag*: cint - len*: uint - p*: ptr byte - - mbedtls_asn1_bitstring* {.bycopy.} = object - len*: uint - unused_bits*: byte - p*: ptr byte - - mbedtls_asn1_sequence* {.bycopy.} = object - buf*: mbedtls_asn1_buf - next*: ptr mbedtls_asn1_sequence - - mbedtls_asn1_named_data* {.bycopy.} = object - oid*: mbedtls_asn1_buf - val*: mbedtls_asn1_buf - next*: ptr mbedtls_asn1_named_data - private_next_merged*: byte - -proc mbedtls_asn1_get_len*(p: ptr ptr byte; `end`: ptr byte; len: ptr uint): cint {. - importc, cdecl.} -proc mbedtls_asn1_get_tag*(p: ptr ptr byte; `end`: ptr byte; len: ptr uint; - tag: cint): cint {.importc, cdecl.} -proc mbedtls_asn1_get_bool*(p: ptr ptr byte; `end`: ptr byte; val: ptr cint): cint {. - importc, cdecl.} -proc mbedtls_asn1_get_int*(p: ptr ptr byte; `end`: ptr byte; val: ptr cint): cint {. - importc, cdecl.} -proc mbedtls_asn1_get_enum*(p: ptr ptr byte; `end`: ptr byte; val: ptr cint): cint {. - importc, cdecl.} -proc mbedtls_asn1_get_bitstring*(p: ptr ptr byte; `end`: ptr byte; - bs: ptr mbedtls_asn1_bitstring): cint {. - importc, cdecl.} -proc mbedtls_asn1_get_bitstring_null*(p: ptr ptr byte; `end`: ptr byte; - len: ptr uint): cint {.importc, cdecl.} -proc mbedtls_asn1_get_sequence_of*(p: ptr ptr byte; `end`: ptr byte; - cur: ptr mbedtls_asn1_sequence; tag: cint): cint {. - importc, cdecl.} -proc mbedtls_asn1_sequence_free*(seq: ptr mbedtls_asn1_sequence) {.importc, - cdecl.} -proc mbedtls_asn1_traverse_sequence_of*(p: ptr ptr byte; `end`: ptr byte; - tag_must_mask: byte; - tag_must_val: byte; - tag_may_mask: byte; - tag_may_val: byte; cb: proc ( - ctx: pointer; tag: cint; start: ptr byte; len: uint): cint {.cdecl.}; - ctx: pointer): cint {.importc, cdecl.} -proc mbedtls_asn1_get_mpi*(p: ptr ptr byte; `end`: ptr byte; - X: ptr mbedtls_mpi): cint {.importc, cdecl.} -proc mbedtls_asn1_get_alg*(p: ptr ptr byte; `end`: ptr byte; - alg: ptr mbedtls_asn1_buf; - params: ptr mbedtls_asn1_buf): cint {.importc, cdecl.} -proc mbedtls_asn1_get_alg_null*(p: ptr ptr byte; `end`: ptr byte; - alg: ptr mbedtls_asn1_buf): cint {.importc, - cdecl.} -proc mbedtls_asn1_find_named_data*(list: ptr mbedtls_asn1_named_data; - oid: cstring; len: uint): ptr mbedtls_asn1_named_data {. - importc, cdecl.} -proc mbedtls_asn1_free_named_data*(entry: ptr mbedtls_asn1_named_data) {. - importc, cdecl.} -proc mbedtls_asn1_free_named_data_list*(head: ptr ptr mbedtls_asn1_named_data) {. - importc, cdecl.} -proc mbedtls_asn1_free_named_data_list_shallow*( - name: ptr mbedtls_asn1_named_data) {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/asn1write.nim b/webrtc/mbedtls/asn1write.nim deleted file mode 100644 index be962c6..0000000 --- a/webrtc/mbedtls/asn1write.nim +++ /dev/null @@ -1,57 +0,0 @@ -import "asn1" -import "bignum" - -{.compile: "./mbedtls/library/asn1write.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -proc mbedtls_asn1_write_len*(p: ptr ptr byte; start: ptr byte; len: uint): cint {. - importc, cdecl.} -proc mbedtls_asn1_write_tag*(p: ptr ptr byte; start: ptr byte; tag: byte): cint {. - importc, cdecl.} -proc mbedtls_asn1_write_raw_buffer*(p: ptr ptr byte; start: ptr byte; - buf: ptr byte; size: uint): cint {. - importc, cdecl.} -proc mbedtls_asn1_write_mpi*(p: ptr ptr byte; start: ptr byte; - X: ptr mbedtls_mpi): cint {.importc, cdecl.} -proc mbedtls_asn1_write_null*(p: ptr ptr byte; start: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_asn1_write_oid*(p: ptr ptr byte; start: ptr byte; oid: cstring; - oid_len: uint): cint {.importc, cdecl.} -proc mbedtls_asn1_write_algorithm_identifier*(p: ptr ptr byte; - start: ptr byte; oid: cstring; oid_len: uint; par_len: uint): cint {. - importc, cdecl.} -proc mbedtls_asn1_write_bool*(p: ptr ptr byte; start: ptr byte; - boolean: cint): cint {.importc, cdecl.} -proc mbedtls_asn1_write_int*(p: ptr ptr byte; start: ptr byte; val: cint): cint {. - importc, cdecl.} -proc mbedtls_asn1_write_enum*(p: ptr ptr byte; start: ptr byte; val: cint): cint {. - importc, cdecl.} -proc mbedtls_asn1_write_tagged_string*(p: ptr ptr byte; start: ptr byte; - tag: cint; text: cstring; text_len: uint): cint {. - importc, cdecl.} -proc mbedtls_asn1_write_printable_string*(p: ptr ptr byte; start: ptr byte; - text: cstring; text_len: uint): cint {.importc, cdecl.} -proc mbedtls_asn1_write_utf8_string*(p: ptr ptr byte; start: ptr byte; - text: cstring; text_len: uint): cint {. - importc, cdecl.} -proc mbedtls_asn1_write_ia5_string*(p: ptr ptr byte; start: ptr byte; - text: cstring; text_len: uint): cint {. - importc, cdecl.} -proc mbedtls_asn1_write_bitstring*(p: ptr ptr byte; start: ptr byte; - buf: ptr byte; bits: uint): cint {.importc, - cdecl.} -proc mbedtls_asn1_write_named_bitstring*(p: ptr ptr byte; start: ptr byte; - buf: ptr byte; bits: uint): cint {.importc, cdecl.} -proc mbedtls_asn1_write_octet_string*(p: ptr ptr byte; start: ptr byte; - buf: ptr byte; size: uint): cint {. - importc, cdecl.} -proc mbedtls_asn1_store_named_data*(list: ptr ptr mbedtls_asn1_named_data; - oid: cstring; oid_len: uint; - val: ptr byte; val_len: uint): ptr mbedtls_asn1_named_data {. - importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/base64.nim b/webrtc/mbedtls/base64.nim deleted file mode 100644 index f77896e..0000000 --- a/webrtc/mbedtls/base64.nim +++ /dev/null @@ -1,19 +0,0 @@ -import "constant_time" - -{.compile: "./mbedtls/library/base64.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL* = -0x0000002A - MBEDTLS_ERR_BASE64_INVALID_CHARACTER* = -0x0000002C -proc mbedtls_base64_encode*(dst: ptr byte; dlen: uint; olen: ptr uint; - src: ptr byte; slen: uint): cint {.importc, cdecl.} -proc mbedtls_base64_decode*(dst: ptr byte; dlen: uint; olen: ptr uint; - src: ptr byte; slen: uint): cint {.importc, cdecl.} -proc mbedtls_base64_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/bignum.nim b/webrtc/mbedtls/bignum.nim deleted file mode 100644 index 2df9958..0000000 --- a/webrtc/mbedtls/bignum.nim +++ /dev/null @@ -1,144 +0,0 @@ -import "md" -import "utils" - -{.compile: "./mbedtls/library/bignum.c".} -{.compile: "./mbedtls/library/bignum_core.c".} -{.compile: "./mbedtls/library/constant_time.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(mbedtls_mpi_gen_prime_flag_t) - -const - MBEDTLS_ERR_MPI_FILE_IO_ERROR* = -0x00000002 - MBEDTLS_ERR_MPI_BAD_INPUT_DATA* = -0x00000004 - MBEDTLS_ERR_MPI_INVALID_CHARACTER* = -0x00000006 - MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL* = -0x00000008 - MBEDTLS_ERR_MPI_NEGATIVE_VALUE* = -0x0000000A - MBEDTLS_ERR_MPI_DIVISION_BY_ZERO* = -0x0000000C - MBEDTLS_ERR_MPI_NOT_ACCEPTABLE* = -0x0000000E - MBEDTLS_ERR_MPI_ALLOC_FAILED* = -0x00000010 - MBEDTLS_MPI_MAX_LIMBS* = 10000 - MBEDTLS_MPI_WINDOW_SIZE* = 2 - MBEDTLS_MPI_MAX_SIZE* = 1024 - MBEDTLS_MPI_MAX_BITS* = (8 * typeof(8)(MBEDTLS_MPI_MAX_SIZE)) - MBEDTLS_MPI_MAX_BITS_SCALE100* = (100 * typeof(100)(MBEDTLS_MPI_MAX_BITS)) - MBEDTLS_LN_2_DIV_LN_10_SCALE100* = 332 - MBEDTLS_MPI_RW_BUFFER_SIZE* = ((typeof(MBEDTLS_MPI_MAX_BITS_SCALE100)((MBEDTLS_MPI_MAX_BITS_SCALE100 + - typeof(MBEDTLS_MPI_MAX_BITS_SCALE100)(MBEDTLS_LN_2_DIV_LN_10_SCALE100) - - typeof(MBEDTLS_MPI_MAX_BITS_SCALE100)(1)) / - typeof(MBEDTLS_MPI_MAX_BITS_SCALE100)(MBEDTLS_LN_2_DIV_LN_10_SCALE100))) + - typeof(MBEDTLS_MPI_MAX_BITS_SCALE100)(10) + - typeof(MBEDTLS_MPI_MAX_BITS_SCALE100)(6)) - MBEDTLS_MPI_GEN_PRIME_FLAG_DH* = (0x00000001).mbedtls_mpi_gen_prime_flag_t - MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR* = (0x00000002).mbedtls_mpi_gen_prime_flag_t -type - mbedtls_mpi_sint* = int64 - mbedtls_mpi_uint* = uint64 - mbedtls_t_udbl* = cuint - mbedtls_mpi* {.bycopy.} = object - private_s*: cint - private_n*: uint - private_p*: ptr mbedtls_mpi_uint - -proc mbedtls_mpi_init*(X: ptr mbedtls_mpi) {.importc, cdecl.} -proc mbedtls_mpi_free*(X: ptr mbedtls_mpi) {.importc, cdecl.} -proc mbedtls_mpi_grow*(X: ptr mbedtls_mpi; nblimbs: uint): cint {.importc, cdecl.} -proc mbedtls_mpi_shrink*(X: ptr mbedtls_mpi; nblimbs: uint): cint {.importc, - cdecl.} -proc mbedtls_mpi_copy*(X: ptr mbedtls_mpi; Y: ptr mbedtls_mpi): cint {.importc, - cdecl.} -proc mbedtls_mpi_swap*(X: ptr mbedtls_mpi; Y: ptr mbedtls_mpi) {.importc, cdecl.} -proc mbedtls_mpi_safe_cond_assign*(X: ptr mbedtls_mpi; Y: ptr mbedtls_mpi; - assign: byte): cint {.importc, cdecl.} -proc mbedtls_mpi_safe_cond_swap*(X: ptr mbedtls_mpi; Y: ptr mbedtls_mpi; - swap: byte): cint {.importc, cdecl.} -proc mbedtls_mpi_lset*(X: ptr mbedtls_mpi; z: mbedtls_mpi_sint): cint {.importc, - cdecl.} -proc mbedtls_mpi_get_bit*(X: ptr mbedtls_mpi; pos: uint): cint {.importc, cdecl.} -proc mbedtls_mpi_set_bit*(X: ptr mbedtls_mpi; pos: uint; val: byte): cint {. - importc, cdecl.} -proc mbedtls_mpi_lsb*(X: ptr mbedtls_mpi): uint {.importc, cdecl.} -proc mbedtls_mpi_bitlen*(X: ptr mbedtls_mpi): uint {.importc, cdecl.} -proc mbedtls_mpi_size*(X: ptr mbedtls_mpi): uint {.importc, cdecl.} -proc mbedtls_mpi_read_string*(X: ptr mbedtls_mpi; radix: cint; s: cstring): cint {. - importc, cdecl.} -proc mbedtls_mpi_write_string*(X: ptr mbedtls_mpi; radix: cint; buf: cstring; - buflen: uint; olen: ptr uint): cint {.importc, - cdecl.} -proc mbedtls_mpi_read_file*(X: ptr mbedtls_mpi; radix: cint; fin: File): cint {. - importc, cdecl.} -proc mbedtls_mpi_write_file*(p: cstring; X: ptr mbedtls_mpi; radix: cint; - fout: File): cint {.importc, cdecl.} -proc mbedtls_mpi_read_binary*(X: ptr mbedtls_mpi; buf: ptr byte; buflen: uint): cint {. - importc, cdecl.} -proc mbedtls_mpi_read_binary_le*(X: ptr mbedtls_mpi; buf: ptr byte; - buflen: uint): cint {.importc, cdecl.} -proc mbedtls_mpi_write_binary*(X: ptr mbedtls_mpi; buf: ptr byte; buflen: uint): cint {. - importc, cdecl.} -proc mbedtls_mpi_write_binary_le*(X: ptr mbedtls_mpi; buf: ptr byte; - buflen: uint): cint {.importc, cdecl.} -proc mbedtls_mpi_shift_l*(X: ptr mbedtls_mpi; count: uint): cint {.importc, - cdecl.} -proc mbedtls_mpi_shift_r*(X: ptr mbedtls_mpi; count: uint): cint {.importc, - cdecl.} -proc mbedtls_mpi_cmp_abs*(X: ptr mbedtls_mpi; Y: ptr mbedtls_mpi): cint {. - importc, cdecl.} -proc mbedtls_mpi_cmp_mpi*(X: ptr mbedtls_mpi; Y: ptr mbedtls_mpi): cint {. - importc, cdecl.} -proc mbedtls_mpi_lt_mpi_ct*(X: ptr mbedtls_mpi; Y: ptr mbedtls_mpi; - ret: ptr cuint): cint {.importc, cdecl.} -proc mbedtls_mpi_cmp_int*(X: ptr mbedtls_mpi; z: mbedtls_mpi_sint): cint {. - importc, cdecl.} -proc mbedtls_mpi_add_abs*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; - B: ptr mbedtls_mpi): cint {.importc, cdecl.} -proc mbedtls_mpi_sub_abs*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; - B: ptr mbedtls_mpi): cint {.importc, cdecl.} -proc mbedtls_mpi_add_mpi*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; - B: ptr mbedtls_mpi): cint {.importc, cdecl.} -proc mbedtls_mpi_sub_mpi*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; - B: ptr mbedtls_mpi): cint {.importc, cdecl.} -proc mbedtls_mpi_add_int*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; - b: mbedtls_mpi_sint): cint {.importc, cdecl.} -proc mbedtls_mpi_sub_int*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; - b: mbedtls_mpi_sint): cint {.importc, cdecl.} -proc mbedtls_mpi_mul_mpi*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; - B: ptr mbedtls_mpi): cint {.importc, cdecl.} -proc mbedtls_mpi_mul_int*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; - b: mbedtls_mpi_uint): cint {.importc, cdecl.} -proc mbedtls_mpi_div_mpi*(Q: ptr mbedtls_mpi; R: ptr mbedtls_mpi; - A: ptr mbedtls_mpi; B: ptr mbedtls_mpi): cint {. - importc, cdecl.} -proc mbedtls_mpi_div_int*(Q: ptr mbedtls_mpi; R: ptr mbedtls_mpi; - A: ptr mbedtls_mpi; b: mbedtls_mpi_sint): cint {. - importc, cdecl.} -proc mbedtls_mpi_mod_mpi*(R: ptr mbedtls_mpi; A: ptr mbedtls_mpi; - B: ptr mbedtls_mpi): cint {.importc, cdecl.} -proc mbedtls_mpi_mod_int*(r: ptr mbedtls_mpi_uint; A: ptr mbedtls_mpi; - b: mbedtls_mpi_sint): cint {.importc, cdecl.} -proc mbedtls_mpi_exp_mod*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; - E: ptr mbedtls_mpi; N: ptr mbedtls_mpi; - prec_RR: ptr mbedtls_mpi): cint {.importc, cdecl.} -proc mbedtls_mpi_fill_random*(X: ptr mbedtls_mpi; size: uint; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_mpi_random*(X: ptr mbedtls_mpi; min: mbedtls_mpi_sint; - N: ptr mbedtls_mpi; f_rng: proc (a1: pointer; - a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, - cdecl.} -proc mbedtls_mpi_gcd*(G: ptr mbedtls_mpi; A: ptr mbedtls_mpi; B: ptr mbedtls_mpi): cint {. - importc, cdecl.} -proc mbedtls_mpi_inv_mod*(X: ptr mbedtls_mpi; A: ptr mbedtls_mpi; - N: ptr mbedtls_mpi): cint {.importc, cdecl.} -proc mbedtls_mpi_is_prime_ext*(X: ptr mbedtls_mpi; rounds: cint; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_mpi_gen_prime*(X: ptr mbedtls_mpi; nbits: uint; flags: cint; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_mpi_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/build_info.nim b/webrtc/mbedtls/build_info.nim deleted file mode 100644 index 3e73b60..0000000 --- a/webrtc/mbedtls/build_info.nim +++ /dev/null @@ -1,14 +0,0 @@ -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_VERSION_MAJOR* = 3 - MBEDTLS_VERSION_MINOR* = 4 - MBEDTLS_VERSION_PATCH* = 0 - MBEDTLS_VERSION_NUMBER* = 0x03040000 - MBEDTLS_VERSION_STRING* = "3.4.0" - MBEDTLS_VERSION_STRING_FULL* = "mbed TLS 3.4.0" -{.pop.} diff --git a/webrtc/mbedtls/camellia.nim b/webrtc/mbedtls/camellia.nim deleted file mode 100644 index 6e13573..0000000 --- a/webrtc/mbedtls/camellia.nim +++ /dev/null @@ -1,48 +0,0 @@ -import "platform_time" - -{.compile: "./mbedtls/library/camellia.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_CAMELLIA_ENCRYPT* = 1 - MBEDTLS_CAMELLIA_DECRYPT* = 0 - MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA* = -0x00000024 - MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH* = -0x00000026 -type - mbedtls_camellia_context* {.bycopy.} = object - private_nr*: cint - private_rk*: array[68, uint32] - -proc mbedtls_camellia_init*(ctx: ptr mbedtls_camellia_context) {.importc, cdecl.} -proc mbedtls_camellia_free*(ctx: ptr mbedtls_camellia_context) {.importc, cdecl.} -proc mbedtls_camellia_setkey_enc*(ctx: ptr mbedtls_camellia_context; - key: ptr byte; keybits: cuint): cint {. - importc, cdecl.} -proc mbedtls_camellia_setkey_dec*(ctx: ptr mbedtls_camellia_context; - key: ptr byte; keybits: cuint): cint {. - importc, cdecl.} -proc mbedtls_camellia_crypt_ecb*(ctx: ptr mbedtls_camellia_context; mode: cint; - input: array[16, byte]; - output: array[16, byte]): cint {.importc, - cdecl.} -proc mbedtls_camellia_crypt_cbc*(ctx: ptr mbedtls_camellia_context; mode: cint; - length: uint; iv: array[16, byte]; - input: ptr byte; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_camellia_crypt_cfb128*(ctx: ptr mbedtls_camellia_context; - mode: cint; length: uint; iv_off: ptr uint; - iv: array[16, byte]; input: ptr byte; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_camellia_crypt_ctr*(ctx: ptr mbedtls_camellia_context; - length: uint; nc_off: ptr uint; - nonce_counter: array[16, byte]; - stream_block: array[16, byte]; - input: ptr byte; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_camellia_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/ccm.nim b/webrtc/mbedtls/ccm.nim deleted file mode 100644 index 1695358..0000000 --- a/webrtc/mbedtls/ccm.nim +++ /dev/null @@ -1,69 +0,0 @@ -import "cipher" - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_CCM_DECRYPT* = 0 - MBEDTLS_CCM_ENCRYPT* = 1 - MBEDTLS_CCM_STAR_DECRYPT* = 2 - MBEDTLS_CCM_STAR_ENCRYPT* = 3 - MBEDTLS_ERR_CCM_BAD_INPUT* = -0x0000000D - MBEDTLS_ERR_CCM_AUTH_FAILED* = -0x0000000F -type - mbedtls_ccm_context* {.bycopy.} = object - private_y*: array[16, byte] - private_ctr*: array[16, byte] - private_cipher_ctx*: mbedtls_cipher_context_t - private_plaintext_len*: uint - private_add_len*: uint - private_tag_len*: uint - private_processed*: uint - private_q*: byte - private_mode*: byte - private_state*: cint - -proc mbedtls_ccm_init*(ctx: ptr mbedtls_ccm_context) {.importc, cdecl.} -proc mbedtls_ccm_setkey*(ctx: ptr mbedtls_ccm_context; - cipher: mbedtls_cipher_id_t; key: ptr byte; - keybits: cuint): cint {.importc, cdecl.} -proc mbedtls_ccm_free*(ctx: ptr mbedtls_ccm_context) {.importc, cdecl.} -proc mbedtls_ccm_encrypt_and_tag*(ctx: ptr mbedtls_ccm_context; length: uint; - iv: ptr byte; iv_len: uint; ad: ptr byte; - ad_len: uint; input: ptr byte; - output: ptr byte; tag: ptr byte; - tag_len: uint): cint {.importc, cdecl.} -proc mbedtls_ccm_star_encrypt_and_tag*(ctx: ptr mbedtls_ccm_context; - length: uint; iv: ptr byte; - iv_len: uint; ad: ptr byte; - ad_len: uint; input: ptr byte; - output: ptr byte; tag: ptr byte; - tag_len: uint): cint {.importc, cdecl.} -proc mbedtls_ccm_auth_decrypt*(ctx: ptr mbedtls_ccm_context; length: uint; - iv: ptr byte; iv_len: uint; ad: ptr byte; - ad_len: uint; input: ptr byte; - output: ptr byte; tag: ptr byte; - tag_len: uint): cint {.importc, cdecl.} -proc mbedtls_ccm_star_auth_decrypt*(ctx: ptr mbedtls_ccm_context; length: uint; - iv: ptr byte; iv_len: uint; - ad: ptr byte; ad_len: uint; - input: ptr byte; output: ptr byte; - tag: ptr byte; tag_len: uint): cint {. - importc, cdecl.} -proc mbedtls_ccm_starts*(ctx: ptr mbedtls_ccm_context; mode: cint; - iv: ptr byte; iv_len: uint): cint {.importc, cdecl.} -proc mbedtls_ccm_set_lengths*(ctx: ptr mbedtls_ccm_context; total_ad_len: uint; - plaintext_len: uint; tag_len: uint): cint {. - importc, cdecl.} -proc mbedtls_ccm_update_ad*(ctx: ptr mbedtls_ccm_context; ad: ptr byte; - ad_len: uint): cint {.importc, cdecl.} -proc mbedtls_ccm_update*(ctx: ptr mbedtls_ccm_context; input: ptr byte; - input_len: uint; output: ptr byte; output_size: uint; - output_len: ptr uint): cint {.importc, cdecl.} -proc mbedtls_ccm_finish*(ctx: ptr mbedtls_ccm_context; tag: ptr byte; - tag_len: uint): cint {.importc, cdecl.} -proc mbedtls_ccm_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/chacha20.nim b/webrtc/mbedtls/chacha20.nim deleted file mode 100644 index c6ee624..0000000 --- a/webrtc/mbedtls/chacha20.nim +++ /dev/null @@ -1,33 +0,0 @@ -import "platform_time" - -{.compile: "./mbedtls/library/chacha20.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA* = -0x00000051 -type - mbedtls_chacha20_context* {.bycopy.} = object - private_state*: array[16, uint32] - private_keystream8*: array[64, uint8] - private_keystream_bytes_used*: uint - -proc mbedtls_chacha20_init*(ctx: ptr mbedtls_chacha20_context) {.importc, cdecl.} -proc mbedtls_chacha20_free*(ctx: ptr mbedtls_chacha20_context) {.importc, cdecl.} -proc mbedtls_chacha20_setkey*(ctx: ptr mbedtls_chacha20_context; - key: array[32, byte]): cint {.importc, cdecl.} -proc mbedtls_chacha20_starts*(ctx: ptr mbedtls_chacha20_context; - nonce: array[12, byte]; counter: uint32): cint {. - importc, cdecl.} -proc mbedtls_chacha20_update*(ctx: ptr mbedtls_chacha20_context; size: uint; - input: ptr byte; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_chacha20_crypt*(key: array[32, byte]; nonce: array[12, byte]; - counter: uint32; size: uint; input: ptr byte; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_chacha20_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/chachapoly.nim b/webrtc/mbedtls/chachapoly.nim deleted file mode 100644 index 9c8860e..0000000 --- a/webrtc/mbedtls/chachapoly.nim +++ /dev/null @@ -1,57 +0,0 @@ -import "poly1305" -import "chacha20" -import "utils" - -{.compile: "./mbedtls/library/chachapoly.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(mbedtls_chachapoly_mode_t) - -const - MBEDTLS_ERR_CHACHAPOLY_BAD_STATE* = -0x00000054 - MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED* = -0x00000056 - MBEDTLS_CHACHAPOLY_ENCRYPT* = (0).mbedtls_chachapoly_mode_t - MBEDTLS_CHACHAPOLY_DECRYPT* = (MBEDTLS_CHACHAPOLY_ENCRYPT + 1).mbedtls_chachapoly_mode_t -type - mbedtls_chachapoly_context* {.bycopy.} = object - private_chacha20_ctx*: mbedtls_chacha20_context - private_poly1305_ctx*: mbedtls_poly1305_context - private_aad_len*: uint64 - private_ciphertext_len*: uint64 - private_state*: cint - private_mode*: mbedtls_chachapoly_mode_t - -proc mbedtls_chachapoly_init*(ctx: ptr mbedtls_chachapoly_context) {.importc, - cdecl.} -proc mbedtls_chachapoly_free*(ctx: ptr mbedtls_chachapoly_context) {.importc, - cdecl.} -proc mbedtls_chachapoly_setkey*(ctx: ptr mbedtls_chachapoly_context; - key: array[32, byte]): cint {.importc, cdecl.} -proc mbedtls_chachapoly_starts*(ctx: ptr mbedtls_chachapoly_context; - nonce: array[12, byte]; - mode: mbedtls_chachapoly_mode_t): cint {. - importc, cdecl.} -proc mbedtls_chachapoly_update_aad*(ctx: ptr mbedtls_chachapoly_context; - aad: ptr byte; aad_len: uint): cint {. - importc, cdecl.} -proc mbedtls_chachapoly_update*(ctx: ptr mbedtls_chachapoly_context; len: uint; - input: ptr byte; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_chachapoly_finish*(ctx: ptr mbedtls_chachapoly_context; - mac: array[16, byte]): cint {.importc, cdecl.} -proc mbedtls_chachapoly_encrypt_and_tag*(ctx: ptr mbedtls_chachapoly_context; - length: uint; nonce: array[12, byte]; aad: ptr byte; aad_len: uint; - input: ptr byte; output: ptr byte; tag: array[16, byte]): cint {. - importc, cdecl.} -proc mbedtls_chachapoly_auth_decrypt*(ctx: ptr mbedtls_chachapoly_context; - length: uint; nonce: array[12, byte]; - aad: ptr byte; aad_len: uint; - tag: array[16, byte]; input: ptr byte; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_chachapoly_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/cipher.nim b/webrtc/mbedtls/cipher.nim deleted file mode 100644 index 9ba99f5..0000000 --- a/webrtc/mbedtls/cipher.nim +++ /dev/null @@ -1,269 +0,0 @@ -import "aes" -import "aria" -import "camellia" -import "chachapoly" -import "des" -import "constant_time" -import "utils" - -{.compile: "./mbedtls/library/ccm.c".} -{.compile: "./mbedtls/library/gcm.c".} -{.compile: "./mbedtls/library/nist_kw.c".} -{.compile: "./mbedtls/library/cipher_wrap.c".} -{.compile: "./mbedtls/library/cipher.c".} - -# proc 'mbedtls_cipher_info_get_type' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_cipher_info_get_mode' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_cipher_info_get_key_bitlen' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_cipher_info_get_name' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_cipher_info_get_iv_size' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_cipher_info_get_block_size' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_cipher_info_has_variable_key_bitlen' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_cipher_info_has_variable_iv_size' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_cipher_get_block_size' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_cipher_get_cipher_mode' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_cipher_get_iv_size' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_cipher_get_type' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_cipher_get_name' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_cipher_get_key_bitlen' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_cipher_get_operation' skipped - static inline procs cannot work with '--noHeader | -H' - - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(mbedtls_cipher_id_t) -defineEnum(mbedtls_cipher_type_t) -defineEnum(mbedtls_cipher_mode_t) -defineEnum(mbedtls_cipher_padding_t) -defineEnum(mbedtls_operation_t) -defineEnum(Enum_cipherh1) - -const - MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE* = -0x00006080 - MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA* = -0x00006100 - MBEDTLS_ERR_CIPHER_ALLOC_FAILED* = -0x00006180 - MBEDTLS_ERR_CIPHER_INVALID_PADDING* = -0x00006200 - MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED* = -0x00006280 - MBEDTLS_ERR_CIPHER_AUTH_FAILED* = -0x00006300 - MBEDTLS_ERR_CIPHER_INVALID_CONTEXT* = -0x00006380 - MBEDTLS_CIPHER_VARIABLE_IV_LEN* = 0x00000001 - MBEDTLS_CIPHER_VARIABLE_KEY_LEN* = 0x00000002 - MBEDTLS_CIPHER_ID_NONE* = (0).mbedtls_cipher_id_t - MBEDTLS_CIPHER_ID_NULL* = (MBEDTLS_CIPHER_ID_NONE + 1).mbedtls_cipher_id_t - MBEDTLS_CIPHER_ID_AES* = (MBEDTLS_CIPHER_ID_NULL + 1).mbedtls_cipher_id_t - MBEDTLS_CIPHER_ID_DES* = (MBEDTLS_CIPHER_ID_AES + 1).mbedtls_cipher_id_t - MBEDTLS_CIPHER_ID_3DES* = (MBEDTLS_CIPHER_ID_DES + 1).mbedtls_cipher_id_t - MBEDTLS_CIPHER_ID_CAMELLIA* = (MBEDTLS_CIPHER_ID_3DES + 1).mbedtls_cipher_id_t - MBEDTLS_CIPHER_ID_ARIA* = (MBEDTLS_CIPHER_ID_CAMELLIA + 1).mbedtls_cipher_id_t - MBEDTLS_CIPHER_ID_CHACHA20* = (MBEDTLS_CIPHER_ID_ARIA + 1).mbedtls_cipher_id_t - MBEDTLS_CIPHER_NONE* = (0).mbedtls_cipher_type_t - MBEDTLS_CIPHER_NULL* = (MBEDTLS_CIPHER_NONE + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_128_ECB* = (MBEDTLS_CIPHER_NULL + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_192_ECB* = (MBEDTLS_CIPHER_AES_128_ECB + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_256_ECB* = (MBEDTLS_CIPHER_AES_192_ECB + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_128_CBC* = (MBEDTLS_CIPHER_AES_256_ECB + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_192_CBC* = (MBEDTLS_CIPHER_AES_128_CBC + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_256_CBC* = (MBEDTLS_CIPHER_AES_192_CBC + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_128_CFB128* = (MBEDTLS_CIPHER_AES_256_CBC + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_192_CFB128* = (MBEDTLS_CIPHER_AES_128_CFB128 + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_256_CFB128* = (MBEDTLS_CIPHER_AES_192_CFB128 + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_128_CTR* = (MBEDTLS_CIPHER_AES_256_CFB128 + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_192_CTR* = (MBEDTLS_CIPHER_AES_128_CTR + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_256_CTR* = (MBEDTLS_CIPHER_AES_192_CTR + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_128_GCM* = (MBEDTLS_CIPHER_AES_256_CTR + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_192_GCM* = (MBEDTLS_CIPHER_AES_128_GCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_256_GCM* = (MBEDTLS_CIPHER_AES_192_GCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_128_ECB* = (MBEDTLS_CIPHER_AES_256_GCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_192_ECB* = (MBEDTLS_CIPHER_CAMELLIA_128_ECB + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_256_ECB* = (MBEDTLS_CIPHER_CAMELLIA_192_ECB + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_128_CBC* = (MBEDTLS_CIPHER_CAMELLIA_256_ECB + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_192_CBC* = (MBEDTLS_CIPHER_CAMELLIA_128_CBC + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_256_CBC* = (MBEDTLS_CIPHER_CAMELLIA_192_CBC + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_128_CFB128* = (MBEDTLS_CIPHER_CAMELLIA_256_CBC + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_192_CFB128* = (MBEDTLS_CIPHER_CAMELLIA_128_CFB128 + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_256_CFB128* = (MBEDTLS_CIPHER_CAMELLIA_192_CFB128 + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_128_CTR* = (MBEDTLS_CIPHER_CAMELLIA_256_CFB128 + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_192_CTR* = (MBEDTLS_CIPHER_CAMELLIA_128_CTR + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_256_CTR* = (MBEDTLS_CIPHER_CAMELLIA_192_CTR + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_128_GCM* = (MBEDTLS_CIPHER_CAMELLIA_256_CTR + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_192_GCM* = (MBEDTLS_CIPHER_CAMELLIA_128_GCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_256_GCM* = (MBEDTLS_CIPHER_CAMELLIA_192_GCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_DES_ECB* = (MBEDTLS_CIPHER_CAMELLIA_256_GCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_DES_CBC* = (MBEDTLS_CIPHER_DES_ECB + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_DES_EDE_ECB* = (MBEDTLS_CIPHER_DES_CBC + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_DES_EDE_CBC* = (MBEDTLS_CIPHER_DES_EDE_ECB + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_DES_EDE3_ECB* = (MBEDTLS_CIPHER_DES_EDE_CBC + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_DES_EDE3_CBC* = (MBEDTLS_CIPHER_DES_EDE3_ECB + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_128_CCM* = (MBEDTLS_CIPHER_DES_EDE3_CBC + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_192_CCM* = (MBEDTLS_CIPHER_AES_128_CCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_256_CCM* = (MBEDTLS_CIPHER_AES_192_CCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG* = (MBEDTLS_CIPHER_AES_256_CCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG* = ( - MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG* = ( - MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_128_CCM* = (MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_192_CCM* = (MBEDTLS_CIPHER_CAMELLIA_128_CCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_256_CCM* = (MBEDTLS_CIPHER_CAMELLIA_192_CCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG* = ( - MBEDTLS_CIPHER_CAMELLIA_256_CCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG* = ( - MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG* = ( - MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_128_ECB* = (MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG + - 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_192_ECB* = (MBEDTLS_CIPHER_ARIA_128_ECB + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_256_ECB* = (MBEDTLS_CIPHER_ARIA_192_ECB + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_128_CBC* = (MBEDTLS_CIPHER_ARIA_256_ECB + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_192_CBC* = (MBEDTLS_CIPHER_ARIA_128_CBC + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_256_CBC* = (MBEDTLS_CIPHER_ARIA_192_CBC + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_128_CFB128* = (MBEDTLS_CIPHER_ARIA_256_CBC + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_192_CFB128* = (MBEDTLS_CIPHER_ARIA_128_CFB128 + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_256_CFB128* = (MBEDTLS_CIPHER_ARIA_192_CFB128 + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_128_CTR* = (MBEDTLS_CIPHER_ARIA_256_CFB128 + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_192_CTR* = (MBEDTLS_CIPHER_ARIA_128_CTR + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_256_CTR* = (MBEDTLS_CIPHER_ARIA_192_CTR + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_128_GCM* = (MBEDTLS_CIPHER_ARIA_256_CTR + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_192_GCM* = (MBEDTLS_CIPHER_ARIA_128_GCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_256_GCM* = (MBEDTLS_CIPHER_ARIA_192_GCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_128_CCM* = (MBEDTLS_CIPHER_ARIA_256_GCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_192_CCM* = (MBEDTLS_CIPHER_ARIA_128_CCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_256_CCM* = (MBEDTLS_CIPHER_ARIA_192_CCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG* = (MBEDTLS_CIPHER_ARIA_256_CCM + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG* = ( - MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG* = ( - MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_128_OFB* = (MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_192_OFB* = (MBEDTLS_CIPHER_AES_128_OFB + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_256_OFB* = (MBEDTLS_CIPHER_AES_192_OFB + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_128_XTS* = (MBEDTLS_CIPHER_AES_256_OFB + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_256_XTS* = (MBEDTLS_CIPHER_AES_128_XTS + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CHACHA20* = (MBEDTLS_CIPHER_AES_256_XTS + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_CHACHA20_POLY1305* = (MBEDTLS_CIPHER_CHACHA20 + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_128_KW* = (MBEDTLS_CIPHER_CHACHA20_POLY1305 + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_192_KW* = (MBEDTLS_CIPHER_AES_128_KW + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_256_KW* = (MBEDTLS_CIPHER_AES_192_KW + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_128_KWP* = (MBEDTLS_CIPHER_AES_256_KW + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_192_KWP* = (MBEDTLS_CIPHER_AES_128_KWP + 1).mbedtls_cipher_type_t - MBEDTLS_CIPHER_AES_256_KWP* = (MBEDTLS_CIPHER_AES_192_KWP + 1).mbedtls_cipher_type_t - MBEDTLS_MODE_NONE* = (0).mbedtls_cipher_mode_t - MBEDTLS_MODE_ECB* = (MBEDTLS_MODE_NONE + 1).mbedtls_cipher_mode_t - MBEDTLS_MODE_CBC* = (MBEDTLS_MODE_ECB + 1).mbedtls_cipher_mode_t - MBEDTLS_MODE_CFB* = (MBEDTLS_MODE_CBC + 1).mbedtls_cipher_mode_t - MBEDTLS_MODE_OFB* = (MBEDTLS_MODE_CFB + 1).mbedtls_cipher_mode_t - MBEDTLS_MODE_CTR* = (MBEDTLS_MODE_OFB + 1).mbedtls_cipher_mode_t - MBEDTLS_MODE_GCM* = (MBEDTLS_MODE_CTR + 1).mbedtls_cipher_mode_t - MBEDTLS_MODE_STREAM* = (MBEDTLS_MODE_GCM + 1).mbedtls_cipher_mode_t - MBEDTLS_MODE_CCM* = (MBEDTLS_MODE_STREAM + 1).mbedtls_cipher_mode_t - MBEDTLS_MODE_CCM_STAR_NO_TAG* = (MBEDTLS_MODE_CCM + 1).mbedtls_cipher_mode_t - MBEDTLS_MODE_XTS* = (MBEDTLS_MODE_CCM_STAR_NO_TAG + 1).mbedtls_cipher_mode_t - MBEDTLS_MODE_CHACHAPOLY* = (MBEDTLS_MODE_XTS + 1).mbedtls_cipher_mode_t - MBEDTLS_MODE_KW* = (MBEDTLS_MODE_CHACHAPOLY + 1).mbedtls_cipher_mode_t - MBEDTLS_MODE_KWP* = (MBEDTLS_MODE_KW + 1).mbedtls_cipher_mode_t - MBEDTLS_PADDING_PKCS7* = (0).mbedtls_cipher_padding_t - MBEDTLS_PADDING_ONE_AND_ZEROS* = (MBEDTLS_PADDING_PKCS7 + 1).mbedtls_cipher_padding_t - MBEDTLS_PADDING_ZEROS_AND_LEN* = (MBEDTLS_PADDING_ONE_AND_ZEROS + 1).mbedtls_cipher_padding_t - MBEDTLS_PADDING_ZEROS* = (MBEDTLS_PADDING_ZEROS_AND_LEN + 1).mbedtls_cipher_padding_t - MBEDTLS_PADDING_NONE* = (MBEDTLS_PADDING_ZEROS + 1).mbedtls_cipher_padding_t - MBEDTLS_OPERATION_NONE* = (-1).mbedtls_operation_t - MBEDTLS_DECRYPT* = (0).mbedtls_operation_t - MBEDTLS_ENCRYPT* = (MBEDTLS_DECRYPT + 1).mbedtls_operation_t - MBEDTLS_KEY_LENGTH_NONE* = (0).cint - MBEDTLS_KEY_LENGTH_DES* = (64).cint - MBEDTLS_KEY_LENGTH_DES_EDE* = (128).cint - MBEDTLS_KEY_LENGTH_DES_EDE3* = (192).cint - MBEDTLS_MAX_IV_LENGTH* = 16 - MBEDTLS_MAX_BLOCK_LENGTH* = 16 - MBEDTLS_MAX_KEY_LENGTH* = 64 -type - mbedtls_cipher_base_t* {.incompleteStruct.} = object - mbedtls_cmac_context_t* {.incompleteStruct.} = object - mbedtls_cipher_info_t* {.bycopy.} = object - private_type*: mbedtls_cipher_type_t - private_mode*: mbedtls_cipher_mode_t - private_key_bitlen*: cuint - private_name*: cstring - private_iv_size*: cuint - private_flags*: cint - private_block_size*: cuint - private_base*: ptr mbedtls_cipher_base_t - - mbedtls_cipher_context_t* {.bycopy.} = object - private_cipher_info*: ptr mbedtls_cipher_info_t - private_key_bitlen*: cint - private_operation*: mbedtls_operation_t - private_add_padding*: proc (output: ptr byte; olen: uint; data_len: uint) {. - cdecl.} - private_get_padding*: proc (input: ptr byte; ilen: uint; - data_len: ptr uint): cint {.cdecl.} - private_unprocessed_data*: array[16, byte] - private_unprocessed_len*: uint - private_iv*: array[16, byte] - private_iv_size*: uint - private_cipher_ctx*: pointer - private_cmac_ctx*: ptr mbedtls_cmac_context_t - -proc mbedtls_cipher_list*(): ptr cint {.importc, cdecl.} -proc mbedtls_cipher_info_from_string*(cipher_name: cstring): ptr mbedtls_cipher_info_t {. - importc, cdecl.} -proc mbedtls_cipher_info_from_type*(cipher_type: mbedtls_cipher_type_t): ptr mbedtls_cipher_info_t {. - importc, cdecl.} -proc mbedtls_cipher_info_from_values*(cipher_id: mbedtls_cipher_id_t; - key_bitlen: cint; - mode: mbedtls_cipher_mode_t): ptr mbedtls_cipher_info_t {. - importc, cdecl.} -proc mbedtls_cipher_init*(ctx: ptr mbedtls_cipher_context_t) {.importc, cdecl.} -proc mbedtls_cipher_free*(ctx: ptr mbedtls_cipher_context_t) {.importc, cdecl.} -proc mbedtls_cipher_setup*(ctx: ptr mbedtls_cipher_context_t; - cipher_info: ptr mbedtls_cipher_info_t): cint {. - importc, cdecl.} -proc mbedtls_cipher_setkey*(ctx: ptr mbedtls_cipher_context_t; key: ptr byte; - key_bitlen: cint; operation: mbedtls_operation_t): cint {. - importc, cdecl.} -proc mbedtls_cipher_set_padding_mode*(ctx: ptr mbedtls_cipher_context_t; - mode: mbedtls_cipher_padding_t): cint {. - importc, cdecl.} -proc mbedtls_cipher_set_iv*(ctx: ptr mbedtls_cipher_context_t; iv: ptr byte; - iv_len: uint): cint {.importc, cdecl.} -proc mbedtls_cipher_reset*(ctx: ptr mbedtls_cipher_context_t): cint {.importc, - cdecl.} -proc mbedtls_cipher_update_ad*(ctx: ptr mbedtls_cipher_context_t; - ad: ptr byte; ad_len: uint): cint {.importc, - cdecl.} -proc mbedtls_cipher_update*(ctx: ptr mbedtls_cipher_context_t; - input: ptr byte; ilen: uint; output: ptr byte; - olen: ptr uint): cint {.importc, cdecl.} -proc mbedtls_cipher_finish*(ctx: ptr mbedtls_cipher_context_t; - output: ptr byte; olen: ptr uint): cint {.importc, - cdecl.} -proc mbedtls_cipher_write_tag*(ctx: ptr mbedtls_cipher_context_t; - tag: ptr byte; tag_len: uint): cint {.importc, - cdecl.} -proc mbedtls_cipher_check_tag*(ctx: ptr mbedtls_cipher_context_t; - tag: ptr byte; tag_len: uint): cint {.importc, - cdecl.} -proc mbedtls_cipher_crypt*(ctx: ptr mbedtls_cipher_context_t; iv: ptr byte; - iv_len: uint; input: ptr byte; ilen: uint; - output: ptr byte; olen: ptr uint): cint {.importc, - cdecl.} -proc mbedtls_cipher_auth_encrypt_ext*(ctx: ptr mbedtls_cipher_context_t; - iv: ptr byte; iv_len: uint; - ad: ptr byte; ad_len: uint; - input: ptr byte; ilen: uint; - output: ptr byte; output_len: uint; - olen: ptr uint; tag_len: uint): cint {. - importc, cdecl.} -proc mbedtls_cipher_auth_decrypt_ext*(ctx: ptr mbedtls_cipher_context_t; - iv: ptr byte; iv_len: uint; - ad: ptr byte; ad_len: uint; - input: ptr byte; ilen: uint; - output: ptr byte; output_len: uint; - olen: ptr uint; tag_len: uint): cint {. - importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/cmac.nim b/webrtc/mbedtls/cmac.nim deleted file mode 100644 index b186ecc..0000000 --- a/webrtc/mbedtls/cmac.nim +++ /dev/null @@ -1,38 +0,0 @@ -import "cipher" - -{.compile: "./mbedtls/library/cmac.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_AES_BLOCK_SIZE* = 16 - MBEDTLS_DES3_BLOCK_SIZE* = 8 - MBEDTLS_CIPHER_BLKSIZE_MAX* = 16 -type - mbedtls_cmac_context_t* {.bycopy.} = object - private_state*: array[16, byte] - private_unprocessed_block*: array[16, byte] - private_unprocessed_len*: uint - -proc mbedtls_cipher_cmac_starts*(ctx: ptr mbedtls_cipher_context_t; - key: ptr byte; keybits: uint): cint {. - importc, cdecl.} -proc mbedtls_cipher_cmac_update*(ctx: ptr mbedtls_cipher_context_t; - input: ptr byte; ilen: uint): cint {.importc, - cdecl.} -proc mbedtls_cipher_cmac_finish*(ctx: ptr mbedtls_cipher_context_t; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_cipher_cmac_reset*(ctx: ptr mbedtls_cipher_context_t): cint {. - importc, cdecl.} -proc mbedtls_cipher_cmac*(cipher_info: ptr mbedtls_cipher_info_t; - key: ptr byte; keylen: uint; input: ptr byte; - ilen: uint; output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_aes_cmac_prf_128*(key: ptr byte; key_len: uint; - input: ptr byte; in_len: uint; - output: array[16, byte]): cint {.importc, cdecl.} -proc mbedtls_cmac_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/config_psa.nim b/webrtc/mbedtls/config_psa.nim deleted file mode 100644 index d4ba28a..0000000 --- a/webrtc/mbedtls/config_psa.nim +++ /dev/null @@ -1,14 +0,0 @@ -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_PSA_BUILTIN_ALG_HMAC* = 1 - PSA_WANT_ALG_HMAC* = 1 - PSA_WANT_KEY_TYPE_DERIVE* = 1 - PSA_WANT_KEY_TYPE_PASSWORD* = 1 - PSA_WANT_KEY_TYPE_PASSWORD_HASH* = 1 - PSA_WANT_KEY_TYPE_RAW_DATA* = 1 -{.pop.} diff --git a/webrtc/mbedtls/constant_time.nim b/webrtc/mbedtls/constant_time.nim deleted file mode 100644 index d03626d..0000000 --- a/webrtc/mbedtls/constant_time.nim +++ /dev/null @@ -1,10 +0,0 @@ -import "bignum" -# TODO: Remove bignum, it's not used in this file. - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} -proc mbedtls_ct_memcmp*(a: pointer; b: pointer; n: uint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/ctr_drbg.nim b/webrtc/mbedtls/ctr_drbg.nim deleted file mode 100644 index 3095af6..0000000 --- a/webrtc/mbedtls/ctr_drbg.nim +++ /dev/null @@ -1,74 +0,0 @@ -import "aes" -import "entropy" -# TODO: Remove entropy, it's not used in this file. - -{.compile: "./mbedtls/library/ctr_drbg.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED* = -0x00000034 - MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG* = -0x00000036 - MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG* = -0x00000038 - MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR* = -0x0000003A - MBEDTLS_CTR_DRBG_BLOCKSIZE* = 16 - MBEDTLS_CTR_DRBG_KEYSIZE* = 32 - MBEDTLS_CTR_DRBG_KEYBITS* = ( - MBEDTLS_CTR_DRBG_KEYSIZE * typeof(MBEDTLS_CTR_DRBG_KEYSIZE)(8)) - MBEDTLS_CTR_DRBG_SEEDLEN* = (MBEDTLS_CTR_DRBG_KEYSIZE + - typeof(MBEDTLS_CTR_DRBG_KEYSIZE)(MBEDTLS_CTR_DRBG_BLOCKSIZE)) - MBEDTLS_CTR_DRBG_ENTROPY_LEN* = 48 - MBEDTLS_CTR_DRBG_RESEED_INTERVAL* = 10000 - MBEDTLS_CTR_DRBG_MAX_INPUT* = 256 - MBEDTLS_CTR_DRBG_MAX_REQUEST* = 1024 - MBEDTLS_CTR_DRBG_MAX_SEED_INPUT* = 384 - MBEDTLS_CTR_DRBG_PR_OFF* = 0 - MBEDTLS_CTR_DRBG_PR_ON* = 1 - MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN* = 0 -type - mbedtls_ctr_drbg_context* {.bycopy.} = object - private_counter*: array[16, byte] - private_reseed_counter*: cint - private_prediction_resistance*: cint - private_entropy_len*: uint - private_reseed_interval*: cint - private_aes_ctx*: mbedtls_aes_context - private_f_entropy*: proc (a1: pointer; a2: ptr byte; a3: uint): cint {. - cdecl.} - private_p_entropy*: pointer - -proc mbedtls_ctr_drbg_init*(ctx: ptr mbedtls_ctr_drbg_context) {.importc, cdecl.} -proc mbedtls_ctr_drbg_seed*(ctx: ptr mbedtls_ctr_drbg_context; f_entropy: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_entropy: pointer; - custom: ptr byte; len: uint): cint {.importc, - cdecl.} -proc mbedtls_ctr_drbg_free*(ctx: ptr mbedtls_ctr_drbg_context) {.importc, cdecl.} -proc mbedtls_ctr_drbg_set_prediction_resistance*( - ctx: ptr mbedtls_ctr_drbg_context; resistance: cint) {.importc, cdecl.} -proc mbedtls_ctr_drbg_set_entropy_len*(ctx: ptr mbedtls_ctr_drbg_context; - len: uint) {.importc, cdecl.} -proc mbedtls_ctr_drbg_set_nonce_len*(ctx: ptr mbedtls_ctr_drbg_context; - len: uint): cint {.importc, cdecl.} -proc mbedtls_ctr_drbg_set_reseed_interval*(ctx: ptr mbedtls_ctr_drbg_context; - interval: cint) {.importc, cdecl.} -proc mbedtls_ctr_drbg_reseed*(ctx: ptr mbedtls_ctr_drbg_context; - additional: ptr byte; len: uint): cint {. - importc, cdecl.} -proc mbedtls_ctr_drbg_update*(ctx: ptr mbedtls_ctr_drbg_context; - additional: ptr byte; add_len: uint): cint {. - importc, cdecl.} -proc mbedtls_ctr_drbg_random_with_add*(p_rng: pointer; output: ptr byte; - output_len: uint; additional: ptr byte; - add_len: uint): cint {.importc, cdecl.} -proc mbedtls_ctr_drbg_random*(p_rng: pointer; output: ptr byte; - output_len: uint): cint {.importc, cdecl.} -proc mbedtls_ctr_drbg_write_seed_file*(ctx: ptr mbedtls_ctr_drbg_context; - path: cstring): cint {.importc, cdecl.} -proc mbedtls_ctr_drbg_update_seed_file*(ctx: ptr mbedtls_ctr_drbg_context; - path: cstring): cint {.importc, cdecl.} -proc mbedtls_ctr_drbg_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/debug.nim b/webrtc/mbedtls/debug.nim deleted file mode 100644 index 0dd9a9e..0000000 --- a/webrtc/mbedtls/debug.nim +++ /dev/null @@ -1,47 +0,0 @@ -import "ssl" -import "bignum" -import "ecp" -import "x509_crt" -import "ecdh" -import "utils" - -# const 'MBEDTLS_PRINTF_MS_TIME' has unsupported value 'PRId64' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(mbedtls_debug_ecdh_attr) - -const - MBEDTLS_PRINTF_SIZET* = "zu" - MBEDTLS_PRINTF_LONGLONG* = "lld" - MBEDTLS_DEBUG_ECDH_Q* = (0).mbedtls_debug_ecdh_attr - MBEDTLS_DEBUG_ECDH_QP* = (MBEDTLS_DEBUG_ECDH_Q + 1).mbedtls_debug_ecdh_attr - MBEDTLS_DEBUG_ECDH_Z* = (MBEDTLS_DEBUG_ECDH_QP + 1).mbedtls_debug_ecdh_attr -proc mbedtls_debug_set_threshold*(threshold: cint) {.importc, cdecl.} -proc mbedtls_debug_print_msg*(ssl: ptr mbedtls_ssl_context; level: cint; - file: cstring; line: cint; format: cstring) {. - importc, cdecl, varargs.} -proc mbedtls_debug_print_ret*(ssl: ptr mbedtls_ssl_context; level: cint; - file: cstring; line: cint; text: cstring; - ret: cint) {.importc, cdecl.} -proc mbedtls_debug_print_buf*(ssl: ptr mbedtls_ssl_context; level: cint; - file: cstring; line: cint; text: cstring; - buf: ptr byte; len: uint) {.importc, cdecl.} -proc mbedtls_debug_print_mpi*(ssl: ptr mbedtls_ssl_context; level: cint; - file: cstring; line: cint; text: cstring; - X: ptr mbedtls_mpi) {.importc, cdecl.} -proc mbedtls_debug_print_ecp*(ssl: ptr mbedtls_ssl_context; level: cint; - file: cstring; line: cint; text: cstring; - X: ptr mbedtls_ecp_point) {.importc, cdecl.} -proc mbedtls_debug_print_crt*(ssl: ptr mbedtls_ssl_context; level: cint; - file: cstring; line: cint; text: cstring; - crt: ptr mbedtls_x509_crt) {.importc, cdecl.} -proc mbedtls_debug_printf_ecdh*(ssl: ptr mbedtls_ssl_context; level: cint; - file: cstring; line: cint; - ecdh: ptr mbedtls_ecdh_context; - attr: mbedtls_debug_ecdh_attr) {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/des.nim b/webrtc/mbedtls/des.nim deleted file mode 100644 index 7ec04b0..0000000 --- a/webrtc/mbedtls/des.nim +++ /dev/null @@ -1,64 +0,0 @@ -import "platform_time" - -{.compile: "./mbedtls/library/des.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_DES_ENCRYPT* = 1 - MBEDTLS_DES_DECRYPT* = 0 - MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH* = -0x00000032 - MBEDTLS_DES_KEY_SIZE* = 8 -type - mbedtls_des_context* {.bycopy.} = object - private_sk*: array[32, uint32] - - mbedtls_des3_context* {.bycopy.} = object - private_sk*: array[96, uint32] - -proc mbedtls_des_init*(ctx: ptr mbedtls_des_context) {.importc, cdecl.} -proc mbedtls_des_free*(ctx: ptr mbedtls_des_context) {.importc, cdecl.} -proc mbedtls_des3_init*(ctx: ptr mbedtls_des3_context) {.importc, cdecl.} -proc mbedtls_des3_free*(ctx: ptr mbedtls_des3_context) {.importc, cdecl.} -proc mbedtls_des_key_set_parity*(key: array[8, byte]) {.importc, cdecl.} -proc mbedtls_des_key_check_key_parity*(key: array[8, byte]): cint {.importc, - cdecl.} -proc mbedtls_des_key_check_weak*(key: array[8, byte]): cint {.importc, cdecl.} -proc mbedtls_des_setkey_enc*(ctx: ptr mbedtls_des_context; key: array[8, byte]): cint {. - importc, cdecl.} -proc mbedtls_des_setkey_dec*(ctx: ptr mbedtls_des_context; key: array[8, byte]): cint {. - importc, cdecl.} -proc mbedtls_des3_set2key_enc*(ctx: ptr mbedtls_des3_context; - key: array[8 * typeof(8)(2), byte]): cint {. - importc, cdecl.} -proc mbedtls_des3_set2key_dec*(ctx: ptr mbedtls_des3_context; - key: array[8 * typeof(8)(2), byte]): cint {. - importc, cdecl.} -proc mbedtls_des3_set3key_enc*(ctx: ptr mbedtls_des3_context; - key: array[8 * typeof(8)(3), byte]): cint {. - importc, cdecl.} -proc mbedtls_des3_set3key_dec*(ctx: ptr mbedtls_des3_context; - key: array[8 * typeof(8)(3), byte]): cint {. - importc, cdecl.} -proc mbedtls_des_crypt_ecb*(ctx: ptr mbedtls_des_context; - input: array[8, byte]; output: array[8, byte]): cint {. - importc, cdecl.} -proc mbedtls_des_crypt_cbc*(ctx: ptr mbedtls_des_context; mode: cint; - length: uint; iv: array[8, byte]; - input: ptr byte; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_des3_crypt_ecb*(ctx: ptr mbedtls_des3_context; - input: array[8, byte]; output: array[8, byte]): cint {. - importc, cdecl.} -proc mbedtls_des3_crypt_cbc*(ctx: ptr mbedtls_des3_context; mode: cint; - length: uint; iv: array[8, byte]; - input: ptr byte; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_des_setkey*(SK: array[32, uint32]; key: array[8, byte]) {. - importc, cdecl.} -proc mbedtls_des_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/dhm.nim b/webrtc/mbedtls/dhm.nim deleted file mode 100644 index 7aaab62..0000000 --- a/webrtc/mbedtls/dhm.nim +++ /dev/null @@ -1,94 +0,0 @@ -import "asn1" -import "pem" -import "bignum" -import "utils" - -{.compile: "./mbedtls/library/dhm.c".} - -# const 'MBEDTLS_DHM_RFC3526_MODP_2048_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' -# const 'MBEDTLS_DHM_RFC3526_MODP_2048_G_BIN' has unsupported value '{ 0x02 }' -# const 'MBEDTLS_DHM_RFC3526_MODP_3072_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33, 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7, 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, 0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C, 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2, 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x3A, 0xD2, 0xCA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' -# const 'MBEDTLS_DHM_RFC3526_MODP_3072_G_BIN' has unsupported value '{ 0x02 }' -# const 'MBEDTLS_DHM_RFC3526_MODP_4096_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33, 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7, 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, 0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C, 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2, 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x21, 0x08, 0x01, 0x1A, 0x72, 0x3C, 0x12, 0xA7, 0x87, 0xE6, 0xD7, 0x88, 0x71, 0x9A, 0x10, 0xBD, 0xBA, 0x5B, 0x26, 0x99, 0xC3, 0x27, 0x18, 0x6A, 0xF4, 0xE2, 0x3C, 0x1A, 0x94, 0x68, 0x34, 0xB6, 0x15, 0x0B, 0xDA, 0x25, 0x83, 0xE9, 0xCA, 0x2A, 0xD4, 0x4C, 0xE8, 0xDB, 0xBB, 0xC2, 0xDB, 0x04, 0xDE, 0x8E, 0xF9, 0x2E, 0x8E, 0xFC, 0x14, 0x1F, 0xBE, 0xCA, 0xA6, 0x28, 0x7C, 0x59, 0x47, 0x4E, 0x6B, 0xC0, 0x5D, 0x99, 0xB2, 0x96, 0x4F, 0xA0, 0x90, 0xC3, 0xA2, 0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, 0xED, 0x1F, 0x61, 0x29, 0x70, 0xCE, 0xE2, 0xD7, 0xAF, 0xB8, 0x1B, 0xDD, 0x76, 0x21, 0x70, 0x48, 0x1C, 0xD0, 0x06, 0x91, 0x27, 0xD5, 0xB0, 0x5A, 0xA9, 0x93, 0xB4, 0xEA, 0x98, 0x8D, 0x8F, 0xDD, 0xC1, 0x86, 0xFF, 0xB7, 0xDC, 0x90, 0xA6, 0xC0, 0x8F, 0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x06, 0x31, 0x99, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' -# const 'MBEDTLS_DHM_RFC3526_MODP_4096_G_BIN' has unsupported value '{ 0x02 }' -# const 'MBEDTLS_DHM_RFC7919_FFDHE2048_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x28, 0x5C, 0x97, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }' -# const 'MBEDTLS_DHM_RFC7919_FFDHE2048_G_BIN' has unsupported value '{ 0x02 }' -# const 'MBEDTLS_DHM_RFC7919_FFDHE3072_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0xC6, 0x2E, 0x37, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' -# const 'MBEDTLS_DHM_RFC7919_FFDHE3072_G_BIN' has unsupported value '{ 0x02 }' -# const 'MBEDTLS_DHM_RFC7919_FFDHE4096_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x65, 0x5F, 0x6A, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' -# const 'MBEDTLS_DHM_RFC7919_FFDHE4096_G_BIN' has unsupported value '{ 0x02 }' -# const 'MBEDTLS_DHM_RFC7919_FFDHE6144_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02, 0x0B, 0xFD, 0x64, 0xB6, 0x45, 0x03, 0x6C, 0x7A, 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A, 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6, 0x3B, 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8, 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C, 0xB3, 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, 0x3A, 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71, 0x9B, 0x1F, 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F, 0x38, 0x81, 0x47, 0xFB, 0x4C, 0xFD, 0xB4, 0x77, 0xA5, 0x24, 0x71, 0xF7, 0xA9, 0xA9, 0x69, 0x10, 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8, 0xA0, 0x0E, 0xF0, 0x92, 0x35, 0x05, 0x11, 0xE3, 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E, 0x7F, 0xB2, 0x9F, 0x8C, 0x18, 0x30, 0x23, 0xC3, 0x58, 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4, 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, 0xBB, 0xC1, 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, 0x92, 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, 0xF6, 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82, 0x0A, 0xE8, 0xDB, 0x58, 0x47, 0xA6, 0x7C, 0xBE, 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C, 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E, 0x62, 0x29, 0x2C, 0x31, 0x15, 0x62, 0xA8, 0x46, 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A, 0xE4, 0x9F, 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17, 0x8C, 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03, 0xEC, 0x9D, 0x18, 0x10, 0xC6, 0x27, 0x2B, 0x04, 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, 0xD6, 0x3F, 0xDD, 0x4A, 0x8E, 0x9A, 0xDB, 0x1E, 0x69, 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1, 0xA4, 0x1D, 0x57, 0x0D, 0x79, 0x38, 0xDA, 0xD4, 0xA4, 0x0E, 0x32, 0x9C, 0xD0, 0xE4, 0x0E, 0x65, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' -# const 'MBEDTLS_DHM_RFC7919_FFDHE6144_G_BIN' has unsupported value '{ 0x02 }' -# const 'MBEDTLS_DHM_RFC7919_FFDHE8192_P_BIN' has unsupported value '{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02, 0x0B, 0xFD, 0x64, 0xB6, 0x45, 0x03, 0x6C, 0x7A, 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A, 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6, 0x3B, 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8, 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C, 0xB3, 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, 0x3A, 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71, 0x9B, 0x1F, 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F, 0x38, 0x81, 0x47, 0xFB, 0x4C, 0xFD, 0xB4, 0x77, 0xA5, 0x24, 0x71, 0xF7, 0xA9, 0xA9, 0x69, 0x10, 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8, 0xA0, 0x0E, 0xF0, 0x92, 0x35, 0x05, 0x11, 0xE3, 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E, 0x7F, 0xB2, 0x9F, 0x8C, 0x18, 0x30, 0x23, 0xC3, 0x58, 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4, 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, 0xBB, 0xC1, 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, 0x92, 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, 0xF6, 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82, 0x0A, 0xE8, 0xDB, 0x58, 0x47, 0xA6, 0x7C, 0xBE, 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C, 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E, 0x62, 0x29, 0x2C, 0x31, 0x15, 0x62, 0xA8, 0x46, 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A, 0xE4, 0x9F, 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17, 0x8C, 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03, 0xEC, 0x9D, 0x18, 0x10, 0xC6, 0x27, 0x2B, 0x04, 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, 0xD6, 0x3F, 0xDD, 0x4A, 0x8E, 0x9A, 0xDB, 0x1E, 0x69, 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1, 0xA4, 0x1D, 0x57, 0x0D, 0x79, 0x38, 0xDA, 0xD4, 0xA4, 0x0E, 0x32, 0x9C, 0xCF, 0xF4, 0x6A, 0xAA, 0x36, 0xAD, 0x00, 0x4C, 0xF6, 0x00, 0xC8, 0x38, 0x1E, 0x42, 0x5A, 0x31, 0xD9, 0x51, 0xAE, 0x64, 0xFD, 0xB2, 0x3F, 0xCE, 0xC9, 0x50, 0x9D, 0x43, 0x68, 0x7F, 0xEB, 0x69, 0xED, 0xD1, 0xCC, 0x5E, 0x0B, 0x8C, 0xC3, 0xBD, 0xF6, 0x4B, 0x10, 0xEF, 0x86, 0xB6, 0x31, 0x42, 0xA3, 0xAB, 0x88, 0x29, 0x55, 0x5B, 0x2F, 0x74, 0x7C, 0x93, 0x26, 0x65, 0xCB, 0x2C, 0x0F, 0x1C, 0xC0, 0x1B, 0xD7, 0x02, 0x29, 0x38, 0x88, 0x39, 0xD2, 0xAF, 0x05, 0xE4, 0x54, 0x50, 0x4A, 0xC7, 0x8B, 0x75, 0x82, 0x82, 0x28, 0x46, 0xC0, 0xBA, 0x35, 0xC3, 0x5F, 0x5C, 0x59, 0x16, 0x0C, 0xC0, 0x46, 0xFD, 0x82, 0x51, 0x54, 0x1F, 0xC6, 0x8C, 0x9C, 0x86, 0xB0, 0x22, 0xBB, 0x70, 0x99, 0x87, 0x6A, 0x46, 0x0E, 0x74, 0x51, 0xA8, 0xA9, 0x31, 0x09, 0x70, 0x3F, 0xEE, 0x1C, 0x21, 0x7E, 0x6C, 0x38, 0x26, 0xE5, 0x2C, 0x51, 0xAA, 0x69, 0x1E, 0x0E, 0x42, 0x3C, 0xFC, 0x99, 0xE9, 0xE3, 0x16, 0x50, 0xC1, 0x21, 0x7B, 0x62, 0x48, 0x16, 0xCD, 0xAD, 0x9A, 0x95, 0xF9, 0xD5, 0xB8, 0x01, 0x94, 0x88, 0xD9, 0xC0, 0xA0, 0xA1, 0xFE, 0x30, 0x75, 0xA5, 0x77, 0xE2, 0x31, 0x83, 0xF8, 0x1D, 0x4A, 0x3F, 0x2F, 0xA4, 0x57, 0x1E, 0xFC, 0x8C, 0xE0, 0xBA, 0x8A, 0x4F, 0xE8, 0xB6, 0x85, 0x5D, 0xFE, 0x72, 0xB0, 0xA6, 0x6E, 0xDE, 0xD2, 0xFB, 0xAB, 0xFB, 0xE5, 0x8A, 0x30, 0xFA, 0xFA, 0xBE, 0x1C, 0x5D, 0x71, 0xA8, 0x7E, 0x2F, 0x74, 0x1E, 0xF8, 0xC1, 0xFE, 0x86, 0xFE, 0xA6, 0xBB, 0xFD, 0xE5, 0x30, 0x67, 0x7F, 0x0D, 0x97, 0xD1, 0x1D, 0x49, 0xF7, 0xA8, 0x44, 0x3D, 0x08, 0x22, 0xE5, 0x06, 0xA9, 0xF4, 0x61, 0x4E, 0x01, 0x1E, 0x2A, 0x94, 0x83, 0x8F, 0xF8, 0x8C, 0xD6, 0x8C, 0x8B, 0xB7, 0xC5, 0xC6, 0x42, 0x4C, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }' -# const 'MBEDTLS_DHM_RFC7919_FFDHE8192_G_BIN' has unsupported value '{ 0x02 }' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(mbedtls_dhm_parameter) - -const - MBEDTLS_ERR_DHM_BAD_INPUT_DATA* = -0x00003080 - MBEDTLS_ERR_DHM_READ_PARAMS_FAILED* = -0x00003100 - MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED* = -0x00003180 - MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED* = -0x00003200 - MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED* = -0x00003280 - MBEDTLS_ERR_DHM_CALC_SECRET_FAILED* = -0x00003300 - MBEDTLS_ERR_DHM_INVALID_FORMAT* = -0x00003380 - MBEDTLS_ERR_DHM_ALLOC_FAILED* = -0x00003400 - MBEDTLS_ERR_DHM_FILE_IO_ERROR* = -0x00003480 - MBEDTLS_ERR_DHM_SET_GROUP_FAILED* = -0x00003580 - MBEDTLS_DHM_PARAM_P* = (0).mbedtls_dhm_parameter - MBEDTLS_DHM_PARAM_G* = (MBEDTLS_DHM_PARAM_P + 1).mbedtls_dhm_parameter - MBEDTLS_DHM_PARAM_X* = (MBEDTLS_DHM_PARAM_G + 1).mbedtls_dhm_parameter - MBEDTLS_DHM_PARAM_GX* = (MBEDTLS_DHM_PARAM_X + 1).mbedtls_dhm_parameter - MBEDTLS_DHM_PARAM_GY* = (MBEDTLS_DHM_PARAM_GX + 1).mbedtls_dhm_parameter - MBEDTLS_DHM_PARAM_K* = (MBEDTLS_DHM_PARAM_GY + 1).mbedtls_dhm_parameter -type - mbedtls_dhm_context* {.bycopy.} = object - private_P*: mbedtls_mpi - private_G*: mbedtls_mpi - private_X*: mbedtls_mpi - private_GX*: mbedtls_mpi - private_GY*: mbedtls_mpi - private_K*: mbedtls_mpi - private_RP*: mbedtls_mpi - private_Vi*: mbedtls_mpi - private_Vf*: mbedtls_mpi - private_pX*: mbedtls_mpi - -proc mbedtls_dhm_init*(ctx: ptr mbedtls_dhm_context) {.importc, cdecl.} -proc mbedtls_dhm_read_params*(ctx: ptr mbedtls_dhm_context; p: ptr ptr byte; - `end`: ptr byte): cint {.importc, cdecl.} -proc mbedtls_dhm_make_params*(ctx: ptr mbedtls_dhm_context; x_size: cint; - output: ptr byte; olen: ptr uint; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_dhm_set_group*(ctx: ptr mbedtls_dhm_context; P: ptr mbedtls_mpi; - G: ptr mbedtls_mpi): cint {.importc, cdecl.} -proc mbedtls_dhm_read_public*(ctx: ptr mbedtls_dhm_context; input: ptr byte; - ilen: uint): cint {.importc, cdecl.} -proc mbedtls_dhm_make_public*(ctx: ptr mbedtls_dhm_context; x_size: cint; - output: ptr byte; olen: uint; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_dhm_calc_secret*(ctx: ptr mbedtls_dhm_context; output: ptr byte; - output_size: uint; olen: ptr uint; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_dhm_get_bitlen*(ctx: ptr mbedtls_dhm_context): uint {.importc, - cdecl.} -proc mbedtls_dhm_get_len*(ctx: ptr mbedtls_dhm_context): uint {.importc, cdecl.} -proc mbedtls_dhm_get_value*(ctx: ptr mbedtls_dhm_context; - param: mbedtls_dhm_parameter; dest: ptr mbedtls_mpi): cint {. - importc, cdecl.} -proc mbedtls_dhm_free*(ctx: ptr mbedtls_dhm_context) {.importc, cdecl.} -proc mbedtls_dhm_parse_dhm*(dhm: ptr mbedtls_dhm_context; dhmin: ptr byte; - dhminlen: uint): cint {.importc, cdecl.} -proc mbedtls_dhm_parse_dhmfile*(dhm: ptr mbedtls_dhm_context; path: cstring): cint {. - importc, cdecl.} -proc mbedtls_dhm_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/ecdh.nim b/webrtc/mbedtls/ecdh.nim deleted file mode 100644 index bea624e..0000000 --- a/webrtc/mbedtls/ecdh.nim +++ /dev/null @@ -1,72 +0,0 @@ -import "ecp" -import "bignum" -import "utils" - -{.compile: "./mbedtls/library/ecdh.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(mbedtls_ecdh_side) -defineEnum(mbedtls_ecdh_variant) - -const - MBEDTLS_ECDH_OURS* = (0).mbedtls_ecdh_side - MBEDTLS_ECDH_THEIRS* = (MBEDTLS_ECDH_OURS + 1).mbedtls_ecdh_side - MBEDTLS_ECDH_VARIANT_NONE* = (0).mbedtls_ecdh_variant - MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0* = (MBEDTLS_ECDH_VARIANT_NONE + 1).mbedtls_ecdh_variant -type - mbedtls_ecdh_context_mbed* {.bycopy.} = object - private_grp*: mbedtls_ecp_group - private_d*: mbedtls_mpi - private_Q*: mbedtls_ecp_point - private_Qp*: mbedtls_ecp_point - private_z*: mbedtls_mpi - - Union_ecdhh1* {.union, bycopy.} = object - private_mbed_ecdh*: mbedtls_ecdh_context_mbed - - mbedtls_ecdh_context* {.bycopy.} = object - private_point_format*: uint8 - private_grp_id*: mbedtls_ecp_group_id - private_var*: mbedtls_ecdh_variant - private_ctx*: Union_ecdhh1 - -proc mbedtls_ecdh_can_do*(gid: mbedtls_ecp_group_id): cint {.importc, cdecl.} -proc mbedtls_ecdh_gen_public*(grp: ptr mbedtls_ecp_group; d: ptr mbedtls_mpi; - Q: ptr mbedtls_ecp_point; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_ecdh_compute_shared*(grp: ptr mbedtls_ecp_group; - z: ptr mbedtls_mpi; Q: ptr mbedtls_ecp_point; - d: ptr mbedtls_mpi; f_rng: proc (a1: pointer; - a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, - cdecl.} -proc mbedtls_ecdh_init*(ctx: ptr mbedtls_ecdh_context) {.importc, cdecl.} -proc mbedtls_ecdh_setup*(ctx: ptr mbedtls_ecdh_context; - grp_id: mbedtls_ecp_group_id): cint {.importc, cdecl.} -proc mbedtls_ecdh_free*(ctx: ptr mbedtls_ecdh_context) {.importc, cdecl.} -proc mbedtls_ecdh_make_params*(ctx: ptr mbedtls_ecdh_context; olen: ptr uint; - buf: ptr byte; blen: uint; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_ecdh_read_params*(ctx: ptr mbedtls_ecdh_context; - buf: ptr ptr byte; `end`: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_ecdh_get_params*(ctx: ptr mbedtls_ecdh_context; - key: ptr mbedtls_ecp_keypair; - side: mbedtls_ecdh_side): cint {.importc, cdecl.} -proc mbedtls_ecdh_make_public*(ctx: ptr mbedtls_ecdh_context; olen: ptr uint; - buf: ptr byte; blen: uint; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_ecdh_read_public*(ctx: ptr mbedtls_ecdh_context; buf: ptr byte; - blen: uint): cint {.importc, cdecl.} -proc mbedtls_ecdh_calc_secret*(ctx: ptr mbedtls_ecdh_context; olen: ptr uint; - buf: ptr byte; blen: uint; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/ecdsa.nim b/webrtc/mbedtls/ecdsa.nim deleted file mode 100644 index 93d2a27..0000000 --- a/webrtc/mbedtls/ecdsa.nim +++ /dev/null @@ -1,83 +0,0 @@ -import "ecp" -import "bignum" -import "md" -import "hmac_drbg" -import "asn1write" - -{.compile: "./mbedtls/library/ecdsa.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -type - mbedtls_ecdsa_context* = mbedtls_ecp_keypair - mbedtls_ecdsa_restart_ctx* = object -proc mbedtls_ecdsa_can_do*(gid: mbedtls_ecp_group_id): cint {.importc, cdecl.} -proc mbedtls_ecdsa_sign*(grp: ptr mbedtls_ecp_group; r: ptr mbedtls_mpi; - s: ptr mbedtls_mpi; d: ptr mbedtls_mpi; - buf: ptr byte; blen: uint; f_rng: proc (a1: pointer; - a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, - cdecl.} -proc mbedtls_ecdsa_sign_det_ext*(grp: ptr mbedtls_ecp_group; r: ptr mbedtls_mpi; - s: ptr mbedtls_mpi; d: ptr mbedtls_mpi; - buf: ptr byte; blen: uint; - md_alg: mbedtls_md_type_t; f_rng_blind: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng_blind: pointer): cint {. - importc, cdecl.} -proc mbedtls_ecdsa_sign_restartable*(grp: ptr mbedtls_ecp_group; - r: ptr mbedtls_mpi; s: ptr mbedtls_mpi; - d: ptr mbedtls_mpi; buf: ptr byte; - blen: uint; f_rng: proc (a1: pointer; - a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; f_rng_blind: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; - p_rng_blind: pointer; - rs_ctx: ptr mbedtls_ecdsa_restart_ctx): cint {. - importc, cdecl.} -proc mbedtls_ecdsa_sign_det_restartable*(grp: ptr mbedtls_ecp_group; - r: ptr mbedtls_mpi; s: ptr mbedtls_mpi; d: ptr mbedtls_mpi; buf: ptr byte; - blen: uint; md_alg: mbedtls_md_type_t; - f_rng_blind: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; - p_rng_blind: pointer; rs_ctx: ptr mbedtls_ecdsa_restart_ctx): cint {. - importc, cdecl.} -proc mbedtls_ecdsa_verify*(grp: ptr mbedtls_ecp_group; buf: ptr byte; - blen: uint; Q: ptr mbedtls_ecp_point; - r: ptr mbedtls_mpi; s: ptr mbedtls_mpi): cint {. - importc, cdecl.} -proc mbedtls_ecdsa_verify_restartable*(grp: ptr mbedtls_ecp_group; - buf: ptr byte; blen: uint; - Q: ptr mbedtls_ecp_point; - r: ptr mbedtls_mpi; s: ptr mbedtls_mpi; - rs_ctx: ptr mbedtls_ecdsa_restart_ctx): cint {. - importc, cdecl.} -proc mbedtls_ecdsa_write_signature*(ctx: ptr mbedtls_ecdsa_context; - md_alg: mbedtls_md_type_t; hash: ptr byte; - hlen: uint; sig: ptr byte; sig_size: uint; - slen: ptr uint; f_rng: proc (a1: pointer; - a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, - cdecl.} -proc mbedtls_ecdsa_write_signature_restartable*(ctx: ptr mbedtls_ecdsa_context; - md_alg: mbedtls_md_type_t; hash: ptr byte; hlen: uint; sig: ptr byte; - sig_size: uint; slen: ptr uint; - f_rng: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; - p_rng: pointer; rs_ctx: ptr mbedtls_ecdsa_restart_ctx): cint {.importc, - cdecl.} -proc mbedtls_ecdsa_read_signature*(ctx: ptr mbedtls_ecdsa_context; - hash: ptr byte; hlen: uint; - sig: ptr byte; slen: uint): cint {.importc, - cdecl.} -proc mbedtls_ecdsa_read_signature_restartable*(ctx: ptr mbedtls_ecdsa_context; - hash: ptr byte; hlen: uint; sig: ptr byte; slen: uint; - rs_ctx: ptr mbedtls_ecdsa_restart_ctx): cint {.importc, cdecl.} -proc mbedtls_ecdsa_genkey*(ctx: ptr mbedtls_ecdsa_context; - gid: mbedtls_ecp_group_id; f_rng: proc (a1: pointer; - a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, - cdecl.} -proc mbedtls_ecdsa_from_keypair*(ctx: ptr mbedtls_ecdsa_context; - key: ptr mbedtls_ecp_keypair): cint {.importc, - cdecl.} -proc mbedtls_ecdsa_init*(ctx: ptr mbedtls_ecdsa_context) {.importc, cdecl.} -proc mbedtls_ecdsa_free*(ctx: ptr mbedtls_ecdsa_context) {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/ecjpake.nim b/webrtc/mbedtls/ecjpake.nim deleted file mode 100644 index a161a55..0000000 --- a/webrtc/mbedtls/ecjpake.nim +++ /dev/null @@ -1,73 +0,0 @@ -import "ecp" -import "bignum" -import "md" -import "hash_info" -import "platform_time" -import "utils" - -{.compile: "./mbedtls/library/ecjpake.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(mbedtls_ecjpake_role) - -const - MBEDTLS_ECJPAKE_CLIENT* = (0).mbedtls_ecjpake_role - MBEDTLS_ECJPAKE_SERVER* = (MBEDTLS_ECJPAKE_CLIENT + 1).mbedtls_ecjpake_role -type - mbedtls_ecjpake_context* {.bycopy.} = object - private_md_type*: mbedtls_md_type_t - private_grp*: mbedtls_ecp_group - private_role*: mbedtls_ecjpake_role - private_point_format*: cint - private_Xm1*: mbedtls_ecp_point - private_Xm2*: mbedtls_ecp_point - private_Xp1*: mbedtls_ecp_point - private_Xp2*: mbedtls_ecp_point - private_Xp*: mbedtls_ecp_point - private_xm1_1*: mbedtls_mpi - private_xm2_1*: mbedtls_mpi - private_s*: mbedtls_mpi - -proc mbedtls_ecjpake_init*(ctx: ptr mbedtls_ecjpake_context) {.importc, cdecl.} -proc mbedtls_ecjpake_setup*(ctx: ptr mbedtls_ecjpake_context; - role: mbedtls_ecjpake_role; hash: mbedtls_md_type_t; - curve: mbedtls_ecp_group_id; secret: ptr byte; - len: uint): cint {.importc, cdecl.} -proc mbedtls_ecjpake_set_point_format*(ctx: ptr mbedtls_ecjpake_context; - point_format: cint): cint {.importc, - cdecl.} -proc mbedtls_ecjpake_check*(ctx: ptr mbedtls_ecjpake_context): cint {.importc, - cdecl.} -proc mbedtls_ecjpake_write_round_one*(ctx: ptr mbedtls_ecjpake_context; - buf: ptr byte; len: uint; - olen: ptr uint; f_rng: proc (a1: pointer; - a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, - cdecl.} -proc mbedtls_ecjpake_read_round_one*(ctx: ptr mbedtls_ecjpake_context; - buf: ptr byte; len: uint): cint {. - importc, cdecl.} -proc mbedtls_ecjpake_write_round_two*(ctx: ptr mbedtls_ecjpake_context; - buf: ptr byte; len: uint; - olen: ptr uint; f_rng: proc (a1: pointer; - a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, - cdecl.} -proc mbedtls_ecjpake_read_round_two*(ctx: ptr mbedtls_ecjpake_context; - buf: ptr byte; len: uint): cint {. - importc, cdecl.} -proc mbedtls_ecjpake_derive_secret*(ctx: ptr mbedtls_ecjpake_context; - buf: ptr byte; len: uint; olen: ptr uint; - f_rng: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; - p_rng: pointer): cint {.importc, cdecl.} -proc mbedtls_ecjpake_write_shared_key*(ctx: ptr mbedtls_ecjpake_context; - buf: ptr byte; len: uint; - olen: ptr uint; f_rng: proc (a1: pointer; - a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, - cdecl.} -proc mbedtls_ecjpake_free*(ctx: ptr mbedtls_ecjpake_context) {.importc, cdecl.} -proc mbedtls_ecjpake_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/ecp.nim b/webrtc/mbedtls/ecp.nim deleted file mode 100644 index fe7a88f..0000000 --- a/webrtc/mbedtls/ecp.nim +++ /dev/null @@ -1,200 +0,0 @@ -import "bignum" -import "utils" - -{.compile: "./mbedtls/library/ecp.c".} -{.compile: "./mbedtls/library/ecp_curves.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(mbedtls_ecp_group_id) -defineEnum(mbedtls_ecp_curve_type) -defineEnum(mbedtls_ecp_modulus_type) - -const - MBEDTLS_ERR_ECP_BAD_INPUT_DATA* = -0x00004F80 - MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL* = -0x00004F00 - MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE* = -0x00004E80 - MBEDTLS_ERR_ECP_VERIFY_FAILED* = -0x00004E00 - MBEDTLS_ERR_ECP_ALLOC_FAILED* = -0x00004D80 - MBEDTLS_ERR_ECP_RANDOM_FAILED* = -0x00004D00 - MBEDTLS_ERR_ECP_INVALID_KEY* = -0x00004C80 - MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH* = -0x00004C00 - MBEDTLS_ERR_ECP_IN_PROGRESS* = -0x00004B00 - MBEDTLS_ECP_DP_NONE* = (0).mbedtls_ecp_group_id - MBEDTLS_ECP_DP_SECP192R1* = (MBEDTLS_ECP_DP_NONE + 1).mbedtls_ecp_group_id - MBEDTLS_ECP_DP_SECP224R1* = (MBEDTLS_ECP_DP_SECP192R1 + 1).mbedtls_ecp_group_id - MBEDTLS_ECP_DP_SECP256R1* = (MBEDTLS_ECP_DP_SECP224R1 + 1).mbedtls_ecp_group_id - MBEDTLS_ECP_DP_SECP384R1* = (MBEDTLS_ECP_DP_SECP256R1 + 1).mbedtls_ecp_group_id - MBEDTLS_ECP_DP_SECP521R1* = (MBEDTLS_ECP_DP_SECP384R1 + 1).mbedtls_ecp_group_id - MBEDTLS_ECP_DP_BP256R1* = (MBEDTLS_ECP_DP_SECP521R1 + 1).mbedtls_ecp_group_id - MBEDTLS_ECP_DP_BP384R1* = (MBEDTLS_ECP_DP_BP256R1 + 1).mbedtls_ecp_group_id - MBEDTLS_ECP_DP_BP512R1* = (MBEDTLS_ECP_DP_BP384R1 + 1).mbedtls_ecp_group_id - MBEDTLS_ECP_DP_CURVE25519* = (MBEDTLS_ECP_DP_BP512R1 + 1).mbedtls_ecp_group_id - MBEDTLS_ECP_DP_SECP192K1* = (MBEDTLS_ECP_DP_CURVE25519 + 1).mbedtls_ecp_group_id - MBEDTLS_ECP_DP_SECP224K1* = (MBEDTLS_ECP_DP_SECP192K1 + 1).mbedtls_ecp_group_id - MBEDTLS_ECP_DP_SECP256K1* = (MBEDTLS_ECP_DP_SECP224K1 + 1).mbedtls_ecp_group_id - MBEDTLS_ECP_DP_CURVE448* = (MBEDTLS_ECP_DP_SECP256K1 + 1).mbedtls_ecp_group_id - MBEDTLS_ECP_DP_MAX* = 14 - MBEDTLS_ECP_TYPE_NONE* = (0).mbedtls_ecp_curve_type - MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS* = (MBEDTLS_ECP_TYPE_NONE + 1).mbedtls_ecp_curve_type - MBEDTLS_ECP_TYPE_MONTGOMERY* = (MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS + 1).mbedtls_ecp_curve_type - MBEDTLS_ECP_MOD_NONE* = (0).mbedtls_ecp_modulus_type - MBEDTLS_ECP_MOD_COORDINATE* = (MBEDTLS_ECP_MOD_NONE + 1).mbedtls_ecp_modulus_type - MBEDTLS_ECP_MOD_SCALAR* = (MBEDTLS_ECP_MOD_COORDINATE + 1).mbedtls_ecp_modulus_type - MBEDTLS_ECP_WINDOW_SIZE* = 4 - MBEDTLS_ECP_FIXED_POINT_OPTIM* = 1 - MBEDTLS_ECP_MAX_BITS* = 521 - MBEDTLS_ECP_MAX_BYTES* = (typeof(MBEDTLS_ECP_MAX_BITS)(( - MBEDTLS_ECP_MAX_BITS + typeof(MBEDTLS_ECP_MAX_BITS)(7)) / - typeof(MBEDTLS_ECP_MAX_BITS)(8))) - MBEDTLS_ECP_MAX_PT_LEN* = (2 * typeof(2)(MBEDTLS_ECP_MAX_BYTES) + typeof(2)(1)) - MBEDTLS_ECP_PF_UNCOMPRESSED* = 0 - MBEDTLS_ECP_PF_COMPRESSED* = 1 - MBEDTLS_ECP_TLS_NAMED_CURVE* = 3 -type - mbedtls_ecp_curve_info* {.bycopy.} = object - grp_id*: mbedtls_ecp_group_id - tls_id*: uint16 - bit_size*: uint16 - name*: cstring - - mbedtls_ecp_point* {.bycopy.} = object - private_X*: mbedtls_mpi - private_Y*: mbedtls_mpi - private_Z*: mbedtls_mpi - - mbedtls_ecp_group* {.bycopy.} = object - id*: mbedtls_ecp_group_id - P*: mbedtls_mpi - A*: mbedtls_mpi - B*: mbedtls_mpi - G*: mbedtls_ecp_point - N*: mbedtls_mpi - pbits*: uint - nbits*: uint - private_h*: cuint - private_modp*: proc (a1: ptr mbedtls_mpi): cint {.cdecl.} - private_t_pre*: proc (a1: ptr mbedtls_ecp_point; a2: pointer): cint {.cdecl.} - private_t_post*: proc (a1: ptr mbedtls_ecp_point; a2: pointer): cint {.cdecl.} - private_t_data*: pointer - private_T*: ptr mbedtls_ecp_point - private_T_size*: uint - - mbedtls_ecp_restart_ctx* = object - mbedtls_ecp_keypair* {.bycopy.} = object - private_grp*: mbedtls_ecp_group - private_d*: mbedtls_mpi - private_Q*: mbedtls_ecp_point - -proc mbedtls_ecp_get_type*(grp: ptr mbedtls_ecp_group): mbedtls_ecp_curve_type {. - importc, cdecl.} -proc mbedtls_ecp_curve_list*(): ptr mbedtls_ecp_curve_info {.importc, cdecl.} -proc mbedtls_ecp_grp_id_list*(): ptr mbedtls_ecp_group_id {.importc, cdecl.} -proc mbedtls_ecp_curve_info_from_grp_id*(grp_id: mbedtls_ecp_group_id): ptr mbedtls_ecp_curve_info {. - importc, cdecl.} -proc mbedtls_ecp_curve_info_from_tls_id*(tls_id: uint16): ptr mbedtls_ecp_curve_info {. - importc, cdecl.} -proc mbedtls_ecp_curve_info_from_name*(name: cstring): ptr mbedtls_ecp_curve_info {. - importc, cdecl.} -proc mbedtls_ecp_point_init*(pt: ptr mbedtls_ecp_point) {.importc, cdecl.} -proc mbedtls_ecp_group_init*(grp: ptr mbedtls_ecp_group) {.importc, cdecl.} -proc mbedtls_ecp_keypair_init*(key: ptr mbedtls_ecp_keypair) {.importc, cdecl.} -proc mbedtls_ecp_point_free*(pt: ptr mbedtls_ecp_point) {.importc, cdecl.} -proc mbedtls_ecp_group_free*(grp: ptr mbedtls_ecp_group) {.importc, cdecl.} -proc mbedtls_ecp_keypair_free*(key: ptr mbedtls_ecp_keypair) {.importc, cdecl.} -proc mbedtls_ecp_copy*(P: ptr mbedtls_ecp_point; Q: ptr mbedtls_ecp_point): cint {. - importc, cdecl.} -proc mbedtls_ecp_group_copy*(dst: ptr mbedtls_ecp_group; - src: ptr mbedtls_ecp_group): cint {.importc, cdecl.} -proc mbedtls_ecp_set_zero*(pt: ptr mbedtls_ecp_point): cint {.importc, cdecl.} -proc mbedtls_ecp_is_zero*(pt: ptr mbedtls_ecp_point): cint {.importc, cdecl.} -proc mbedtls_ecp_point_cmp*(P: ptr mbedtls_ecp_point; Q: ptr mbedtls_ecp_point): cint {. - importc, cdecl.} -proc mbedtls_ecp_point_read_string*(P: ptr mbedtls_ecp_point; radix: cint; - x: cstring; y: cstring): cint {.importc, - cdecl.} -proc mbedtls_ecp_point_write_binary*(grp: ptr mbedtls_ecp_group; - P: ptr mbedtls_ecp_point; format: cint; - olen: ptr uint; buf: ptr byte; - buflen: uint): cint {.importc, cdecl.} -proc mbedtls_ecp_point_read_binary*(grp: ptr mbedtls_ecp_group; - P: ptr mbedtls_ecp_point; buf: ptr byte; - ilen: uint): cint {.importc, cdecl.} -proc mbedtls_ecp_tls_read_point*(grp: ptr mbedtls_ecp_group; - pt: ptr mbedtls_ecp_point; buf: ptr ptr byte; - len: uint): cint {.importc, cdecl.} -proc mbedtls_ecp_tls_write_point*(grp: ptr mbedtls_ecp_group; - pt: ptr mbedtls_ecp_point; format: cint; - olen: ptr uint; buf: ptr byte; blen: uint): cint {. - importc, cdecl.} -proc mbedtls_ecp_group_load*(grp: ptr mbedtls_ecp_group; - id: mbedtls_ecp_group_id): cint {.importc, cdecl.} -proc mbedtls_ecp_tls_read_group*(grp: ptr mbedtls_ecp_group; - buf: ptr ptr byte; len: uint): cint {. - importc, cdecl.} -proc mbedtls_ecp_tls_read_group_id*(grp: ptr mbedtls_ecp_group_id; - buf: ptr ptr byte; len: uint): cint {. - importc, cdecl.} -proc mbedtls_ecp_tls_write_group*(grp: ptr mbedtls_ecp_group; olen: ptr uint; - buf: ptr byte; blen: uint): cint {.importc, - cdecl.} -proc mbedtls_ecp_mul*(grp: ptr mbedtls_ecp_group; R: ptr mbedtls_ecp_point; - m: ptr mbedtls_mpi; P: ptr mbedtls_ecp_point; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_ecp_mul_restartable*(grp: ptr mbedtls_ecp_group; - R: ptr mbedtls_ecp_point; m: ptr mbedtls_mpi; - P: ptr mbedtls_ecp_point; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; - rs_ctx: ptr mbedtls_ecp_restart_ctx): cint {. - importc, cdecl.} -proc mbedtls_ecp_muladd*(grp: ptr mbedtls_ecp_group; R: ptr mbedtls_ecp_point; - m: ptr mbedtls_mpi; P: ptr mbedtls_ecp_point; - n: ptr mbedtls_mpi; Q: ptr mbedtls_ecp_point): cint {. - importc, cdecl.} -proc mbedtls_ecp_muladd_restartable*(grp: ptr mbedtls_ecp_group; - R: ptr mbedtls_ecp_point; - m: ptr mbedtls_mpi; - P: ptr mbedtls_ecp_point; - n: ptr mbedtls_mpi; - Q: ptr mbedtls_ecp_point; - rs_ctx: ptr mbedtls_ecp_restart_ctx): cint {. - importc, cdecl.} -proc mbedtls_ecp_check_pubkey*(grp: ptr mbedtls_ecp_group; - pt: ptr mbedtls_ecp_point): cint {.importc, cdecl.} -proc mbedtls_ecp_check_privkey*(grp: ptr mbedtls_ecp_group; d: ptr mbedtls_mpi): cint {. - importc, cdecl.} -proc mbedtls_ecp_gen_privkey*(grp: ptr mbedtls_ecp_group; d: ptr mbedtls_mpi; - f_rng: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; - p_rng: pointer): cint {.importc, cdecl.} -proc mbedtls_ecp_gen_keypair_base*(grp: ptr mbedtls_ecp_group; - G: ptr mbedtls_ecp_point; d: ptr mbedtls_mpi; - Q: ptr mbedtls_ecp_point; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_ecp_gen_keypair*(grp: ptr mbedtls_ecp_group; d: ptr mbedtls_mpi; - Q: ptr mbedtls_ecp_point; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_ecp_gen_key*(grp_id: mbedtls_ecp_group_id; - key: ptr mbedtls_ecp_keypair; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_ecp_read_key*(grp_id: mbedtls_ecp_group_id; - key: ptr mbedtls_ecp_keypair; buf: ptr byte; - buflen: uint): cint {.importc, cdecl.} -proc mbedtls_ecp_write_key*(key: ptr mbedtls_ecp_keypair; buf: ptr byte; - buflen: uint): cint {.importc, cdecl.} -proc mbedtls_ecp_check_pub_priv*(pub: ptr mbedtls_ecp_keypair; - prv: ptr mbedtls_ecp_keypair; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_ecp_export*(key: ptr mbedtls_ecp_keypair; - grp: ptr mbedtls_ecp_group; d: ptr mbedtls_mpi; - Q: ptr mbedtls_ecp_point): cint {.importc, cdecl.} -proc mbedtls_ecp_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/entropy.nim b/webrtc/mbedtls/entropy.nim deleted file mode 100644 index fd6281e..0000000 --- a/webrtc/mbedtls/entropy.nim +++ /dev/null @@ -1,64 +0,0 @@ -import "md" - -{.compile: "./mbedtls/library/entropy.c".} -{.compile: "./mbedtls/library/entropy_poll.c".} - -# const 'MBEDTLS_ENTROPY_MD' has unsupported value 'MBEDTLS_MD_SHA512' -# const 'MBEDTLS_ENTROPY_SOURCE_MANUAL' has unsupported value 'MBEDTLS_ENTROPY_MAX_SOURCES' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ENTROPY_BLOCK_SIZE* = 64 - MBEDTLS_ERR_ENTROPY_SOURCE_FAILED* = -0x0000003C - MBEDTLS_ERR_ENTROPY_MAX_SOURCES* = -0x0000003E - MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED* = -0x00000040 - MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE* = -0x0000003D - MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR* = -0x0000003F - MBEDTLS_ENTROPY_MAX_SOURCES* = 20 - MBEDTLS_ENTROPY_MAX_GATHER* = 128 - MBEDTLS_ENTROPY_MAX_SEED_SIZE* = 1024 - MBEDTLS_ENTROPY_SOURCE_STRONG* = 1 - MBEDTLS_ENTROPY_SOURCE_WEAK* = 0 -type - mbedtls_entropy_f_source_ptr* = proc (data: pointer; output: ptr byte; - len: uint; olen: ptr uint): cint {.cdecl.} - mbedtls_entropy_source_state* {.bycopy.} = object - private_f_source*: mbedtls_entropy_f_source_ptr - private_p_source*: pointer - private_size*: uint - private_threshold*: uint - private_strong*: cint - - mbedtls_entropy_context* {.bycopy.} = object - private_accumulator_started*: cint - private_accumulator*: mbedtls_md_context_t - private_source_count*: cint - private_source*: array[20, mbedtls_entropy_source_state] - -proc mbedtls_platform_entropy_poll*(data: pointer; output: ptr byte; - len: uint; olen: ptr uint): cint {.importc, - cdecl.} -proc mbedtls_entropy_init*(ctx: ptr mbedtls_entropy_context) {.importc, cdecl.} -proc mbedtls_entropy_free*(ctx: ptr mbedtls_entropy_context) {.importc, cdecl.} -proc mbedtls_entropy_add_source*(ctx: ptr mbedtls_entropy_context; - f_source: mbedtls_entropy_f_source_ptr; - p_source: pointer; threshold: uint; - strong: cint): cint {.importc, cdecl.} -proc mbedtls_entropy_gather*(ctx: ptr mbedtls_entropy_context): cint {.importc, - cdecl.} -proc mbedtls_entropy_func*(data: pointer; output: ptr byte; len: uint): cint {. - importc, cdecl.} -proc mbedtls_entropy_update_manual*(ctx: ptr mbedtls_entropy_context; - data: ptr byte; len: uint): cint {. - importc, cdecl.} -proc mbedtls_entropy_write_seed_file*(ctx: ptr mbedtls_entropy_context; - path: cstring): cint {.importc, cdecl.} -proc mbedtls_entropy_update_seed_file*(ctx: ptr mbedtls_entropy_context; - path: cstring): cint {.importc, cdecl.} -proc mbedtls_entropy_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/error.nim b/webrtc/mbedtls/error.nim deleted file mode 100644 index 5b0f608..0000000 --- a/webrtc/mbedtls/error.nim +++ /dev/null @@ -1,20 +0,0 @@ -{.compile: "./mbedtls/library/error.c".} - -# proc 'mbedtls_error_add' skipped - static inline procs cannot work with '--noHeader | -H' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_ERROR_GENERIC_ERROR* = -0x00000001 - MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED* = -0x0000006E - MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED* = -0x00000070 - MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED* = -0x00000072 -proc mbedtls_strerror*(errnum: cint; buffer: cstring; buflen: uint) {.importc, - cdecl.} -proc mbedtls_high_level_strerr*(error_code: cint): cstring {.importc, cdecl.} -proc mbedtls_low_level_strerr*(error_code: cint): cstring {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/gcm.nim b/webrtc/mbedtls/gcm.nim deleted file mode 100644 index 21e29c4..0000000 --- a/webrtc/mbedtls/gcm.nim +++ /dev/null @@ -1,55 +0,0 @@ -import "cipher" - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_GCM_ENCRYPT* = 1 - MBEDTLS_GCM_DECRYPT* = 0 - MBEDTLS_ERR_GCM_AUTH_FAILED* = -0x00000012 - MBEDTLS_ERR_GCM_BAD_INPUT* = -0x00000014 - MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL* = -0x00000016 -type - mbedtls_gcm_context* {.bycopy.} = object - private_cipher_ctx*: mbedtls_cipher_context_t - private_HL*: array[16, uint64] - private_HH*: array[16, uint64] - private_len*: uint64 - private_add_len*: uint64 - private_base_ectr*: array[16, byte] - private_y*: array[16, byte] - private_buf*: array[16, byte] - private_mode*: cint - -proc mbedtls_gcm_init*(ctx: ptr mbedtls_gcm_context) {.importc, cdecl.} -proc mbedtls_gcm_setkey*(ctx: ptr mbedtls_gcm_context; - cipher: mbedtls_cipher_id_t; key: ptr byte; - keybits: cuint): cint {.importc, cdecl.} -proc mbedtls_gcm_crypt_and_tag*(ctx: ptr mbedtls_gcm_context; mode: cint; - length: uint; iv: ptr byte; iv_len: uint; - add: ptr byte; add_len: uint; - input: ptr byte; output: ptr byte; - tag_len: uint; tag: ptr byte): cint {.importc, - cdecl.} -proc mbedtls_gcm_auth_decrypt*(ctx: ptr mbedtls_gcm_context; length: uint; - iv: ptr byte; iv_len: uint; add: ptr byte; - add_len: uint; tag: ptr byte; tag_len: uint; - input: ptr byte; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_gcm_starts*(ctx: ptr mbedtls_gcm_context; mode: cint; - iv: ptr byte; iv_len: uint): cint {.importc, cdecl.} -proc mbedtls_gcm_update_ad*(ctx: ptr mbedtls_gcm_context; add: ptr byte; - add_len: uint): cint {.importc, cdecl.} -proc mbedtls_gcm_update*(ctx: ptr mbedtls_gcm_context; input: ptr byte; - input_length: uint; output: ptr byte; - output_size: uint; output_length: ptr uint): cint {. - importc, cdecl.} -proc mbedtls_gcm_finish*(ctx: ptr mbedtls_gcm_context; output: ptr byte; - output_size: uint; output_length: ptr uint; - tag: ptr byte; tag_len: uint): cint {.importc, cdecl.} -proc mbedtls_gcm_free*(ctx: ptr mbedtls_gcm_context) {.importc, cdecl.} -proc mbedtls_gcm_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/hash_info.nim b/webrtc/mbedtls/hash_info.nim deleted file mode 100644 index 536b204..0000000 --- a/webrtc/mbedtls/hash_info.nim +++ /dev/null @@ -1,4 +0,0 @@ -# TODO: Put the .compile. pragma in one of the file using it without breaking everything -{.compile: "./mbedtls/library/hash_info.c".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} diff --git a/webrtc/mbedtls/hkdf.nim b/webrtc/mbedtls/hkdf.nim deleted file mode 100644 index 2b2e3cf..0000000 --- a/webrtc/mbedtls/hkdf.nim +++ /dev/null @@ -1,23 +0,0 @@ -import "md" - -{.compile: "./mbedtls/library/hkdf.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_HKDF_BAD_INPUT_DATA* = -0x00005F80 -proc mbedtls_hkdf*(md: ptr mbedtls_md_info_t; salt: ptr byte; salt_len: uint; - ikm: ptr byte; ikm_len: uint; info: ptr byte; - info_len: uint; okm: ptr byte; okm_len: uint): cint {. - importc, cdecl.} -proc mbedtls_hkdf_extract*(md: ptr mbedtls_md_info_t; salt: ptr byte; - salt_len: uint; ikm: ptr byte; ikm_len: uint; - prk: ptr byte): cint {.importc, cdecl.} -proc mbedtls_hkdf_expand*(md: ptr mbedtls_md_info_t; prk: ptr byte; - prk_len: uint; info: ptr byte; info_len: uint; - okm: ptr byte; okm_len: uint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/hmac_drbg.nim b/webrtc/mbedtls/hmac_drbg.nim deleted file mode 100644 index 009d96f..0000000 --- a/webrtc/mbedtls/hmac_drbg.nim +++ /dev/null @@ -1,70 +0,0 @@ -import "md" - -{.compile: "./mbedtls/library/hmac_drbg.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG* = -0x00000003 - MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG* = -0x00000005 - MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR* = -0x00000007 - MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED* = -0x00000009 - MBEDTLS_HMAC_DRBG_RESEED_INTERVAL* = 10000 - MBEDTLS_HMAC_DRBG_MAX_INPUT* = 256 - MBEDTLS_HMAC_DRBG_MAX_REQUEST* = 1024 - MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT* = 384 - MBEDTLS_HMAC_DRBG_PR_OFF* = 0 - MBEDTLS_HMAC_DRBG_PR_ON* = 1 -type - mbedtls_hmac_drbg_context* {.bycopy.} = object - private_md_ctx*: mbedtls_md_context_t - private_V*: array[64, byte] - private_reseed_counter*: cint - private_entropy_len*: uint - private_prediction_resistance*: cint - private_reseed_interval*: cint - private_f_entropy*: proc (a1: pointer; a2: ptr byte; a3: uint): cint {. - cdecl.} - private_p_entropy*: pointer - -proc mbedtls_hmac_drbg_init*(ctx: ptr mbedtls_hmac_drbg_context) {.importc, - cdecl.} -proc mbedtls_hmac_drbg_seed*(ctx: ptr mbedtls_hmac_drbg_context; - md_info: ptr mbedtls_md_info_t; f_entropy: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_entropy: pointer; - custom: ptr byte; len: uint): cint {.importc, - cdecl.} -proc mbedtls_hmac_drbg_seed_buf*(ctx: ptr mbedtls_hmac_drbg_context; - md_info: ptr mbedtls_md_info_t; - data: ptr byte; data_len: uint): cint {. - importc, cdecl.} -proc mbedtls_hmac_drbg_set_prediction_resistance*( - ctx: ptr mbedtls_hmac_drbg_context; resistance: cint) {.importc, cdecl.} -proc mbedtls_hmac_drbg_set_entropy_len*(ctx: ptr mbedtls_hmac_drbg_context; - len: uint) {.importc, cdecl.} -proc mbedtls_hmac_drbg_set_reseed_interval*(ctx: ptr mbedtls_hmac_drbg_context; - interval: cint) {.importc, cdecl.} -proc mbedtls_hmac_drbg_update*(ctx: ptr mbedtls_hmac_drbg_context; - additional: ptr byte; add_len: uint): cint {. - importc, cdecl.} -proc mbedtls_hmac_drbg_reseed*(ctx: ptr mbedtls_hmac_drbg_context; - additional: ptr byte; len: uint): cint {. - importc, cdecl.} -proc mbedtls_hmac_drbg_random_with_add*(p_rng: pointer; output: ptr byte; - output_len: uint; - additional: ptr byte; add_len: uint): cint {. - importc, cdecl.} -proc mbedtls_hmac_drbg_random*(p_rng: pointer; output: ptr byte; out_len: uint): cint {. - importc, cdecl.} -proc mbedtls_hmac_drbg_free*(ctx: ptr mbedtls_hmac_drbg_context) {.importc, - cdecl.} -proc mbedtls_hmac_drbg_write_seed_file*(ctx: ptr mbedtls_hmac_drbg_context; - path: cstring): cint {.importc, cdecl.} -proc mbedtls_hmac_drbg_update_seed_file*(ctx: ptr mbedtls_hmac_drbg_context; - path: cstring): cint {.importc, cdecl.} -proc mbedtls_hmac_drbg_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/lms.nim b/webrtc/mbedtls/lms.nim deleted file mode 100644 index 8713064..0000000 --- a/webrtc/mbedtls/lms.nim +++ /dev/null @@ -1,63 +0,0 @@ -import "psa/crypto" -import "utils" - -{.compile: "./mbedtls/library/lms.c".} -{.compile: "./mbedtls/library/lmots.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(mbedtls_lms_algorithm_type_t) -defineEnum(mbedtls_lmots_algorithm_type_t) - -const - MBEDTLS_ERR_LMS_BAD_INPUT_DATA* = -0x00000011 - MBEDTLS_ERR_LMS_OUT_OF_PRIVATE_KEYS* = -0x00000013 - MBEDTLS_ERR_LMS_VERIFY_FAILED* = -0x00000015 - MBEDTLS_ERR_LMS_ALLOC_FAILED* = -0x00000017 - MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL* = -0x00000019 - MBEDTLS_LMOTS_N_HASH_LEN_MAX* = (32'u) - MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT_MAX* = (34'u) - MBEDTLS_LMOTS_I_KEY_ID_LEN* = (16'u) - MBEDTLS_LMOTS_Q_LEAF_ID_LEN* = (4'u) - MBEDTLS_LMOTS_TYPE_LEN* = (4'u) - MBEDTLS_LMS_TYPE_LEN* = (4) - MBEDTLS_LMS_M_NODE_BYTES_MAX* = 32 - MBEDTLS_LMS_SHA256_M32_H10* = (0x00000006).mbedtls_lms_algorithm_type_t - MBEDTLS_LMOTS_SHA256_N32_W8* = (4).mbedtls_lmots_algorithm_type_t -type - mbedtls_lmots_parameters_t* {.bycopy.} = object - private_I_key_identifier*: array[(16'u), byte] - private_q_leaf_identifier*: array[(4'u), byte] - private_type*: mbedtls_lmots_algorithm_type_t - - mbedtls_lmots_public_t* {.bycopy.} = object - private_params*: mbedtls_lmots_parameters_t - private_public_key*: array[(32'u), byte] - private_have_public_key*: byte - - mbedtls_lms_parameters_t* {.bycopy.} = object - private_I_key_identifier*: array[(16'u), byte] - private_otstype*: mbedtls_lmots_algorithm_type_t - private_type*: mbedtls_lms_algorithm_type_t - - mbedtls_lms_public_t* {.bycopy.} = object - private_params*: mbedtls_lms_parameters_t - private_T_1_pub_key*: array[32, byte] - private_have_public_key*: byte - -proc mbedtls_lms_public_init*(ctx: ptr mbedtls_lms_public_t) {.importc, cdecl.} -proc mbedtls_lms_public_free*(ctx: ptr mbedtls_lms_public_t) {.importc, cdecl.} -proc mbedtls_lms_import_public_key*(ctx: ptr mbedtls_lms_public_t; - key: ptr byte; key_size: uint): cint {. - importc, cdecl.} -proc mbedtls_lms_export_public_key*(ctx: ptr mbedtls_lms_public_t; - key: ptr byte; key_size: uint; - key_len: ptr uint): cint {.importc, cdecl.} -proc mbedtls_lms_verify*(ctx: ptr mbedtls_lms_public_t; msg: ptr byte; - msg_size: uint; sig: ptr byte; sig_size: uint): cint {. - importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/mbedtls_config.nim b/webrtc/mbedtls/mbedtls_config.nim deleted file mode 100644 index 808f7ff..0000000 --- a/webrtc/mbedtls/mbedtls_config.nim +++ /dev/null @@ -1,13 +0,0 @@ -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT* = 0 - MBEDTLS_SSL_MAX_EARLY_DATA_SIZE* = 1024 - MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE* = 6000 - MBEDTLS_SSL_TLS1_3_TICKET_NONCE_LENGTH* = 32 - MBEDTLS_SSL_TLS1_3_DEFAULT_NEW_SESSION_TICKETS* = 1 -{.pop.} diff --git a/webrtc/mbedtls/md.nim b/webrtc/mbedtls/md.nim deleted file mode 100644 index 1b7e588..0000000 --- a/webrtc/mbedtls/md.nim +++ /dev/null @@ -1,83 +0,0 @@ -import "ripemd160" -import "sha1" -import "sha256" -import "sha512" -import "md5" -import "utils" - -{.compile: "./mbedtls/library/md.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(mbedtls_md_type_t) -defineEnum(mbedtls_md_engine_t) - -const - MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE* = -0x00005080 - MBEDTLS_ERR_MD_BAD_INPUT_DATA* = -0x00005100 - MBEDTLS_ERR_MD_ALLOC_FAILED* = -0x00005180 - MBEDTLS_ERR_MD_FILE_IO_ERROR* = -0x00005200 - MBEDTLS_MD_NONE* = (0).mbedtls_md_type_t - MBEDTLS_MD_MD5* = (MBEDTLS_MD_NONE + 1).mbedtls_md_type_t - MBEDTLS_MD_SHA1* = (MBEDTLS_MD_MD5 + 1).mbedtls_md_type_t - MBEDTLS_MD_SHA224* = (MBEDTLS_MD_SHA1 + 1).mbedtls_md_type_t - MBEDTLS_MD_SHA256* = (MBEDTLS_MD_SHA224 + 1).mbedtls_md_type_t - MBEDTLS_MD_SHA384* = (MBEDTLS_MD_SHA256 + 1).mbedtls_md_type_t - MBEDTLS_MD_SHA512* = (MBEDTLS_MD_SHA384 + 1).mbedtls_md_type_t - MBEDTLS_MD_RIPEMD160* = (MBEDTLS_MD_SHA512 + 1).mbedtls_md_type_t - MBEDTLS_MD_MAX_SIZE* = 64 - MBEDTLS_MD_MAX_BLOCK_SIZE* = 128 - MBEDTLS_MD_ENGINE_LEGACY* = (0).mbedtls_md_engine_t - MBEDTLS_MD_ENGINE_PSA* = (MBEDTLS_MD_ENGINE_LEGACY + 1).mbedtls_md_engine_t -type - mbedtls_md_info_t* {.incompleteStruct.} = object - mbedtls_md_context_t* {.bycopy.} = object - private_md_info*: ptr mbedtls_md_info_t - private_md_ctx*: pointer - private_hmac_ctx*: pointer - -proc mbedtls_md_info_from_type*(md_type: mbedtls_md_type_t): ptr mbedtls_md_info_t {. - importc, cdecl.} -proc mbedtls_md_init*(ctx: ptr mbedtls_md_context_t) {.importc, cdecl.} -proc mbedtls_md_free*(ctx: ptr mbedtls_md_context_t) {.importc, cdecl.} -proc mbedtls_md_setup*(ctx: ptr mbedtls_md_context_t; - md_info: ptr mbedtls_md_info_t; hmac: cint): cint {. - importc, cdecl.} -proc mbedtls_md_clone*(dst: ptr mbedtls_md_context_t; - src: ptr mbedtls_md_context_t): cint {.importc, cdecl.} -proc mbedtls_md_get_size*(md_info: ptr mbedtls_md_info_t): byte {.importc, - cdecl.} -proc mbedtls_md_get_type*(md_info: ptr mbedtls_md_info_t): mbedtls_md_type_t {. - importc, cdecl.} -proc mbedtls_md_starts*(ctx: ptr mbedtls_md_context_t): cint {.importc, cdecl.} -proc mbedtls_md_update*(ctx: ptr mbedtls_md_context_t; input: ptr byte; - ilen: uint): cint {.importc, cdecl.} -proc mbedtls_md_finish*(ctx: ptr mbedtls_md_context_t; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_md*(md_info: ptr mbedtls_md_info_t; input: ptr byte; ilen: uint; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_md_list*(): ptr cint {.importc, cdecl.} -proc mbedtls_md_info_from_string*(md_name: cstring): ptr mbedtls_md_info_t {. - importc, cdecl.} -proc mbedtls_md_get_name*(md_info: ptr mbedtls_md_info_t): cstring {.importc, - cdecl.} -proc mbedtls_md_info_from_ctx*(ctx: ptr mbedtls_md_context_t): ptr mbedtls_md_info_t {. - importc, cdecl.} -proc mbedtls_md_file*(md_info: ptr mbedtls_md_info_t; path: cstring; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_md_hmac_starts*(ctx: ptr mbedtls_md_context_t; key: ptr byte; - keylen: uint): cint {.importc, cdecl.} -proc mbedtls_md_hmac_update*(ctx: ptr mbedtls_md_context_t; input: ptr byte; - ilen: uint): cint {.importc, cdecl.} -proc mbedtls_md_hmac_finish*(ctx: ptr mbedtls_md_context_t; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_md_hmac_reset*(ctx: ptr mbedtls_md_context_t): cint {.importc, - cdecl.} -proc mbedtls_md_hmac*(md_info: ptr mbedtls_md_info_t; key: ptr byte; - keylen: uint; input: ptr byte; ilen: uint; - output: ptr byte): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/md5.nim b/webrtc/mbedtls/md5.nim deleted file mode 100644 index 50974bd..0000000 --- a/webrtc/mbedtls/md5.nim +++ /dev/null @@ -1,32 +0,0 @@ -import "platform_time" - -{.compile: "./mbedtls/library/md5.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -type - mbedtls_md5_context* {.bycopy.} = object - private_total*: array[2, uint32] - private_state*: array[4, uint32] - private_buffer*: array[64, byte] - -proc mbedtls_md5_init*(ctx: ptr mbedtls_md5_context) {.importc, cdecl.} -proc mbedtls_md5_free*(ctx: ptr mbedtls_md5_context) {.importc, cdecl.} -proc mbedtls_md5_clone*(dst: ptr mbedtls_md5_context; - src: ptr mbedtls_md5_context) {.importc, cdecl.} -proc mbedtls_md5_starts*(ctx: ptr mbedtls_md5_context): cint {.importc, cdecl.} -proc mbedtls_md5_update*(ctx: ptr mbedtls_md5_context; input: ptr byte; - ilen: uint): cint {.importc, cdecl.} -proc mbedtls_md5_finish*(ctx: ptr mbedtls_md5_context; output: array[16, byte]): cint {. - importc, cdecl.} -proc mbedtls_internal_md5_process*(ctx: ptr mbedtls_md5_context; - data: array[64, byte]): cint {.importc, - cdecl.} -proc mbedtls_md5*(input: ptr byte; ilen: uint; output: array[16, byte]): cint {. - importc, cdecl.} -proc mbedtls_md5_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/memory_buffer_alloc.nim b/webrtc/mbedtls/memory_buffer_alloc.nim deleted file mode 100644 index 5ef0373..0000000 --- a/webrtc/mbedtls/memory_buffer_alloc.nim +++ /dev/null @@ -1,23 +0,0 @@ -{.compile: "./mbedtls/library/memory_buffer_alloc.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_MEMORY_ALIGN_MULTIPLE* = 4 - MBEDTLS_MEMORY_VERIFY_NONE* = 0 - MBEDTLS_MEMORY_VERIFY_ALLOC* = (1 shl typeof(1)(0)) - MBEDTLS_MEMORY_VERIFY_FREE* = (1 shl typeof(1)(1)) - MBEDTLS_MEMORY_VERIFY_ALWAYS* = (MBEDTLS_MEMORY_VERIFY_ALLOC or - typeof(MBEDTLS_MEMORY_VERIFY_ALLOC)(MBEDTLS_MEMORY_VERIFY_FREE)) -proc mbedtls_memory_buffer_alloc_init*(buf: ptr byte; len: uint) {.importc, - cdecl.} -proc mbedtls_memory_buffer_alloc_free*() {.importc, cdecl.} -proc mbedtls_memory_buffer_set_verify*(verify: cint) {.importc, cdecl.} -proc mbedtls_memory_buffer_alloc_verify*(): cint {.importc, cdecl.} -proc mbedtls_memory_buffer_alloc_self_test*(verbose: cint): cint {.importc, - cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/net_sockets.nim b/webrtc/mbedtls/net_sockets.nim deleted file mode 100644 index 38dcc7d..0000000 --- a/webrtc/mbedtls/net_sockets.nim +++ /dev/null @@ -1,55 +0,0 @@ -{.compile: "./mbedtls/library/net_sockets.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_NET_SOCKET_FAILED* = -0x00000042 - MBEDTLS_ERR_NET_CONNECT_FAILED* = -0x00000044 - MBEDTLS_ERR_NET_BIND_FAILED* = -0x00000046 - MBEDTLS_ERR_NET_LISTEN_FAILED* = -0x00000048 - MBEDTLS_ERR_NET_ACCEPT_FAILED* = -0x0000004A - MBEDTLS_ERR_NET_RECV_FAILED* = -0x0000004C - MBEDTLS_ERR_NET_SEND_FAILED* = -0x0000004E - MBEDTLS_ERR_NET_CONN_RESET* = -0x00000050 - MBEDTLS_ERR_NET_UNKNOWN_HOST* = -0x00000052 - MBEDTLS_ERR_NET_BUFFER_TOO_SMALL* = -0x00000043 - MBEDTLS_ERR_NET_INVALID_CONTEXT* = -0x00000045 - MBEDTLS_ERR_NET_POLL_FAILED* = -0x00000047 - MBEDTLS_ERR_NET_BAD_INPUT_DATA* = -0x00000049 - MBEDTLS_NET_LISTEN_BACKLOG* = 10 - MBEDTLS_NET_PROTO_TCP* = 0 - MBEDTLS_NET_PROTO_UDP* = 1 - MBEDTLS_NET_POLL_READ* = 1 - MBEDTLS_NET_POLL_WRITE* = 2 -type - mbedtls_net_context* {.bycopy.} = object - fd*: cint - -proc mbedtls_net_init*(ctx: ptr mbedtls_net_context) {.importc, cdecl.} -proc mbedtls_net_connect*(ctx: ptr mbedtls_net_context; host: cstring; - port: cstring; proto: cint): cint {.importc, cdecl.} -proc mbedtls_net_bind*(ctx: ptr mbedtls_net_context; bind_ip: cstring; - port: cstring; proto: cint): cint {.importc, cdecl.} -proc mbedtls_net_accept*(bind_ctx: ptr mbedtls_net_context; - client_ctx: ptr mbedtls_net_context; - client_ip: pointer; buf_size: uint; ip_len: ptr uint): cint {. - importc, cdecl.} -proc mbedtls_net_poll*(ctx: ptr mbedtls_net_context; rw: uint32; timeout: uint32): cint {. - importc, cdecl.} -proc mbedtls_net_set_block*(ctx: ptr mbedtls_net_context): cint {.importc, cdecl.} -proc mbedtls_net_set_nonblock*(ctx: ptr mbedtls_net_context): cint {.importc, - cdecl.} -proc mbedtls_net_usleep*(usec: culong) {.importc, cdecl.} -proc mbedtls_net_recv*(ctx: pointer; buf: ptr byte; len: uint): cint {. - importc, cdecl.} -proc mbedtls_net_send*(ctx: pointer; buf: ptr byte; len: uint): cint {. - importc, cdecl.} -proc mbedtls_net_recv_timeout*(ctx: pointer; buf: ptr byte; len: uint; - timeout: uint32): cint {.importc, cdecl.} -proc mbedtls_net_close*(ctx: ptr mbedtls_net_context) {.importc, cdecl.} -proc mbedtls_net_free*(ctx: ptr mbedtls_net_context) {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/nist_kw.nim b/webrtc/mbedtls/nist_kw.nim deleted file mode 100644 index b35c31a..0000000 --- a/webrtc/mbedtls/nist_kw.nim +++ /dev/null @@ -1,35 +0,0 @@ -import "cipher" -import "utils" - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(mbedtls_nist_kw_mode_t) - -const - MBEDTLS_KW_MODE_KW* = (0).mbedtls_nist_kw_mode_t - MBEDTLS_KW_MODE_KWP* = (1).mbedtls_nist_kw_mode_t -type - mbedtls_nist_kw_context* {.bycopy.} = object - private_cipher_ctx*: mbedtls_cipher_context_t - -proc mbedtls_nist_kw_init*(ctx: ptr mbedtls_nist_kw_context) {.importc, cdecl.} -proc mbedtls_nist_kw_setkey*(ctx: ptr mbedtls_nist_kw_context; - cipher: mbedtls_cipher_id_t; key: ptr byte; - keybits: cuint; is_wrap: cint): cint {.importc, - cdecl.} -proc mbedtls_nist_kw_free*(ctx: ptr mbedtls_nist_kw_context) {.importc, cdecl.} -proc mbedtls_nist_kw_wrap*(ctx: ptr mbedtls_nist_kw_context; - mode: mbedtls_nist_kw_mode_t; input: ptr byte; - in_len: uint; output: ptr byte; out_len: ptr uint; - out_size: uint): cint {.importc, cdecl.} -proc mbedtls_nist_kw_unwrap*(ctx: ptr mbedtls_nist_kw_context; - mode: mbedtls_nist_kw_mode_t; input: ptr byte; - in_len: uint; output: ptr byte; - out_len: ptr uint; out_size: uint): cint {.importc, - cdecl.} -proc mbedtls_nist_kw_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/oid.nim b/webrtc/mbedtls/oid.nim deleted file mode 100644 index 39ae8e3..0000000 --- a/webrtc/mbedtls/oid.nim +++ /dev/null @@ -1,256 +0,0 @@ -import "asn1" -import "pk" -import "md" -import "ecp" -import "cipher" - -# const 'MBEDTLS_OID_RSA_COMPANY' has unsupported value 'MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US MBEDTLS_OID_ORG_RSA_DATA_SECURITY' -# const 'MBEDTLS_OID_ANSI_X9_62' has unsupported value 'MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US MBEDTLS_OID_ORG_ANSI_X9_62' -# const 'MBEDTLS_OID_OIW_SECSIG' has unsupported value 'MBEDTLS_OID_ORG_OIW "\x03"' -# const 'MBEDTLS_OID_OIW_SECSIG_ALG' has unsupported value 'MBEDTLS_OID_OIW_SECSIG "\x02"' -# const 'MBEDTLS_OID_OIW_SECSIG_SHA1' has unsupported value 'MBEDTLS_OID_OIW_SECSIG_ALG "\x1a"' -# const 'MBEDTLS_OID_CERTICOM' has unsupported value 'MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_CERTICOM' -# const 'MBEDTLS_OID_TELETRUST' has unsupported value 'MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_TELETRUST' -# const 'MBEDTLS_OID_ISO_ITU_US_ORG' has unsupported value 'MBEDTLS_OID_ISO_ITU_COUNTRY MBEDTLS_OID_COUNTRY_US MBEDTLS_OID_ORGANIZATION' -# const 'MBEDTLS_OID_GOV' has unsupported value 'MBEDTLS_OID_ISO_ITU_US_ORG MBEDTLS_OID_ORG_GOV' -# const 'MBEDTLS_OID_NETSCAPE' has unsupported value 'MBEDTLS_OID_ISO_ITU_US_ORG MBEDTLS_OID_ORG_NETSCAPE' -# const 'MBEDTLS_OID_ID_CE' has unsupported value 'MBEDTLS_OID_ISO_CCITT_DS "\x1D"' -# const 'MBEDTLS_OID_NIST_ALG' has unsupported value 'MBEDTLS_OID_GOV "\x03\x04"' -# const 'MBEDTLS_OID_INTERNET' has unsupported value 'MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_DOD "\x01"' -# const 'MBEDTLS_OID_PKIX' has unsupported value 'MBEDTLS_OID_INTERNET "\x05\x05\x07"' -# const 'MBEDTLS_OID_AT' has unsupported value 'MBEDTLS_OID_ISO_CCITT_DS "\x04"' -# const 'MBEDTLS_OID_AT_CN' has unsupported value 'MBEDTLS_OID_AT "\x03"' -# const 'MBEDTLS_OID_AT_SUR_NAME' has unsupported value 'MBEDTLS_OID_AT "\x04"' -# const 'MBEDTLS_OID_AT_SERIAL_NUMBER' has unsupported value 'MBEDTLS_OID_AT "\x05"' -# const 'MBEDTLS_OID_AT_COUNTRY' has unsupported value 'MBEDTLS_OID_AT "\x06"' -# const 'MBEDTLS_OID_AT_LOCALITY' has unsupported value 'MBEDTLS_OID_AT "\x07"' -# const 'MBEDTLS_OID_AT_STATE' has unsupported value 'MBEDTLS_OID_AT "\x08"' -# const 'MBEDTLS_OID_AT_ORGANIZATION' has unsupported value 'MBEDTLS_OID_AT "\x0A"' -# const 'MBEDTLS_OID_AT_ORG_UNIT' has unsupported value 'MBEDTLS_OID_AT "\x0B"' -# const 'MBEDTLS_OID_AT_TITLE' has unsupported value 'MBEDTLS_OID_AT "\x0C"' -# const 'MBEDTLS_OID_AT_POSTAL_ADDRESS' has unsupported value 'MBEDTLS_OID_AT "\x10"' -# const 'MBEDTLS_OID_AT_POSTAL_CODE' has unsupported value 'MBEDTLS_OID_AT "\x11"' -# const 'MBEDTLS_OID_AT_GIVEN_NAME' has unsupported value 'MBEDTLS_OID_AT "\x2A"' -# const 'MBEDTLS_OID_AT_INITIALS' has unsupported value 'MBEDTLS_OID_AT "\x2B"' -# const 'MBEDTLS_OID_AT_GENERATION_QUALIFIER' has unsupported value 'MBEDTLS_OID_AT "\x2C"' -# const 'MBEDTLS_OID_AT_UNIQUE_IDENTIFIER' has unsupported value 'MBEDTLS_OID_AT "\x2D"' -# const 'MBEDTLS_OID_AT_DN_QUALIFIER' has unsupported value 'MBEDTLS_OID_AT "\x2E"' -# const 'MBEDTLS_OID_AT_PSEUDONYM' has unsupported value 'MBEDTLS_OID_AT "\x41"' -# const 'MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER' has unsupported value 'MBEDTLS_OID_ID_CE "\x23"' -# const 'MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER' has unsupported value 'MBEDTLS_OID_ID_CE "\x0E"' -# const 'MBEDTLS_OID_KEY_USAGE' has unsupported value 'MBEDTLS_OID_ID_CE "\x0F"' -# const 'MBEDTLS_OID_CERTIFICATE_POLICIES' has unsupported value 'MBEDTLS_OID_ID_CE "\x20"' -# const 'MBEDTLS_OID_POLICY_MAPPINGS' has unsupported value 'MBEDTLS_OID_ID_CE "\x21"' -# const 'MBEDTLS_OID_SUBJECT_ALT_NAME' has unsupported value 'MBEDTLS_OID_ID_CE "\x11"' -# const 'MBEDTLS_OID_ISSUER_ALT_NAME' has unsupported value 'MBEDTLS_OID_ID_CE "\x12"' -# const 'MBEDTLS_OID_SUBJECT_DIRECTORY_ATTRS' has unsupported value 'MBEDTLS_OID_ID_CE "\x09"' -# const 'MBEDTLS_OID_BASIC_CONSTRAINTS' has unsupported value 'MBEDTLS_OID_ID_CE "\x13"' -# const 'MBEDTLS_OID_NAME_CONSTRAINTS' has unsupported value 'MBEDTLS_OID_ID_CE "\x1E"' -# const 'MBEDTLS_OID_POLICY_CONSTRAINTS' has unsupported value 'MBEDTLS_OID_ID_CE "\x24"' -# const 'MBEDTLS_OID_EXTENDED_KEY_USAGE' has unsupported value 'MBEDTLS_OID_ID_CE "\x25"' -# const 'MBEDTLS_OID_CRL_DISTRIBUTION_POINTS' has unsupported value 'MBEDTLS_OID_ID_CE "\x1F"' -# const 'MBEDTLS_OID_INIHIBIT_ANYPOLICY' has unsupported value 'MBEDTLS_OID_ID_CE "\x36"' -# const 'MBEDTLS_OID_FRESHEST_CRL' has unsupported value 'MBEDTLS_OID_ID_CE "\x2E"' -# const 'MBEDTLS_OID_ANY_POLICY' has unsupported value 'MBEDTLS_OID_CERTIFICATE_POLICIES "\x00"' -# const 'MBEDTLS_OID_NS_CERT' has unsupported value 'MBEDTLS_OID_NETSCAPE "\x01"' -# const 'MBEDTLS_OID_NS_CERT_TYPE' has unsupported value 'MBEDTLS_OID_NS_CERT "\x01"' -# const 'MBEDTLS_OID_NS_BASE_URL' has unsupported value 'MBEDTLS_OID_NS_CERT "\x02"' -# const 'MBEDTLS_OID_NS_REVOCATION_URL' has unsupported value 'MBEDTLS_OID_NS_CERT "\x03"' -# const 'MBEDTLS_OID_NS_CA_REVOCATION_URL' has unsupported value 'MBEDTLS_OID_NS_CERT "\x04"' -# const 'MBEDTLS_OID_NS_RENEWAL_URL' has unsupported value 'MBEDTLS_OID_NS_CERT "\x07"' -# const 'MBEDTLS_OID_NS_CA_POLICY_URL' has unsupported value 'MBEDTLS_OID_NS_CERT "\x08"' -# const 'MBEDTLS_OID_NS_SSL_SERVER_NAME' has unsupported value 'MBEDTLS_OID_NS_CERT "\x0C"' -# const 'MBEDTLS_OID_NS_COMMENT' has unsupported value 'MBEDTLS_OID_NS_CERT "\x0D"' -# const 'MBEDTLS_OID_NS_DATA_TYPE' has unsupported value 'MBEDTLS_OID_NETSCAPE "\x02"' -# const 'MBEDTLS_OID_NS_CERT_SEQUENCE' has unsupported value 'MBEDTLS_OID_NS_DATA_TYPE "\x05"' -# const 'MBEDTLS_OID_PRIVATE_KEY_USAGE_PERIOD' has unsupported value 'MBEDTLS_OID_ID_CE "\x10"' -# const 'MBEDTLS_OID_CRL_NUMBER' has unsupported value 'MBEDTLS_OID_ID_CE "\x14"' -# const 'MBEDTLS_OID_ANY_EXTENDED_KEY_USAGE' has unsupported value 'MBEDTLS_OID_EXTENDED_KEY_USAGE "\x00"' -# const 'MBEDTLS_OID_KP' has unsupported value 'MBEDTLS_OID_PKIX "\x03"' -# const 'MBEDTLS_OID_SERVER_AUTH' has unsupported value 'MBEDTLS_OID_KP "\x01"' -# const 'MBEDTLS_OID_CLIENT_AUTH' has unsupported value 'MBEDTLS_OID_KP "\x02"' -# const 'MBEDTLS_OID_CODE_SIGNING' has unsupported value 'MBEDTLS_OID_KP "\x03"' -# const 'MBEDTLS_OID_EMAIL_PROTECTION' has unsupported value 'MBEDTLS_OID_KP "\x04"' -# const 'MBEDTLS_OID_TIME_STAMPING' has unsupported value 'MBEDTLS_OID_KP "\x08"' -# const 'MBEDTLS_OID_OCSP_SIGNING' has unsupported value 'MBEDTLS_OID_KP "\x09"' -# const 'MBEDTLS_OID_WISUN_FAN' has unsupported value 'MBEDTLS_OID_INTERNET "\x04\x01\x82\xe4\x25\x01"' -# const 'MBEDTLS_OID_ON' has unsupported value 'MBEDTLS_OID_PKIX "\x08"' -# const 'MBEDTLS_OID_ON_HW_MODULE_NAME' has unsupported value 'MBEDTLS_OID_ON "\x04"' -# const 'MBEDTLS_OID_PKCS' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x01"' -# const 'MBEDTLS_OID_PKCS1' has unsupported value 'MBEDTLS_OID_PKCS "\x01"' -# const 'MBEDTLS_OID_PKCS5' has unsupported value 'MBEDTLS_OID_PKCS "\x05"' -# const 'MBEDTLS_OID_PKCS7' has unsupported value 'MBEDTLS_OID_PKCS "\x07"' -# const 'MBEDTLS_OID_PKCS9' has unsupported value 'MBEDTLS_OID_PKCS "\x09"' -# const 'MBEDTLS_OID_PKCS12' has unsupported value 'MBEDTLS_OID_PKCS "\x0c"' -# const 'MBEDTLS_OID_PKCS1_RSA' has unsupported value 'MBEDTLS_OID_PKCS1 "\x01"' -# const 'MBEDTLS_OID_PKCS1_MD5' has unsupported value 'MBEDTLS_OID_PKCS1 "\x04"' -# const 'MBEDTLS_OID_PKCS1_SHA1' has unsupported value 'MBEDTLS_OID_PKCS1 "\x05"' -# const 'MBEDTLS_OID_PKCS1_SHA224' has unsupported value 'MBEDTLS_OID_PKCS1 "\x0e"' -# const 'MBEDTLS_OID_PKCS1_SHA256' has unsupported value 'MBEDTLS_OID_PKCS1 "\x0b"' -# const 'MBEDTLS_OID_PKCS1_SHA384' has unsupported value 'MBEDTLS_OID_PKCS1 "\x0c"' -# const 'MBEDTLS_OID_PKCS1_SHA512' has unsupported value 'MBEDTLS_OID_PKCS1 "\x0d"' -# const 'MBEDTLS_OID_PKCS9_EMAIL' has unsupported value 'MBEDTLS_OID_PKCS9 "\x01"' -# const 'MBEDTLS_OID_RSASSA_PSS' has unsupported value 'MBEDTLS_OID_PKCS1 "\x0a"' -# const 'MBEDTLS_OID_MGF1' has unsupported value 'MBEDTLS_OID_PKCS1 "\x08"' -# const 'MBEDTLS_OID_DIGEST_ALG_MD5' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x02\x05"' -# const 'MBEDTLS_OID_DIGEST_ALG_SHA1' has unsupported value 'MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_OIW_SECSIG_SHA1' -# const 'MBEDTLS_OID_DIGEST_ALG_SHA224' has unsupported value 'MBEDTLS_OID_NIST_ALG "\x02\x04"' -# const 'MBEDTLS_OID_DIGEST_ALG_SHA256' has unsupported value 'MBEDTLS_OID_NIST_ALG "\x02\x01"' -# const 'MBEDTLS_OID_DIGEST_ALG_SHA384' has unsupported value 'MBEDTLS_OID_NIST_ALG "\x02\x02"' -# const 'MBEDTLS_OID_DIGEST_ALG_SHA512' has unsupported value 'MBEDTLS_OID_NIST_ALG "\x02\x03"' -# const 'MBEDTLS_OID_DIGEST_ALG_RIPEMD160' has unsupported value 'MBEDTLS_OID_TELETRUST "\x03\x02\x01"' -# const 'MBEDTLS_OID_HMAC_SHA1' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x02\x07"' -# const 'MBEDTLS_OID_HMAC_SHA224' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x02\x08"' -# const 'MBEDTLS_OID_HMAC_SHA256' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x02\x09"' -# const 'MBEDTLS_OID_HMAC_SHA384' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x02\x0A"' -# const 'MBEDTLS_OID_HMAC_SHA512' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x02\x0B"' -# const 'MBEDTLS_OID_DES_CBC' has unsupported value 'MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_OIW_SECSIG_ALG "\x07"' -# const 'MBEDTLS_OID_DES_EDE3_CBC' has unsupported value 'MBEDTLS_OID_RSA_COMPANY "\x03\x07"' -# const 'MBEDTLS_OID_AES' has unsupported value 'MBEDTLS_OID_NIST_ALG "\x01"' -# const 'MBEDTLS_OID_AES128_KW' has unsupported value 'MBEDTLS_OID_AES "\x05"' -# const 'MBEDTLS_OID_AES128_KWP' has unsupported value 'MBEDTLS_OID_AES "\x08"' -# const 'MBEDTLS_OID_AES192_KW' has unsupported value 'MBEDTLS_OID_AES "\x19"' -# const 'MBEDTLS_OID_AES192_KWP' has unsupported value 'MBEDTLS_OID_AES "\x1c"' -# const 'MBEDTLS_OID_AES256_KW' has unsupported value 'MBEDTLS_OID_AES "\x2d"' -# const 'MBEDTLS_OID_AES256_KWP' has unsupported value 'MBEDTLS_OID_AES "\x30"' -# const 'MBEDTLS_OID_PKCS5_PBKDF2' has unsupported value 'MBEDTLS_OID_PKCS5 "\x0c"' -# const 'MBEDTLS_OID_PKCS5_PBES2' has unsupported value 'MBEDTLS_OID_PKCS5 "\x0d"' -# const 'MBEDTLS_OID_PKCS5_PBMAC1' has unsupported value 'MBEDTLS_OID_PKCS5 "\x0e"' -# const 'MBEDTLS_OID_PKCS5_PBE_MD5_DES_CBC' has unsupported value 'MBEDTLS_OID_PKCS5 "\x03"' -# const 'MBEDTLS_OID_PKCS5_PBE_MD5_RC2_CBC' has unsupported value 'MBEDTLS_OID_PKCS5 "\x06"' -# const 'MBEDTLS_OID_PKCS5_PBE_SHA1_DES_CBC' has unsupported value 'MBEDTLS_OID_PKCS5 "\x0a"' -# const 'MBEDTLS_OID_PKCS5_PBE_SHA1_RC2_CBC' has unsupported value 'MBEDTLS_OID_PKCS5 "\x0b"' -# const 'MBEDTLS_OID_PKCS7_DATA' has unsupported value 'MBEDTLS_OID_PKCS7 "\x01"' -# const 'MBEDTLS_OID_PKCS7_SIGNED_DATA' has unsupported value 'MBEDTLS_OID_PKCS7 "\x02"' -# const 'MBEDTLS_OID_PKCS7_ENVELOPED_DATA' has unsupported value 'MBEDTLS_OID_PKCS7 "\x03"' -# const 'MBEDTLS_OID_PKCS7_SIGNED_AND_ENVELOPED_DATA' has unsupported value 'MBEDTLS_OID_PKCS7 "\x04"' -# const 'MBEDTLS_OID_PKCS7_DIGESTED_DATA' has unsupported value 'MBEDTLS_OID_PKCS7 "\x05"' -# const 'MBEDTLS_OID_PKCS7_ENCRYPTED_DATA' has unsupported value 'MBEDTLS_OID_PKCS7 "\x06"' -# const 'MBEDTLS_OID_PKCS9_CSR_EXT_REQ' has unsupported value 'MBEDTLS_OID_PKCS9 "\x0e"' -# const 'MBEDTLS_OID_PKCS12_PBE' has unsupported value 'MBEDTLS_OID_PKCS12 "\x01"' -# const 'MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC' has unsupported value 'MBEDTLS_OID_PKCS12_PBE "\x03"' -# const 'MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC' has unsupported value 'MBEDTLS_OID_PKCS12_PBE "\x04"' -# const 'MBEDTLS_OID_PKCS12_PBE_SHA1_RC2_128_CBC' has unsupported value 'MBEDTLS_OID_PKCS12_PBE "\x05"' -# const 'MBEDTLS_OID_PKCS12_PBE_SHA1_RC2_40_CBC' has unsupported value 'MBEDTLS_OID_PKCS12_PBE "\x06"' -# const 'MBEDTLS_OID_EC_ALG_UNRESTRICTED' has unsupported value 'MBEDTLS_OID_ANSI_X9_62 "\x02\01"' -# const 'MBEDTLS_OID_EC_ALG_ECDH' has unsupported value 'MBEDTLS_OID_CERTICOM "\x01\x0c"' -# const 'MBEDTLS_OID_EC_GRP_SECP192R1' has unsupported value 'MBEDTLS_OID_ANSI_X9_62 "\x03\x01\x01"' -# const 'MBEDTLS_OID_EC_GRP_SECP224R1' has unsupported value 'MBEDTLS_OID_CERTICOM "\x00\x21"' -# const 'MBEDTLS_OID_EC_GRP_SECP256R1' has unsupported value 'MBEDTLS_OID_ANSI_X9_62 "\x03\x01\x07"' -# const 'MBEDTLS_OID_EC_GRP_SECP384R1' has unsupported value 'MBEDTLS_OID_CERTICOM "\x00\x22"' -# const 'MBEDTLS_OID_EC_GRP_SECP521R1' has unsupported value 'MBEDTLS_OID_CERTICOM "\x00\x23"' -# const 'MBEDTLS_OID_EC_GRP_SECP192K1' has unsupported value 'MBEDTLS_OID_CERTICOM "\x00\x1f"' -# const 'MBEDTLS_OID_EC_GRP_SECP224K1' has unsupported value 'MBEDTLS_OID_CERTICOM "\x00\x20"' -# const 'MBEDTLS_OID_EC_GRP_SECP256K1' has unsupported value 'MBEDTLS_OID_CERTICOM "\x00\x0a"' -# const 'MBEDTLS_OID_EC_BRAINPOOL_V1' has unsupported value 'MBEDTLS_OID_TELETRUST "\x03\x03\x02\x08\x01\x01"' -# const 'MBEDTLS_OID_EC_GRP_BP256R1' has unsupported value 'MBEDTLS_OID_EC_BRAINPOOL_V1 "\x07"' -# const 'MBEDTLS_OID_EC_GRP_BP384R1' has unsupported value 'MBEDTLS_OID_EC_BRAINPOOL_V1 "\x0B"' -# const 'MBEDTLS_OID_EC_GRP_BP512R1' has unsupported value 'MBEDTLS_OID_EC_BRAINPOOL_V1 "\x0D"' -# const 'MBEDTLS_OID_ANSI_X9_62_FIELD_TYPE' has unsupported value 'MBEDTLS_OID_ANSI_X9_62 "\x01"' -# const 'MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_FIELD_TYPE "\x01"' -# const 'MBEDTLS_OID_ANSI_X9_62_SIG' has unsupported value 'MBEDTLS_OID_ANSI_X9_62 "\x04"' -# const 'MBEDTLS_OID_ANSI_X9_62_SIG_SHA2' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_SIG "\x03"' -# const 'MBEDTLS_OID_ECDSA_SHA1' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_SIG "\x01"' -# const 'MBEDTLS_OID_ECDSA_SHA224' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x01"' -# const 'MBEDTLS_OID_ECDSA_SHA256' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x02"' -# const 'MBEDTLS_OID_ECDSA_SHA384' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x03"' -# const 'MBEDTLS_OID_ECDSA_SHA512' has unsupported value 'MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x04"' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_OID_NOT_FOUND* = -0x0000002E - MBEDTLS_ERR_OID_BUF_TOO_SMALL* = -0x0000000B - MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER* = (1 shl typeof(1)(0)) - MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER* = (1 shl typeof(1)(1)) - MBEDTLS_OID_X509_EXT_KEY_USAGE* = (1 shl typeof(1)(2)) - MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES* = (1 shl typeof(1)(3)) - MBEDTLS_OID_X509_EXT_POLICY_MAPPINGS* = (1 shl typeof(1)(4)) - MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME* = (1 shl typeof(1)(5)) - MBEDTLS_OID_X509_EXT_ISSUER_ALT_NAME* = (1 shl typeof(1)(6)) - MBEDTLS_OID_X509_EXT_SUBJECT_DIRECTORY_ATTRS* = (1 shl typeof(1)(7)) - MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS* = (1 shl typeof(1)(8)) - MBEDTLS_OID_X509_EXT_NAME_CONSTRAINTS* = (1 shl typeof(1)(9)) - MBEDTLS_OID_X509_EXT_POLICY_CONSTRAINTS* = (1 shl typeof(1)(10)) - MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE* = (1 shl typeof(1)(11)) - MBEDTLS_OID_X509_EXT_CRL_DISTRIBUTION_POINTS* = (1 shl typeof(1)(12)) - MBEDTLS_OID_X509_EXT_INIHIBIT_ANYPOLICY* = (1 shl typeof(1)(13)) - MBEDTLS_OID_X509_EXT_FRESHEST_CRL* = (1 shl typeof(1)(14)) - MBEDTLS_OID_X509_EXT_NS_CERT_TYPE* = (1 shl typeof(1)(16)) - MBEDTLS_OID_ISO_MEMBER_BODIES* = "*" - MBEDTLS_OID_ISO_IDENTIFIED_ORG* = "+" - MBEDTLS_OID_ISO_CCITT_DS* = "U" - MBEDTLS_OID_ISO_ITU_COUNTRY* = "`" - MBEDTLS_OID_COUNTRY_US* = "†H" - MBEDTLS_OID_ORG_RSA_DATA_SECURITY* = "†÷\r" - MBEDTLS_OID_ORG_ANSI_X9_62* = "Î=" - MBEDTLS_OID_ORG_DOD* = "\x06" - MBEDTLS_OID_ORG_OIW* = "\x0E" - MBEDTLS_OID_ORG_CERTICOM* = "\x04" - MBEDTLS_OID_ORG_TELETRUST* = "$" - MBEDTLS_OID_ORGANIZATION* = "\x01" - MBEDTLS_OID_ORG_GOV* = "e" - MBEDTLS_OID_ORG_NETSCAPE* = "†øB" - MBEDTLS_OID_UID* = "\t’&‰“ò,d\x01\x01" - MBEDTLS_OID_DOMAIN_COMPONENT* = "\t’&‰“ò,d\x01\x19" - MBEDTLS_OID_RSA_SHA_OBS* = "+\x0E\x03\x02\x1D" -type - mbedtls_oid_descriptor_t* {.bycopy.} = object - private_asn1*: cstring - private_asn1_len*: uint - private_name*: cstring - private_description*: cstring - -proc mbedtls_oid_get_numeric_string*(buf: cstring; size: uint; - oid: ptr mbedtls_asn1_buf): cint {.importc, - cdecl.} -proc mbedtls_oid_get_x509_ext_type*(oid: ptr mbedtls_asn1_buf; - ext_type: ptr cint): cint {.importc, cdecl.} -proc mbedtls_oid_get_attr_short_name*(oid: ptr mbedtls_asn1_buf; - short_name: ptr cstring): cint {.importc, - cdecl.} -proc mbedtls_oid_get_pk_alg*(oid: ptr mbedtls_asn1_buf; - pk_alg: ptr mbedtls_pk_type_t): cint {.importc, - cdecl.} -proc mbedtls_oid_get_oid_by_pk_alg*(pk_alg: mbedtls_pk_type_t; oid: ptr cstring; - olen: ptr uint): cint {.importc, cdecl.} -proc mbedtls_oid_get_ec_grp*(oid: ptr mbedtls_asn1_buf; - grp_id: ptr mbedtls_ecp_group_id): cint {.importc, - cdecl.} -proc mbedtls_oid_get_oid_by_ec_grp*(grp_id: mbedtls_ecp_group_id; - oid: ptr cstring; olen: ptr uint): cint {. - importc, cdecl.} -proc mbedtls_oid_get_sig_alg*(oid: ptr mbedtls_asn1_buf; - md_alg: ptr mbedtls_md_type_t; - pk_alg: ptr mbedtls_pk_type_t): cint {.importc, - cdecl.} -proc mbedtls_oid_get_sig_alg_desc*(oid: ptr mbedtls_asn1_buf; desc: ptr cstring): cint {. - importc, cdecl.} -proc mbedtls_oid_get_oid_by_sig_alg*(pk_alg: mbedtls_pk_type_t; - md_alg: mbedtls_md_type_t; - oid: ptr cstring; olen: ptr uint): cint {. - importc, cdecl.} -proc mbedtls_oid_get_md_hmac*(oid: ptr mbedtls_asn1_buf; - md_hmac: ptr mbedtls_md_type_t): cint {.importc, - cdecl.} -proc mbedtls_oid_get_md_alg*(oid: ptr mbedtls_asn1_buf; - md_alg: ptr mbedtls_md_type_t): cint {.importc, - cdecl.} -proc mbedtls_oid_get_extended_key_usage*(oid: ptr mbedtls_asn1_buf; - desc: ptr cstring): cint {.importc, cdecl.} -proc mbedtls_oid_get_certificate_policies*(oid: ptr mbedtls_asn1_buf; - desc: ptr cstring): cint {.importc, cdecl.} -proc mbedtls_oid_get_oid_by_md*(md_alg: mbedtls_md_type_t; oid: ptr cstring; - olen: ptr uint): cint {.importc, cdecl.} -proc mbedtls_oid_get_cipher_alg*(oid: ptr mbedtls_asn1_buf; - cipher_alg: ptr mbedtls_cipher_type_t): cint {. - importc, cdecl.} -proc mbedtls_oid_get_pkcs12_pbe_alg*(oid: ptr mbedtls_asn1_buf; - md_alg: ptr mbedtls_md_type_t; - cipher_alg: ptr mbedtls_cipher_type_t): cint {. - importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/pem.nim b/webrtc/mbedtls/pem.nim deleted file mode 100644 index 8654fb0..0000000 --- a/webrtc/mbedtls/pem.nim +++ /dev/null @@ -1,41 +0,0 @@ -import "aes" -import "base64" -import "des" - -{.compile: "./mbedtls/library/pem.c".} - -# proc 'mbedtls_pem_get_buffer' skipped - static inline procs cannot work with '--noHeader | -H' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT* = -0x00001080 - MBEDTLS_ERR_PEM_INVALID_DATA* = -0x00001100 - MBEDTLS_ERR_PEM_ALLOC_FAILED* = -0x00001180 - MBEDTLS_ERR_PEM_INVALID_ENC_IV* = -0x00001200 - MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG* = -0x00001280 - MBEDTLS_ERR_PEM_PASSWORD_REQUIRED* = -0x00001300 - MBEDTLS_ERR_PEM_PASSWORD_MISMATCH* = -0x00001380 - MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE* = -0x00001400 - MBEDTLS_ERR_PEM_BAD_INPUT_DATA* = -0x00001480 -type - mbedtls_pem_context* {.bycopy.} = object - private_buf*: ptr byte - private_buflen*: uint - private_info*: ptr byte - -proc mbedtls_pem_init*(ctx: ptr mbedtls_pem_context) {.importc, cdecl.} -proc mbedtls_pem_read_buffer*(ctx: ptr mbedtls_pem_context; header: cstring; - footer: cstring; data: ptr byte; - pwd: ptr byte; pwdlen: uint; use_len: ptr uint): cint {. - importc, cdecl.} -proc mbedtls_pem_free*(ctx: ptr mbedtls_pem_context) {.importc, cdecl.} -proc mbedtls_pem_write_buffer*(header: cstring; footer: cstring; - der_data: ptr byte; der_len: uint; - buf: ptr byte; buf_len: uint; olen: ptr uint): cint {. - importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/pk.nim b/webrtc/mbedtls/pk.nim deleted file mode 100644 index 2a33ec4..0000000 --- a/webrtc/mbedtls/pk.nim +++ /dev/null @@ -1,172 +0,0 @@ -import "pem" -import "md" -import "ecdsa" -import "psa_util" -import "psa/crypto" -import "utils" - -{.compile: "./mbedtls/library/pk_wrap.c".} -{.compile: "./mbedtls/library/pk.c".} -{.compile: "./mbedtls/library/pkparse.c".} -{.compile: "./mbedtls/library/pkwrite.c".} - -# const 'MBEDTLS_PK_SIGNATURE_MAX_SIZE' has unsupported value 'MBEDTLS_MPI_MAX_SIZE' -# proc 'mbedtls_pk_get_len' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_pk_rsa' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_pk_ec' skipped - static inline procs cannot work with '--noHeader | -H' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(mbedtls_pk_type_t) -defineEnum(mbedtls_pk_debug_type) - -const - MBEDTLS_ERR_PK_ALLOC_FAILED* = -0x00003F80 - MBEDTLS_ERR_PK_TYPE_MISMATCH* = -0x00003F00 - MBEDTLS_ERR_PK_BAD_INPUT_DATA* = -0x00003E80 - MBEDTLS_ERR_PK_FILE_IO_ERROR* = -0x00003E00 - MBEDTLS_ERR_PK_KEY_INVALID_VERSION* = -0x00003D80 - MBEDTLS_ERR_PK_KEY_INVALID_FORMAT* = -0x00003D00 - MBEDTLS_ERR_PK_UNKNOWN_PK_ALG* = -0x00003C80 - MBEDTLS_ERR_PK_PASSWORD_REQUIRED* = -0x00003C00 - MBEDTLS_ERR_PK_PASSWORD_MISMATCH* = -0x00003B80 - MBEDTLS_ERR_PK_INVALID_PUBKEY* = -0x00003B00 - MBEDTLS_ERR_PK_INVALID_ALG* = -0x00003A80 - MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE* = -0x00003A00 - MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE* = -0x00003980 - MBEDTLS_ERR_PK_SIG_LEN_MISMATCH* = -0x00003900 - MBEDTLS_ERR_PK_BUFFER_TOO_SMALL* = -0x00003880 - MBEDTLS_PK_NONE* = (0).mbedtls_pk_type_t - MBEDTLS_PK_RSA* = (MBEDTLS_PK_NONE + 1).mbedtls_pk_type_t - MBEDTLS_PK_ECKEY* = (MBEDTLS_PK_RSA + 1).mbedtls_pk_type_t - MBEDTLS_PK_ECKEY_DH* = (MBEDTLS_PK_ECKEY + 1).mbedtls_pk_type_t - MBEDTLS_PK_ECDSA* = (MBEDTLS_PK_ECKEY_DH + 1).mbedtls_pk_type_t - MBEDTLS_PK_RSA_ALT* = (MBEDTLS_PK_ECDSA + 1).mbedtls_pk_type_t - MBEDTLS_PK_RSASSA_PSS* = (MBEDTLS_PK_RSA_ALT + 1).mbedtls_pk_type_t - MBEDTLS_PK_OPAQUE* = (MBEDTLS_PK_RSASSA_PSS + 1).mbedtls_pk_type_t - MBEDTLS_PK_SIGNATURE_MAX_SIZE* = 0 - MBEDTLS_PK_DEBUG_NONE* = (0).mbedtls_pk_debug_type - MBEDTLS_PK_DEBUG_MPI* = (MBEDTLS_PK_DEBUG_NONE + 1).mbedtls_pk_debug_type - MBEDTLS_PK_DEBUG_ECP* = (MBEDTLS_PK_DEBUG_MPI + 1).mbedtls_pk_debug_type - MBEDTLS_PK_DEBUG_MAX_ITEMS* = 3 -type - mbedtls_pk_rsassa_pss_options* {.bycopy.} = object - mgf1_hash_id*: mbedtls_md_type_t - expected_salt_len*: cint - - mbedtls_pk_debug_item* {.bycopy.} = object - private_type*: mbedtls_pk_debug_type - private_name*: cstring - private_value*: pointer - - mbedtls_pk_info_t* {.incompleteStruct.} = object - mbedtls_pk_context* {.bycopy.} = object - private_pk_info*: ptr mbedtls_pk_info_t - private_pk_ctx*: pointer - - mbedtls_pk_restart_ctx* = object - mbedtls_pk_rsa_alt_decrypt_func* = proc (ctx: pointer; olen: ptr uint; - input: ptr byte; output: ptr byte; output_max_len: uint): cint {.cdecl.} - mbedtls_pk_rsa_alt_sign_func* = proc (ctx: pointer; f_rng: proc (a1: pointer; - a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; - md_alg: mbedtls_md_type_t; - hashlen: cuint; hash: ptr byte; - sig: ptr byte): cint {.cdecl.} - mbedtls_pk_rsa_alt_key_len_func* = proc (ctx: pointer): uint {.cdecl.} -proc mbedtls_pk_info_from_type*(pk_type: mbedtls_pk_type_t): ptr mbedtls_pk_info_t {. - importc, cdecl.} -proc mbedtls_pk_init*(ctx: ptr mbedtls_pk_context) {.importc, cdecl.} -proc mbedtls_pk_free*(ctx: ptr mbedtls_pk_context) {.importc, cdecl.} -proc mbedtls_pk_setup*(ctx: ptr mbedtls_pk_context; info: ptr mbedtls_pk_info_t): cint {. - importc, cdecl.} -proc mbedtls_pk_setup_rsa_alt*(ctx: ptr mbedtls_pk_context; key: pointer; - decrypt_func: mbedtls_pk_rsa_alt_decrypt_func; - sign_func: mbedtls_pk_rsa_alt_sign_func; - key_len_func: mbedtls_pk_rsa_alt_key_len_func): cint {. - importc, cdecl.} -proc mbedtls_pk_get_bitlen*(ctx: ptr mbedtls_pk_context): uint {.importc, cdecl.} -proc mbedtls_pk_can_do*(ctx: ptr mbedtls_pk_context; `type`: mbedtls_pk_type_t): cint {. - importc, cdecl.} -proc mbedtls_pk_verify*(ctx: ptr mbedtls_pk_context; md_alg: mbedtls_md_type_t; - hash: ptr byte; hash_len: uint; sig: ptr byte; - sig_len: uint): cint {.importc, cdecl.} -proc mbedtls_pk_verify_restartable*(ctx: ptr mbedtls_pk_context; - md_alg: mbedtls_md_type_t; hash: ptr byte; - hash_len: uint; sig: ptr byte; - sig_len: uint; - rs_ctx: ptr mbedtls_pk_restart_ctx): cint {. - importc, cdecl.} -proc mbedtls_pk_verify_ext*(`type`: mbedtls_pk_type_t; options: pointer; - ctx: ptr mbedtls_pk_context; - md_alg: mbedtls_md_type_t; hash: ptr byte; - hash_len: uint; sig: ptr byte; sig_len: uint): cint {. - importc, cdecl.} -proc mbedtls_pk_sign*(ctx: ptr mbedtls_pk_context; md_alg: mbedtls_md_type_t; - hash: ptr byte; hash_len: uint; sig: ptr byte; - sig_size: uint; sig_len: ptr uint; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_pk_sign_ext*(pk_type: mbedtls_pk_type_t; - ctx: ptr mbedtls_pk_context; - md_alg: mbedtls_md_type_t; hash: ptr byte; - hash_len: uint; sig: ptr byte; sig_size: uint; - sig_len: ptr uint; f_rng: proc (a1: pointer; - a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, - cdecl.} -proc mbedtls_pk_sign_restartable*(ctx: ptr mbedtls_pk_context; - md_alg: mbedtls_md_type_t; hash: ptr byte; - hash_len: uint; sig: ptr byte; - sig_size: uint; sig_len: ptr uint; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; - rs_ctx: ptr mbedtls_pk_restart_ctx): cint {. - importc, cdecl.} -proc mbedtls_pk_decrypt*(ctx: ptr mbedtls_pk_context; input: ptr byte; - ilen: uint; output: ptr byte; olen: ptr uint; - osize: uint; f_rng: proc (a1: pointer; a2: ptr byte; - a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, cdecl.} -proc mbedtls_pk_encrypt*(ctx: ptr mbedtls_pk_context; input: ptr byte; - ilen: uint; output: ptr byte; olen: ptr uint; - osize: uint; f_rng: proc (a1: pointer; a2: ptr byte; - a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, cdecl.} -proc mbedtls_pk_check_pair*(pub: ptr mbedtls_pk_context; - prv: ptr mbedtls_pk_context; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_pk_debug*(ctx: ptr mbedtls_pk_context; - items: ptr mbedtls_pk_debug_item): cint {.importc, cdecl.} -proc mbedtls_pk_get_name*(ctx: ptr mbedtls_pk_context): cstring {.importc, cdecl.} -proc mbedtls_pk_get_type*(ctx: ptr mbedtls_pk_context): mbedtls_pk_type_t {. - importc, cdecl.} -proc mbedtls_pk_parse_key*(ctx: ptr mbedtls_pk_context; key: ptr byte; - keylen: uint; pwd: ptr byte; pwdlen: uint; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_pk_parse_public_key*(ctx: ptr mbedtls_pk_context; key: ptr byte; - keylen: uint): cint {.importc, cdecl.} -proc mbedtls_pk_parse_keyfile*(ctx: ptr mbedtls_pk_context; path: cstring; - password: cstring; f_rng: proc (a1: pointer; - a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, - cdecl.} -proc mbedtls_pk_parse_public_keyfile*(ctx: ptr mbedtls_pk_context; path: cstring): cint {. - importc, cdecl.} -proc mbedtls_pk_write_key_der*(ctx: ptr mbedtls_pk_context; buf: ptr byte; - size: uint): cint {.importc, cdecl.} -proc mbedtls_pk_write_pubkey_der*(ctx: ptr mbedtls_pk_context; buf: ptr byte; - size: uint): cint {.importc, cdecl.} -proc mbedtls_pk_write_pubkey_pem*(ctx: ptr mbedtls_pk_context; buf: ptr byte; - size: uint): cint {.importc, cdecl.} -proc mbedtls_pk_write_key_pem*(ctx: ptr mbedtls_pk_context; buf: ptr byte; - size: uint): cint {.importc, cdecl.} -proc mbedtls_pk_parse_subpubkey*(p: ptr ptr byte; `end`: ptr byte; - pk: ptr mbedtls_pk_context): cint {.importc, - cdecl.} -proc mbedtls_pk_write_pubkey*(p: ptr ptr byte; start: ptr byte; - key: ptr mbedtls_pk_context): cint {.importc, - cdecl.} -proc mbedtls_pk_load_file*(path: cstring; buf: ptr ptr byte; n: ptr uint): cint {. - importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/pkcs12.nim b/webrtc/mbedtls/pkcs12.nim deleted file mode 100644 index e3c2d54..0000000 --- a/webrtc/mbedtls/pkcs12.nim +++ /dev/null @@ -1,36 +0,0 @@ -import "md" -import "platform_time" -import "cipher" -import "asn1" -import "ctr_drbg" -import "hash_info" - -{.compile: "./mbedtls/library/pkcs12.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA* = -0x00001F80 - MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE* = -0x00001F00 - MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT* = -0x00001E80 - MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH* = -0x00001E00 - MBEDTLS_PKCS12_DERIVE_KEY* = 1 - MBEDTLS_PKCS12_DERIVE_IV* = 2 - MBEDTLS_PKCS12_DERIVE_MAC_KEY* = 3 - MBEDTLS_PKCS12_PBE_DECRYPT* = 0 - MBEDTLS_PKCS12_PBE_ENCRYPT* = 1 -proc mbedtls_pkcs12_pbe*(pbe_params: ptr mbedtls_asn1_buf; mode: cint; - cipher_type: mbedtls_cipher_type_t; - md_type: mbedtls_md_type_t; pwd: ptr byte; - pwdlen: uint; input: ptr byte; len: uint; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_pkcs12_derivation*(data: ptr byte; datalen: uint; - pwd: ptr byte; pwdlen: uint; salt: ptr byte; - saltlen: uint; mbedtls_md: mbedtls_md_type_t; - id: cint; iterations: cint): cint {.importc, - cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/pkcs5.nim b/webrtc/mbedtls/pkcs5.nim deleted file mode 100644 index 36986c4..0000000 --- a/webrtc/mbedtls/pkcs5.nim +++ /dev/null @@ -1,37 +0,0 @@ -import "asn1" -import "md" -import "cipher" -import "ctr_drbg" -import "rsa" - -{.compile: "./mbedtls/library/pkcs5.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA* = -0x00002F80 - MBEDTLS_ERR_PKCS5_INVALID_FORMAT* = -0x00002F00 - MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE* = -0x00002E80 - MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH* = -0x00002E00 - MBEDTLS_PKCS5_DECRYPT* = 0 - MBEDTLS_PKCS5_ENCRYPT* = 1 -proc mbedtls_pkcs5_pbes2*(pbe_params: ptr mbedtls_asn1_buf; mode: cint; - pwd: ptr byte; pwdlen: uint; data: ptr byte; - datalen: uint; output: ptr byte): cint {.importc, - cdecl.} -proc mbedtls_pkcs5_pbkdf2_hmac_ext*(md_type: mbedtls_md_type_t; - password: ptr byte; plen: uint; - salt: ptr byte; slen: uint; - iteration_count: cuint; key_length: uint32; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_pkcs5_pbkdf2_hmac*(ctx: ptr mbedtls_md_context_t; - password: ptr byte; plen: uint; - salt: ptr byte; slen: uint; - iteration_count: cuint; key_length: uint32; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_pkcs5_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/pkcs7.nim b/webrtc/mbedtls/pkcs7.nim deleted file mode 100644 index 217b1f2..0000000 --- a/webrtc/mbedtls/pkcs7.nim +++ /dev/null @@ -1,78 +0,0 @@ -import "asn1" -import "x509" -import "x509_crt" -import "x509_crl" -import "utils" - -{.compile: "./mbedtls/library/pkcs7.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(mbedtls_pkcs7_type) - -const - MBEDTLS_ERR_PKCS7_INVALID_FORMAT* = -0x00005300 - MBEDTLS_ERR_PKCS7_FEATURE_UNAVAILABLE* = -0x00005380 - MBEDTLS_ERR_PKCS7_INVALID_VERSION* = -0x00005400 - MBEDTLS_ERR_PKCS7_INVALID_CONTENT_INFO* = -0x00005480 - MBEDTLS_ERR_PKCS7_INVALID_ALG* = -0x00005500 - MBEDTLS_ERR_PKCS7_INVALID_CERT* = -0x00005580 - MBEDTLS_ERR_PKCS7_INVALID_SIGNATURE* = -0x00005600 - MBEDTLS_ERR_PKCS7_INVALID_SIGNER_INFO* = -0x00005680 - MBEDTLS_ERR_PKCS7_BAD_INPUT_DATA* = -0x00005700 - MBEDTLS_ERR_PKCS7_ALLOC_FAILED* = -0x00005780 - MBEDTLS_ERR_PKCS7_VERIFY_FAIL* = -0x00005800 - MBEDTLS_ERR_PKCS7_CERT_DATE_INVALID* = -0x00005880 - MBEDTLS_PKCS7_SUPPORTED_VERSION* = 0x00000001 - MBEDTLS_PKCS7_NONE* = (0).mbedtls_pkcs7_type - MBEDTLS_PKCS7_DATA* = (MBEDTLS_PKCS7_NONE + 1).mbedtls_pkcs7_type - MBEDTLS_PKCS7_SIGNED_DATA* = (MBEDTLS_PKCS7_DATA + 1).mbedtls_pkcs7_type - MBEDTLS_PKCS7_ENVELOPED_DATA* = (MBEDTLS_PKCS7_SIGNED_DATA + 1).mbedtls_pkcs7_type - MBEDTLS_PKCS7_SIGNED_AND_ENVELOPED_DATA* = (MBEDTLS_PKCS7_ENVELOPED_DATA + 1).mbedtls_pkcs7_type - MBEDTLS_PKCS7_DIGESTED_DATA* = (MBEDTLS_PKCS7_SIGNED_AND_ENVELOPED_DATA + 1).mbedtls_pkcs7_type - MBEDTLS_PKCS7_ENCRYPTED_DATA* = (MBEDTLS_PKCS7_DIGESTED_DATA + 1).mbedtls_pkcs7_type -type - mbedtls_pkcs7_buf* = mbedtls_asn1_buf - mbedtls_pkcs7_name* = mbedtls_asn1_named_data - mbedtls_pkcs7_sequence* = mbedtls_asn1_sequence - mbedtls_pkcs7_signer_info* {.bycopy.} = object - private_version*: cint - private_serial*: mbedtls_x509_buf - private_issuer*: mbedtls_x509_name - private_issuer_raw*: mbedtls_x509_buf - private_alg_identifier*: mbedtls_x509_buf - private_sig_alg_identifier*: mbedtls_x509_buf - private_sig*: mbedtls_x509_buf - private_next*: ptr mbedtls_pkcs7_signer_info - - mbedtls_pkcs7_signed_data* {.bycopy.} = object - private_version*: cint - private_digest_alg_identifiers*: mbedtls_pkcs7_buf - private_no_of_certs*: cint - private_certs*: mbedtls_x509_crt - private_no_of_crls*: cint - private_crl*: mbedtls_x509_crl - private_no_of_signers*: cint - private_signers*: mbedtls_pkcs7_signer_info - - mbedtls_pkcs7* {.bycopy.} = object - private_raw*: mbedtls_pkcs7_buf - private_signed_data*: mbedtls_pkcs7_signed_data - -proc mbedtls_pkcs7_init*(pkcs7: ptr mbedtls_pkcs7) {.importc, cdecl.} -proc mbedtls_pkcs7_parse_der*(pkcs7: ptr mbedtls_pkcs7; buf: ptr byte; - buflen: uint): cint {.importc, cdecl.} -proc mbedtls_pkcs7_signed_data_verify*(pkcs7: ptr mbedtls_pkcs7; - cert: ptr mbedtls_x509_crt; - data: ptr byte; datalen: uint): cint {. - importc, cdecl.} -proc mbedtls_pkcs7_signed_hash_verify*(pkcs7: ptr mbedtls_pkcs7; - cert: ptr mbedtls_x509_crt; - hash: ptr byte; hashlen: uint): cint {. - importc, cdecl.} -proc mbedtls_pkcs7_free*(pkcs7: ptr mbedtls_pkcs7) {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/platform.nim b/webrtc/mbedtls/platform.nim deleted file mode 100644 index 7bc2b60..0000000 --- a/webrtc/mbedtls/platform.nim +++ /dev/null @@ -1,45 +0,0 @@ -import "platform_time" - -{.compile: "./mbedtls/library/platform.c".} - -# const 'MBEDTLS_PLATFORM_STD_SNPRINTF' has unsupported value 'snprintf' -# const 'MBEDTLS_PLATFORM_STD_VSNPRINTF' has unsupported value 'vsnprintf' -# const 'MBEDTLS_PLATFORM_STD_PRINTF' has unsupported value 'printf' -# const 'MBEDTLS_PLATFORM_STD_FPRINTF' has unsupported value 'fprintf' -# const 'MBEDTLS_PLATFORM_STD_CALLOC' has unsupported value 'calloc' -# const 'MBEDTLS_PLATFORM_STD_FREE' has unsupported value 'free' -# const 'MBEDTLS_PLATFORM_STD_SETBUF' has unsupported value 'setbuf' -# const 'MBEDTLS_PLATFORM_STD_EXIT' has unsupported value 'exit' -# const 'MBEDTLS_PLATFORM_STD_TIME' has unsupported value 'time' -# const 'MBEDTLS_PLATFORM_STD_EXIT_SUCCESS' has unsupported value 'EXIT_SUCCESS' -# const 'MBEDTLS_PLATFORM_STD_EXIT_FAILURE' has unsupported value 'EXIT_FAILURE' -# const 'MBEDTLS_PLATFORM_STD_NV_SEED_READ' has unsupported value 'mbedtls_platform_std_nv_seed_read' -# const 'MBEDTLS_PLATFORM_STD_NV_SEED_WRITE' has unsupported value 'mbedtls_platform_std_nv_seed_write' -# const 'mbedtls_free' has unsupported value 'free' -# const 'mbedtls_calloc' has unsupported value 'calloc' -# const 'mbedtls_fprintf' has unsupported value 'fprintf' -# const 'mbedtls_printf' has unsupported value 'printf' -# const 'mbedtls_snprintf' has unsupported value 'MBEDTLS_PLATFORM_STD_SNPRINTF' -# const 'mbedtls_vsnprintf' has unsupported value 'vsnprintf' -# const 'mbedtls_setbuf' has unsupported value 'setbuf' -# const 'mbedtls_exit' has unsupported value 'exit' -# const 'MBEDTLS_EXIT_SUCCESS' has unsupported value 'MBEDTLS_PLATFORM_STD_EXIT_SUCCESS' -# const 'MBEDTLS_EXIT_FAILURE' has unsupported value 'MBEDTLS_PLATFORM_STD_EXIT_FAILURE' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_PLATFORM_STD_NV_SEED_FILE* = "seedfile" -type - mbedtls_platform_context* {.bycopy.} = object - private_dummy*: cchar - -proc mbedtls_platform_setup*(ctx: ptr mbedtls_platform_context): cint {.importc, - cdecl.} -proc mbedtls_platform_teardown*(ctx: ptr mbedtls_platform_context) {.importc, - cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/platform_time.nim b/webrtc/mbedtls/platform_time.nim deleted file mode 100644 index dff2cec..0000000 --- a/webrtc/mbedtls/platform_time.nim +++ /dev/null @@ -1,18 +0,0 @@ -{.used.} -{.compile: "./mbedtls/library/platform_util.c".} - -# const 'mbedtls_time' has unsupported value 'time' -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -import std/time_t as std_time_t -type time_t* = std_time_t.Time - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -type - mbedtls_time_t* = time_t - mbedtls_ms_time_t* = int64 -proc mbedtls_ms_time*(): mbedtls_ms_time_t {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/platform_util.nim b/webrtc/mbedtls/platform_util.nim deleted file mode 100644 index 354694b..0000000 --- a/webrtc/mbedtls/platform_util.nim +++ /dev/null @@ -1,17 +0,0 @@ -import "platform_time" - -# const 'MBEDTLS_CHECK_RETURN' has unsupported value '__attribute__((__warn_unused_result__))' -# const 'MBEDTLS_CHECK_RETURN_CRITICAL' has unsupported value 'MBEDTLS_CHECK_RETURN' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -type tm {.importc: "struct tm", header: "".} = object - -proc mbedtls_platform_zeroize*(buf: pointer; len: uint) {.importc, cdecl.} -proc mbedtls_platform_gmtime_r*(tt: ptr mbedtls_time_t; tm_buf: ptr tm): ptr tm {. - importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/poly1305.nim b/webrtc/mbedtls/poly1305.nim deleted file mode 100644 index e3a35ec..0000000 --- a/webrtc/mbedtls/poly1305.nim +++ /dev/null @@ -1,34 +0,0 @@ -import "md" - -{.compile: "./mbedtls/library/poly1305.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA* = -0x00000057 -type - mbedtls_poly1305_context* {.bycopy.} = object - private_r*: array[4, uint32] - private_s*: array[4, uint32] - private_acc*: array[5, uint32] - private_queue*: array[16, uint8] - private_queue_len*: uint - -proc mbedtls_poly1305_init*(ctx: ptr mbedtls_poly1305_context) {.importc, cdecl.} -proc mbedtls_poly1305_free*(ctx: ptr mbedtls_poly1305_context) {.importc, cdecl.} -proc mbedtls_poly1305_starts*(ctx: ptr mbedtls_poly1305_context; - key: array[32, byte]): cint {.importc, cdecl.} -proc mbedtls_poly1305_update*(ctx: ptr mbedtls_poly1305_context; - input: ptr byte; ilen: uint): cint {.importc, - cdecl.} -proc mbedtls_poly1305_finish*(ctx: ptr mbedtls_poly1305_context; - mac: array[16, byte]): cint {.importc, cdecl.} -proc mbedtls_poly1305_mac*(key: array[32, byte]; input: ptr byte; - ilen: uint; mac: array[16, byte]): cint {.importc, - cdecl.} -proc mbedtls_poly1305_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto.nim b/webrtc/mbedtls/psa/crypto.nim deleted file mode 100644 index 39ba003..0000000 --- a/webrtc/mbedtls/psa/crypto.nim +++ /dev/null @@ -1,589 +0,0 @@ -import "crypto_types" -import "crypto_struct" -import "../pk" -import "../ecp" -import "../ecdh" -import "../cmac" -import "../utils" - -{.compile: "./mbedtls/library/psa_crypto.c".} -{.compile: "./mbedtls/library/psa_crypto_hash.c".} -{.compile: "./mbedtls/library/psa_crypto_slot_management.c".} -{.compile: "./mbedtls/library/psa_crypto_storage.c".} -{.compile: "./mbedtls/library/psa_its_file.c".} -{.compile: "./mbedtls/library/psa_crypto_driver_wrappers.c".} -{.compile: "./mbedtls/library/psa_crypto_pake.c".} -{.compile: "./mbedtls/library/psa_crypto_rsa.c".} -{.compile: "./mbedtls/library/psa_crypto_mac.c".} -{.compile: "./mbedtls/library/psa_crypto_ecp.c".} -{.compile: "./mbedtls/library/psa_crypto_aead.c".} -{.compile: "./mbedtls/library/psa_crypto_cipher.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.pragma: impcryptoHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto.h".} -{.pragma: impcrypto_compatHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_compat.h".} -{.pragma: impcrypto_extraHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_extra.h".} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(psa_jpake_step) -defineEnum(psa_jpake_state) -defineEnum(psa_jpake_sequence) -defineEnum(psa_crypto_driver_pake_step) - -const - PSA_CRYPTO_API_VERSION_MAJOR* = 1 - PSA_CRYPTO_API_VERSION_MINOR* = 0 - PSA_KEY_DERIVATION_UNLIMITED_CAPACITY* = (cast[uint]((-1))) - - PSA_CRYPTO_ITS_RANDOM_SEED_UID* = 0xFFFFFF52 - MBEDTLS_PSA_KEY_SLOT_COUNT* = 32 - PSA_KEY_TYPE_DSA_PUBLIC_KEY* = (cast[psa_key_type_t](0x00004002)) - PSA_KEY_TYPE_DSA_KEY_PAIR* = (cast[psa_key_type_t](0x00007002)) - PSA_ALG_DSA_BASE* = (cast[psa_algorithm_t](0x06000400)) - PSA_ALG_DETERMINISTIC_DSA_BASE* = (cast[psa_algorithm_t](0x06000500)) - PSA_DH_FAMILY_CUSTOM* = (cast[psa_dh_family_t](0x0000007E)) - PSA_PAKE_OPERATION_STAGE_SETUP* = 0 - PSA_PAKE_OPERATION_STAGE_COLLECT_INPUTS* = 1 - PSA_PAKE_OPERATION_STAGE_COMPUTATION* = 2 - MBEDTLS_PSA_KEY_ID_BUILTIN_MIN* = (cast[psa_key_id_t](0x7FFF0000)) - MBEDTLS_PSA_KEY_ID_BUILTIN_MAX* = (cast[psa_key_id_t](0x7FFFEFFF)) - PSA_ALG_CATEGORY_PAKE* = (cast[psa_algorithm_t](0x0A000000)) - PSA_ALG_JPAKE* = (cast[psa_algorithm_t](0x0A000100)) - PSA_PAKE_ROLE_NONE* = (cast[psa_pake_role_t](0x00000000)) - PSA_PAKE_ROLE_FIRST* = (cast[psa_pake_role_t](0x00000001)) - PSA_PAKE_ROLE_SECOND* = (cast[psa_pake_role_t](0x00000002)) - PSA_PAKE_ROLE_CLIENT* = (cast[psa_pake_role_t](0x00000011)) - PSA_PAKE_ROLE_SERVER* = (cast[psa_pake_role_t](0x00000012)) - PSA_PAKE_PRIMITIVE_TYPE_ECC* = (cast[psa_pake_primitive_type_t](0x00000001)) - PSA_PAKE_PRIMITIVE_TYPE_DH* = (cast[psa_pake_primitive_type_t](0x00000002)) - PSA_PAKE_STEP_KEY_SHARE* = (cast[psa_pake_step_t](0x00000001)) - PSA_PAKE_STEP_ZK_PUBLIC* = (cast[psa_pake_step_t](0x00000002)) - PSA_PAKE_STEP_ZK_PROOF* = (cast[psa_pake_step_t](0x00000003)) - PSA_PAKE_OUTPUT_MAX_SIZE* = 65 - PSA_PAKE_INPUT_MAX_SIZE* = 65 - PSA_PAKE_STEP_INVALID* = (0).psa_jpake_step - PSA_PAKE_STEP_X1_X2* = (1).psa_jpake_step - PSA_PAKE_STEP_X2S* = (2).psa_jpake_step - PSA_PAKE_STEP_DERIVE* = (3).psa_jpake_step - PSA_PAKE_STATE_INVALID* = (0).psa_jpake_state - PSA_PAKE_STATE_SETUP* = (1).psa_jpake_state - PSA_PAKE_STATE_READY* = (2).psa_jpake_state - PSA_PAKE_OUTPUT_X1_X2* = (3).psa_jpake_state - PSA_PAKE_OUTPUT_X2S* = (4).psa_jpake_state - PSA_PAKE_INPUT_X1_X2* = (5).psa_jpake_state - PSA_PAKE_INPUT_X4S* = (6).psa_jpake_state - PSA_PAKE_SEQ_INVALID* = (0).psa_jpake_sequence - PSA_PAKE_X1_STEP_KEY_SHARE* = (1).psa_jpake_sequence - PSA_PAKE_X1_STEP_ZK_PUBLIC* = (2).psa_jpake_sequence - PSA_PAKE_X1_STEP_ZK_PROOF* = (3).psa_jpake_sequence - PSA_PAKE_X2_STEP_KEY_SHARE* = (4).psa_jpake_sequence - PSA_PAKE_X2_STEP_ZK_PUBLIC* = (5).psa_jpake_sequence - PSA_PAKE_X2_STEP_ZK_PROOF* = (6).psa_jpake_sequence - PSA_PAKE_SEQ_END* = (7).psa_jpake_sequence - PSA_JPAKE_STEP_INVALID* = (0).psa_crypto_driver_pake_step - PSA_JPAKE_X1_STEP_KEY_SHARE* = (1).psa_crypto_driver_pake_step - PSA_JPAKE_X1_STEP_ZK_PUBLIC* = (2).psa_crypto_driver_pake_step - PSA_JPAKE_X1_STEP_ZK_PROOF* = (3).psa_crypto_driver_pake_step - PSA_JPAKE_X2_STEP_KEY_SHARE* = (4).psa_crypto_driver_pake_step - PSA_JPAKE_X2_STEP_ZK_PUBLIC* = (5).psa_crypto_driver_pake_step - PSA_JPAKE_X2_STEP_ZK_PROOF* = (6).psa_crypto_driver_pake_step - PSA_JPAKE_X2S_STEP_KEY_SHARE* = (7).psa_crypto_driver_pake_step - PSA_JPAKE_X2S_STEP_ZK_PUBLIC* = (8).psa_crypto_driver_pake_step - PSA_JPAKE_X2S_STEP_ZK_PROOF* = (9).psa_crypto_driver_pake_step - PSA_JPAKE_X4S_STEP_KEY_SHARE* = (10).psa_crypto_driver_pake_step - PSA_JPAKE_X4S_STEP_ZK_PUBLIC* = (11).psa_crypto_driver_pake_step - PSA_JPAKE_X4S_STEP_ZK_PROOF* = (12).psa_crypto_driver_pake_step - -type - psa_hash_operation_t* {.importc, impcryptoHdr.} = psa_hash_operation_s - psa_mac_operation_t* {.importc, impcryptoHdr.} = psa_mac_operation_s - psa_cipher_operation_t* {.importc, impcryptoHdr.} = psa_cipher_operation_s - psa_aead_operation_t* {.importc, impcryptoHdr.} = psa_aead_operation_s - psa_key_derivation_operation_t* {.importc, impcryptoHdr.} = psa_key_derivation_s - psa_sign_hash_interruptible_operation_t* {.importc, impcryptoHdr.} = psa_sign_hash_interruptible_operation_s - psa_verify_hash_interruptible_operation_t* {.importc, impcryptoHdr.} = psa_verify_hash_interruptible_operation_s - - psa_key_handle_t* {.importc, impcrypto_compatHdr.} = mbedtls_svc_key_id_t - - mbedtls_psa_stats_s* {.bycopy, impcrypto_extraHdr, - importc: "struct mbedtls_psa_stats_s".} = object - private_volatile_slots*: uint - private_persistent_slots*: uint - private_external_slots*: uint - private_half_filled_slots*: uint - private_cache_slots*: uint - private_empty_slots*: uint - private_locked_slots*: uint - private_max_open_internal_key_id*: psa_key_id_t - private_max_open_external_key_id*: psa_key_id_t - - mbedtls_psa_stats_t* {.importc, impcrypto_extraHdr.} = mbedtls_psa_stats_s - psa_drv_slot_number_t* {.importc, impcrypto_extraHdr.} = uint64 - psa_pake_role_t* {.importc, impcrypto_extraHdr.} = uint8 - psa_pake_step_t* {.importc, impcrypto_extraHdr.} = uint8 - psa_pake_primitive_type_t* {.importc, impcrypto_extraHdr.} = uint8 - psa_pake_family_t* {.importc, impcrypto_extraHdr.} = uint8 - psa_pake_primitive_t* {.importc, impcrypto_extraHdr.} = uint32 - psa_pake_cipher_suite_t* {.importc, impcrypto_extraHdr.} = psa_pake_cipher_suite_s - psa_pake_operation_t* {.importc, impcrypto_extraHdr.} = psa_pake_operation_s - psa_crypto_driver_pake_inputs_t* {.importc, impcrypto_extraHdr.} = psa_crypto_driver_pake_inputs_s - psa_jpake_computation_stage_t* {.importc, impcrypto_extraHdr.} = psa_jpake_computation_stage_s - psa_pake_cipher_suite_s* {.bycopy, impcrypto_extraHdr, - importc: "struct psa_pake_cipher_suite_s".} = object - algorithm*: psa_algorithm_t - `type`*: psa_pake_primitive_type_t - family*: psa_pake_family_t - bits*: uint16 - hash*: psa_algorithm_t - - psa_crypto_driver_pake_inputs_s* {.bycopy, impcrypto_extraHdr, importc: "struct psa_crypto_driver_pake_inputs_s".} = object - private_password*: ptr uint8 - private_password_len*: uint - private_role*: psa_pake_role_t - private_user*: ptr uint8 - private_user_len*: uint - private_peer*: ptr uint8 - private_peer_len*: uint - private_attributes*: psa_key_attributes_t - private_cipher_suite*: psa_pake_cipher_suite_t - - psa_jpake_step_t* {.importc, impcrypto_extraHdr.} = psa_jpake_step - psa_jpake_state_t* {.importc, impcrypto_extraHdr.} = psa_jpake_state - psa_jpake_sequence_t* {.importc, impcrypto_extraHdr.} = psa_jpake_sequence - psa_crypto_driver_pake_step_t* {.importc, impcrypto_extraHdr.} = psa_crypto_driver_pake_step - psa_jpake_computation_stage_s* {.bycopy, impcrypto_extraHdr, importc: "struct psa_jpake_computation_stage_s".} = object - private_state*: psa_jpake_state_t - private_sequence*: psa_jpake_sequence_t - private_input_step*: psa_jpake_step_t - private_output_step*: psa_jpake_step_t - - Union_crypto_extrah1* {.union, bycopy, impcrypto_extraHdr, - importc: "union Union_crypto_extrah1".} = object - private_dummy*: uint8 - private_jpake*: psa_jpake_computation_stage_t - - Union_crypto_extrah2* {.union, bycopy, impcrypto_extraHdr, - importc: "union Union_crypto_extrah2".} = object - private_ctx*: psa_driver_pake_context_t - private_inputs*: psa_crypto_driver_pake_inputs_t - - psa_pake_operation_s* {.bycopy, impcrypto_extraHdr, - importc: "struct psa_pake_operation_s".} = object - private_id*: cuint - private_alg*: psa_algorithm_t - private_primitive*: psa_pake_primitive_t - private_stage*: uint8 - private_computation_stage*: Union_crypto_extrah1 - private_data*: Union_crypto_extrah2 - -proc psa_crypto_init*(): psa_status_t {.importc, cdecl, impcryptoHdr.} -proc psa_key_attributes_init*(): psa_key_attributes_t {.importc, cdecl, - impcryptoHdr.} -proc psa_set_key_id*(attributes: ptr psa_key_attributes_t; - key: mbedtls_svc_key_id_t) {.importc, cdecl, impcryptoHdr.} -proc psa_set_key_lifetime*(attributes: ptr psa_key_attributes_t; - lifetime: psa_key_lifetime_t) {.importc, cdecl, - impcryptoHdr.} -proc psa_get_key_id*(attributes: ptr psa_key_attributes_t): mbedtls_svc_key_id_t {. - importc, cdecl, impcryptoHdr.} -proc psa_get_key_lifetime*(attributes: ptr psa_key_attributes_t): psa_key_lifetime_t {. - importc, cdecl, impcryptoHdr.} -proc psa_set_key_usage_flags*(attributes: ptr psa_key_attributes_t; - usage_flags: psa_key_usage_t) {.importc, cdecl, - impcryptoHdr.} -proc psa_get_key_usage_flags*(attributes: ptr psa_key_attributes_t): psa_key_usage_t {. - importc, cdecl, impcryptoHdr.} -proc psa_set_key_algorithm*(attributes: ptr psa_key_attributes_t; - alg: psa_algorithm_t) {.importc, cdecl, impcryptoHdr.} -proc psa_get_key_algorithm*(attributes: ptr psa_key_attributes_t): psa_algorithm_t {. - importc, cdecl, impcryptoHdr.} -proc psa_set_key_type*(attributes: ptr psa_key_attributes_t; - `type`: psa_key_type_t) {.importc, cdecl, impcryptoHdr.} -proc psa_set_key_bits*(attributes: ptr psa_key_attributes_t; bits: uint) {. - importc, cdecl, impcryptoHdr.} -proc psa_get_key_type*(attributes: ptr psa_key_attributes_t): psa_key_type_t {. - importc, cdecl, impcryptoHdr.} -proc psa_get_key_bits*(attributes: ptr psa_key_attributes_t): uint {.importc, - cdecl, impcryptoHdr.} -proc psa_get_key_attributes*(key: mbedtls_svc_key_id_t; - attributes: ptr psa_key_attributes_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_reset_key_attributes*(attributes: ptr psa_key_attributes_t) {.importc, - cdecl, impcryptoHdr.} -proc psa_purge_key*(key: mbedtls_svc_key_id_t): psa_status_t {.importc, cdecl, - impcryptoHdr.} -proc psa_copy_key*(source_key: mbedtls_svc_key_id_t; - attributes: ptr psa_key_attributes_t; - target_key: ptr mbedtls_svc_key_id_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_destroy_key*(key: mbedtls_svc_key_id_t): psa_status_t {.importc, cdecl, - impcryptoHdr.} -proc psa_import_key*(attributes: ptr psa_key_attributes_t; data: ptr uint8; - data_length: uint; key: ptr mbedtls_svc_key_id_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_export_key*(key: mbedtls_svc_key_id_t; data: ptr uint8; - data_size: uint; data_length: ptr uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_export_public_key*(key: mbedtls_svc_key_id_t; data: ptr uint8; - data_size: uint; data_length: ptr uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_hash_compute*(alg: psa_algorithm_t; input: ptr uint8; - input_length: uint; hash: ptr uint8; hash_size: uint; - hash_length: ptr uint): psa_status_t {.importc, cdecl, - impcryptoHdr.} -proc psa_hash_compare*(alg: psa_algorithm_t; input: ptr uint8; - input_length: uint; hash: ptr uint8; hash_length: uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_hash_operation_init*(): psa_hash_operation_t {.importc, cdecl, - impcryptoHdr.} -proc psa_hash_setup*(operation: ptr psa_hash_operation_t; alg: psa_algorithm_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_hash_update*(operation: ptr psa_hash_operation_t; input: ptr uint8; - input_length: uint): psa_status_t {.importc, cdecl, - impcryptoHdr.} -proc psa_hash_finish*(operation: ptr psa_hash_operation_t; hash: ptr uint8; - hash_size: uint; hash_length: ptr uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_hash_verify*(operation: ptr psa_hash_operation_t; hash: ptr uint8; - hash_length: uint): psa_status_t {.importc, cdecl, - impcryptoHdr.} -proc psa_hash_abort*(operation: ptr psa_hash_operation_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_hash_clone*(source_operation: ptr psa_hash_operation_t; - target_operation: ptr psa_hash_operation_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_mac_compute*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; - input: ptr uint8; input_length: uint; mac: ptr uint8; - mac_size: uint; mac_length: ptr uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_mac_verify*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; - input: ptr uint8; input_length: uint; mac: ptr uint8; - mac_length: uint): psa_status_t {.importc, cdecl, - impcryptoHdr.} -proc psa_mac_operation_init*(): psa_mac_operation_t {.importc, cdecl, - impcryptoHdr.} -proc psa_mac_sign_setup*(operation: ptr psa_mac_operation_t; - key: mbedtls_svc_key_id_t; alg: psa_algorithm_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_mac_verify_setup*(operation: ptr psa_mac_operation_t; - key: mbedtls_svc_key_id_t; alg: psa_algorithm_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_mac_update*(operation: ptr psa_mac_operation_t; input: ptr uint8; - input_length: uint): psa_status_t {.importc, cdecl, - impcryptoHdr.} -proc psa_mac_sign_finish*(operation: ptr psa_mac_operation_t; mac: ptr uint8; - mac_size: uint; mac_length: ptr uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_mac_verify_finish*(operation: ptr psa_mac_operation_t; mac: ptr uint8; - mac_length: uint): psa_status_t {.importc, cdecl, - impcryptoHdr.} -proc psa_mac_abort*(operation: ptr psa_mac_operation_t): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_cipher_encrypt*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; - input: ptr uint8; input_length: uint; - output: ptr uint8; output_size: uint; - output_length: ptr uint): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_cipher_decrypt*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; - input: ptr uint8; input_length: uint; - output: ptr uint8; output_size: uint; - output_length: ptr uint): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_cipher_operation_init*(): psa_cipher_operation_t {.importc, cdecl, - impcryptoHdr.} -proc psa_cipher_encrypt_setup*(operation: ptr psa_cipher_operation_t; - key: mbedtls_svc_key_id_t; alg: psa_algorithm_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_cipher_decrypt_setup*(operation: ptr psa_cipher_operation_t; - key: mbedtls_svc_key_id_t; alg: psa_algorithm_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_cipher_generate_iv*(operation: ptr psa_cipher_operation_t; - iv: ptr uint8; iv_size: uint; iv_length: ptr uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_cipher_set_iv*(operation: ptr psa_cipher_operation_t; iv: ptr uint8; - iv_length: uint): psa_status_t {.importc, cdecl, - impcryptoHdr.} -proc psa_cipher_update*(operation: ptr psa_cipher_operation_t; input: ptr uint8; - input_length: uint; output: ptr uint8; - output_size: uint; output_length: ptr uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_cipher_finish*(operation: ptr psa_cipher_operation_t; - output: ptr uint8; output_size: uint; - output_length: ptr uint): psa_status_t {.importc, cdecl, - impcryptoHdr.} -proc psa_cipher_abort*(operation: ptr psa_cipher_operation_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_aead_encrypt*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; - nonce: ptr uint8; nonce_length: uint; - additional_data: ptr uint8; additional_data_length: uint; - plaintext: ptr uint8; plaintext_length: uint; - ciphertext: ptr uint8; ciphertext_size: uint; - ciphertext_length: ptr uint): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_aead_decrypt*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; - nonce: ptr uint8; nonce_length: uint; - additional_data: ptr uint8; additional_data_length: uint; - ciphertext: ptr uint8; ciphertext_length: uint; - plaintext: ptr uint8; plaintext_size: uint; - plaintext_length: ptr uint): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_aead_operation_init*(): psa_aead_operation_t {.importc, cdecl, - impcryptoHdr.} -proc psa_aead_encrypt_setup*(operation: ptr psa_aead_operation_t; - key: mbedtls_svc_key_id_t; alg: psa_algorithm_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_aead_decrypt_setup*(operation: ptr psa_aead_operation_t; - key: mbedtls_svc_key_id_t; alg: psa_algorithm_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_aead_generate_nonce*(operation: ptr psa_aead_operation_t; - nonce: ptr uint8; nonce_size: uint; - nonce_length: ptr uint): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_aead_set_nonce*(operation: ptr psa_aead_operation_t; nonce: ptr uint8; - nonce_length: uint): psa_status_t {.importc, cdecl, - impcryptoHdr.} -proc psa_aead_set_lengths*(operation: ptr psa_aead_operation_t; ad_length: uint; - plaintext_length: uint): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_aead_update_ad*(operation: ptr psa_aead_operation_t; input: ptr uint8; - input_length: uint): psa_status_t {.importc, cdecl, - impcryptoHdr.} -proc psa_aead_update*(operation: ptr psa_aead_operation_t; input: ptr uint8; - input_length: uint; output: ptr uint8; output_size: uint; - output_length: ptr uint): psa_status_t {.importc, cdecl, - impcryptoHdr.} -proc psa_aead_finish*(operation: ptr psa_aead_operation_t; - ciphertext: ptr uint8; ciphertext_size: uint; - ciphertext_length: ptr uint; tag: ptr uint8; - tag_size: uint; tag_length: ptr uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_aead_verify*(operation: ptr psa_aead_operation_t; plaintext: ptr uint8; - plaintext_size: uint; plaintext_length: ptr uint; - tag: ptr uint8; tag_length: uint): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_aead_abort*(operation: ptr psa_aead_operation_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_sign_message*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; - input: ptr uint8; input_length: uint; - signature: ptr uint8; signature_size: uint; - signature_length: ptr uint): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_verify_message*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; - input: ptr uint8; input_length: uint; - signature: ptr uint8; signature_length: uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_sign_hash*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; - hash: ptr uint8; hash_length: uint; signature: ptr uint8; - signature_size: uint; signature_length: ptr uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_verify_hash*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; - hash: ptr uint8; hash_length: uint; signature: ptr uint8; - signature_length: uint): psa_status_t {.importc, cdecl, - impcryptoHdr.} -proc psa_asymmetric_encrypt*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; - input: ptr uint8; input_length: uint; - salt: ptr uint8; salt_length: uint; - output: ptr uint8; output_size: uint; - output_length: ptr uint): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_asymmetric_decrypt*(key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; - input: ptr uint8; input_length: uint; - salt: ptr uint8; salt_length: uint; - output: ptr uint8; output_size: uint; - output_length: ptr uint): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_key_derivation_operation_init*(): psa_key_derivation_operation_t {. - importc, cdecl, impcryptoHdr.} -proc psa_key_derivation_setup*(operation: ptr psa_key_derivation_operation_t; - alg: psa_algorithm_t): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_key_derivation_get_capacity*(operation: ptr psa_key_derivation_operation_t; - capacity: ptr uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_key_derivation_set_capacity*(operation: ptr psa_key_derivation_operation_t; - capacity: uint): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_key_derivation_input_bytes*(operation: ptr psa_key_derivation_operation_t; - step: psa_key_derivation_step_t; - data: ptr uint8; data_length: uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_key_derivation_input_integer*(operation: ptr psa_key_derivation_operation_t; - step: psa_key_derivation_step_t; - value: uint64): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_key_derivation_input_key*(operation: ptr psa_key_derivation_operation_t; - step: psa_key_derivation_step_t; - key: mbedtls_svc_key_id_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_key_derivation_key_agreement*(operation: ptr psa_key_derivation_operation_t; - step: psa_key_derivation_step_t; - private_key: mbedtls_svc_key_id_t; - peer_key: ptr uint8; - peer_key_length: uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_key_derivation_output_bytes*(operation: ptr psa_key_derivation_operation_t; - output: ptr uint8; output_length: uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_key_derivation_output_key*(attributes: ptr psa_key_attributes_t; - operation: ptr psa_key_derivation_operation_t; key: ptr mbedtls_svc_key_id_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_key_derivation_verify_bytes*(operation: ptr psa_key_derivation_operation_t; - expected_output: ptr uint8; - output_length: uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_key_derivation_verify_key*(operation: ptr psa_key_derivation_operation_t; - expected: psa_key_id_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_key_derivation_abort*(operation: ptr psa_key_derivation_operation_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_raw_key_agreement*(alg: psa_algorithm_t; - private_key: mbedtls_svc_key_id_t; - peer_key: ptr uint8; peer_key_length: uint; - output: ptr uint8; output_size: uint; - output_length: ptr uint): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_generate_random*(output: ptr uint8; output_size: uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_generate_key*(attributes: ptr psa_key_attributes_t; - key: ptr mbedtls_svc_key_id_t): psa_status_t {.importc, - cdecl, impcryptoHdr.} -proc psa_interruptible_set_max_ops*(max_ops: uint32) {.importc, cdecl, - impcryptoHdr.} -proc psa_interruptible_get_max_ops*(): uint32 {.importc, cdecl, impcryptoHdr.} -proc psa_sign_hash_get_num_ops*(operation: ptr psa_sign_hash_interruptible_operation_t): uint32 {. - importc, cdecl, impcryptoHdr.} -proc psa_verify_hash_get_num_ops*(operation: ptr psa_verify_hash_interruptible_operation_t): uint32 {. - importc, cdecl, impcryptoHdr.} -proc psa_sign_hash_start*(operation: ptr psa_sign_hash_interruptible_operation_t; - key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; - hash: ptr uint8; hash_length: uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_sign_hash_complete*(operation: ptr psa_sign_hash_interruptible_operation_t; - signature: ptr uint8; signature_size: uint; - signature_length: ptr uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_sign_hash_abort*(operation: ptr psa_sign_hash_interruptible_operation_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_verify_hash_start*(operation: ptr psa_verify_hash_interruptible_operation_t; - key: mbedtls_svc_key_id_t; alg: psa_algorithm_t; - hash: ptr uint8; hash_length: uint; - signature: ptr uint8; signature_length: uint): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_verify_hash_complete*(operation: ptr psa_verify_hash_interruptible_operation_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} -proc psa_verify_hash_abort*(operation: ptr psa_verify_hash_interruptible_operation_t): psa_status_t {. - importc, cdecl, impcryptoHdr.} - -proc psa_key_handle_is_null*(handle: psa_key_handle_t): cint {.importc, cdecl, - impcrypto_compatHdr.} -proc psa_open_key*(key: mbedtls_svc_key_id_t; handle: ptr psa_key_handle_t): psa_status_t {. - importc, cdecl, impcrypto_compatHdr.} -proc psa_close_key*(handle: psa_key_handle_t): psa_status_t {.importc, cdecl, - impcrypto_compatHdr.} - -proc psa_set_key_enrollment_algorithm*(attributes: ptr psa_key_attributes_t; - alg2: psa_algorithm_t) {.importc, cdecl, - impcrypto_extraHdr.} -proc psa_get_key_enrollment_algorithm*(attributes: ptr psa_key_attributes_t): psa_algorithm_t {. - importc, cdecl, impcrypto_extraHdr.} -proc mbedtls_psa_crypto_free*() {.importc, cdecl, impcrypto_extraHdr.} -proc mbedtls_psa_get_stats*(stats: ptr mbedtls_psa_stats_t) {.importc, cdecl, - impcrypto_extraHdr.} -proc mbedtls_psa_inject_entropy*(seed: ptr uint8; seed_size: uint): psa_status_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_set_key_domain_parameters*(attributes: ptr psa_key_attributes_t; - `type`: psa_key_type_t; data: ptr uint8; - data_length: uint): psa_status_t {.importc, - cdecl, impcrypto_extraHdr.} -proc psa_get_key_domain_parameters*(attributes: ptr psa_key_attributes_t; - data: ptr uint8; data_size: uint; - data_length: ptr uint): psa_status_t {. - importc, cdecl, impcrypto_extraHdr.} -proc mbedtls_ecc_group_to_psa*(grpid: mbedtls_ecp_group_id; bits: ptr uint): psa_ecc_family_t {. - importc, cdecl, impcrypto_extraHdr.} -proc mbedtls_ecc_group_of_psa*(curve: psa_ecc_family_t; bits: uint; - bits_is_sloppy: cint): mbedtls_ecp_group_id {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_pake_cipher_suite_init*(): psa_pake_cipher_suite_t {.importc, cdecl, - impcrypto_extraHdr.} -proc psa_pake_cs_get_algorithm*(cipher_suite: ptr psa_pake_cipher_suite_t): psa_algorithm_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_pake_cs_set_algorithm*(cipher_suite: ptr psa_pake_cipher_suite_t; - algorithm: psa_algorithm_t) {.importc, cdecl, - impcrypto_extraHdr.} -proc psa_pake_cs_get_primitive*(cipher_suite: ptr psa_pake_cipher_suite_t): psa_pake_primitive_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_pake_cs_set_primitive*(cipher_suite: ptr psa_pake_cipher_suite_t; - primitive: psa_pake_primitive_t) {.importc, - cdecl, impcrypto_extraHdr.} -proc psa_pake_cs_get_family*(cipher_suite: ptr psa_pake_cipher_suite_t): psa_pake_family_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_pake_cs_get_bits*(cipher_suite: ptr psa_pake_cipher_suite_t): uint16 {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_pake_cs_get_hash*(cipher_suite: ptr psa_pake_cipher_suite_t): psa_algorithm_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_pake_cs_set_hash*(cipher_suite: ptr psa_pake_cipher_suite_t; - hash: psa_algorithm_t) {.importc, cdecl, - impcrypto_extraHdr.} -proc psa_pake_operation_init*(): psa_pake_operation_t {.importc, cdecl, - impcrypto_extraHdr.} -proc psa_crypto_driver_pake_get_password_len*( - inputs: ptr psa_crypto_driver_pake_inputs_t; password_len: ptr uint): psa_status_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_crypto_driver_pake_get_password*( - inputs: ptr psa_crypto_driver_pake_inputs_t; buffer: ptr uint8; - buffer_size: uint; buffer_length: ptr uint): psa_status_t {.importc, cdecl, - impcrypto_extraHdr.} -proc psa_crypto_driver_pake_get_role*(inputs: ptr psa_crypto_driver_pake_inputs_t; - role: ptr psa_pake_role_t): psa_status_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_crypto_driver_pake_get_user_len*( - inputs: ptr psa_crypto_driver_pake_inputs_t; user_len: ptr uint): psa_status_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_crypto_driver_pake_get_peer_len*( - inputs: ptr psa_crypto_driver_pake_inputs_t; peer_len: ptr uint): psa_status_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_crypto_driver_pake_get_user*(inputs: ptr psa_crypto_driver_pake_inputs_t; - user_id: ptr uint8; user_id_size: uint; - user_id_len: ptr uint): psa_status_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_crypto_driver_pake_get_peer*(inputs: ptr psa_crypto_driver_pake_inputs_t; - peer_id: ptr uint8; peer_id_size: uint; - peer_id_length: ptr uint): psa_status_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_crypto_driver_pake_get_cipher_suite*( - inputs: ptr psa_crypto_driver_pake_inputs_t; - cipher_suite: ptr psa_pake_cipher_suite_t): psa_status_t {.importc, cdecl, - impcrypto_extraHdr.} -proc psa_pake_setup*(operation: ptr psa_pake_operation_t; - cipher_suite: ptr psa_pake_cipher_suite_t): psa_status_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_pake_set_password_key*(operation: ptr psa_pake_operation_t; - password: mbedtls_svc_key_id_t): psa_status_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_pake_set_user*(operation: ptr psa_pake_operation_t; user_id: ptr uint8; - user_id_len: uint): psa_status_t {.importc, cdecl, - impcrypto_extraHdr.} -proc psa_pake_set_peer*(operation: ptr psa_pake_operation_t; peer_id: ptr uint8; - peer_id_len: uint): psa_status_t {.importc, cdecl, - impcrypto_extraHdr.} -proc psa_pake_set_role*(operation: ptr psa_pake_operation_t; - role: psa_pake_role_t): psa_status_t {.importc, cdecl, - impcrypto_extraHdr.} -proc psa_pake_output*(operation: ptr psa_pake_operation_t; - step: psa_pake_step_t; output: ptr uint8; - output_size: uint; output_length: ptr uint): psa_status_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_pake_input*(operation: ptr psa_pake_operation_t; step: psa_pake_step_t; - input: ptr uint8; input_length: uint): psa_status_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_pake_get_implicit_key*(operation: ptr psa_pake_operation_t; - output: ptr psa_key_derivation_operation_t): psa_status_t {. - importc, cdecl, impcrypto_extraHdr.} -proc psa_pake_abort*(operation: ptr psa_pake_operation_t): psa_status_t {. - importc, cdecl, impcrypto_extraHdr.} -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_builtin_composites.nim b/webrtc/mbedtls/psa/crypto_builtin_composites.nim deleted file mode 100644 index 16147af..0000000 --- a/webrtc/mbedtls/psa/crypto_builtin_composites.nim +++ /dev/null @@ -1,24 +0,0 @@ -# const 'MBEDTLS_PSA_HMAC_OPERATION_INIT' has unsupported value '{ 0, PSA_HASH_OPERATION_INIT, { 0 } }' -# const 'MBEDTLS_PSA_MAC_OPERATION_INIT' has unsupported value '{ 0, { 0 } }' -# const 'MBEDTLS_PSA_AEAD_OPERATION_INIT' has unsupported value '{ 0, 0, 0, 0, { 0 } }' -# const 'MBEDTLS_PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT' has unsupported value '{ 0 }' -# const 'MBEDTLS_VERIFY_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT' has unsupported value '{ 0 }' -# const 'MBEDTLS_PSA_PAKE_OPERATION_INIT' has unsupported value '{ { 0 } }' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.pragma: impcrypto_builtin_compositesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_builtin_composites.h".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_PSA_BUILTIN_AEAD* = 1 - MBEDTLS_PSA_BUILTIN_PAKE* = 1 - MBEDTLS_PSA_JPAKE_BUFFER_SIZE* = ((3 + typeof(3)(1) + typeof(3)(65) + - typeof(3)(1) + - typeof(3)(65) + - typeof(3)(1) + - typeof(3)(32)) * - typeof(3)(2)) -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_builtin_primitives.nim b/webrtc/mbedtls/psa/crypto_builtin_primitives.nim deleted file mode 100644 index 155cf05..0000000 --- a/webrtc/mbedtls/psa/crypto_builtin_primitives.nim +++ /dev/null @@ -1,12 +0,0 @@ -# const 'MBEDTLS_PSA_HASH_OPERATION_INIT' has unsupported value '{ 0, { 0 } }' -# const 'MBEDTLS_PSA_CIPHER_OPERATION_INIT' has unsupported value '{ 0, 0, 0, { 0 } }' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} -{.pragma: impcrypto_builtin_primitivesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_builtin_primitives.h".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_PSA_BUILTIN_CIPHER* = 1 -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_config.nim b/webrtc/mbedtls/psa/crypto_config.nim deleted file mode 100644 index c6641ab..0000000 --- a/webrtc/mbedtls/psa/crypto_config.nim +++ /dev/null @@ -1,70 +0,0 @@ -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.pragma: impcrypto_configHdr, - header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_config.h".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - PSA_WANT_ALG_CBC_NO_PADDING* = 1 - PSA_WANT_ALG_CBC_PKCS7* = 1 - PSA_WANT_ALG_CCM* = 1 - PSA_WANT_ALG_CCM_STAR_NO_TAG* = 1 - PSA_WANT_ALG_CMAC* = 1 - PSA_WANT_ALG_CFB* = 1 - PSA_WANT_ALG_CHACHA20_POLY1305* = 1 - PSA_WANT_ALG_CTR* = 1 - PSA_WANT_ALG_DETERMINISTIC_ECDSA* = 1 - PSA_WANT_ALG_ECB_NO_PADDING* = 1 - PSA_WANT_ALG_ECDH* = 1 - PSA_WANT_ALG_ECDSA* = 1 - PSA_WANT_ALG_JPAKE* = 1 - PSA_WANT_ALG_GCM* = 1 - PSA_WANT_ALG_HKDF* = 1 - PSA_WANT_ALG_HKDF_EXTRACT* = 1 - PSA_WANT_ALG_HKDF_EXPAND* = 1 - PSA_WANT_ALG_HMAC* = 1 - PSA_WANT_ALG_MD5* = 1 - PSA_WANT_ALG_OFB* = 1 - PSA_WANT_ALG_RIPEMD160* = 1 - PSA_WANT_ALG_RSA_OAEP* = 1 - PSA_WANT_ALG_RSA_PKCS1V15_CRYPT* = 1 - PSA_WANT_ALG_RSA_PKCS1V15_SIGN* = 1 - PSA_WANT_ALG_RSA_PSS* = 1 - PSA_WANT_ALG_SHA_1* = 1 - PSA_WANT_ALG_SHA_224* = 1 - PSA_WANT_ALG_SHA_256* = 1 - PSA_WANT_ALG_SHA_384* = 1 - PSA_WANT_ALG_SHA_512* = 1 - PSA_WANT_ALG_STREAM_CIPHER* = 1 - PSA_WANT_ALG_TLS12_PRF* = 1 - PSA_WANT_ALG_TLS12_PSK_TO_MS* = 1 - PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS* = 1 - PSA_WANT_ECC_BRAINPOOL_P_R1_256* = 1 - PSA_WANT_ECC_BRAINPOOL_P_R1_384* = 1 - PSA_WANT_ECC_BRAINPOOL_P_R1_512* = 1 - PSA_WANT_ECC_MONTGOMERY_255* = 1 - PSA_WANT_ECC_MONTGOMERY_448* = 1 - PSA_WANT_ECC_SECP_K1_192* = 1 - PSA_WANT_ECC_SECP_K1_256* = 1 - PSA_WANT_ECC_SECP_R1_192* = 1 - PSA_WANT_ECC_SECP_R1_224* = 1 - PSA_WANT_ECC_SECP_R1_256* = 1 - PSA_WANT_ECC_SECP_R1_384* = 1 - PSA_WANT_ECC_SECP_R1_521* = 1 - PSA_WANT_KEY_TYPE_DERIVE* = 1 - PSA_WANT_KEY_TYPE_PASSWORD* = 1 - PSA_WANT_KEY_TYPE_PASSWORD_HASH* = 1 - PSA_WANT_KEY_TYPE_HMAC* = 1 - PSA_WANT_KEY_TYPE_AES* = 1 - PSA_WANT_KEY_TYPE_ARIA* = 1 - PSA_WANT_KEY_TYPE_CAMELLIA* = 1 - PSA_WANT_KEY_TYPE_CHACHA20* = 1 - PSA_WANT_KEY_TYPE_DES* = 1 - PSA_WANT_KEY_TYPE_ECC_KEY_PAIR* = 1 - PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY* = 1 - PSA_WANT_KEY_TYPE_RAW_DATA* = 1 - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR* = 1 - PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY* = 1 -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_driver_common.nim b/webrtc/mbedtls/psa/crypto_driver_common.nim deleted file mode 100644 index 638f6cd..0000000 --- a/webrtc/mbedtls/psa/crypto_driver_common.nim +++ /dev/null @@ -1,15 +0,0 @@ -import "../utils" - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.pragma: impcrypto_driver_commonHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_driver_common.h".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(psa_encrypt_or_decrypt_t) - -const - PSA_CRYPTO_DRIVER_DECRYPT* = (0).psa_encrypt_or_decrypt_t - PSA_CRYPTO_DRIVER_ENCRYPT* = (PSA_CRYPTO_DRIVER_DECRYPT + 1).psa_encrypt_or_decrypt_t -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_se_driver.nim b/webrtc/mbedtls/psa/crypto_se_driver.nim deleted file mode 100644 index 995fc6f..0000000 --- a/webrtc/mbedtls/psa/crypto_se_driver.nim +++ /dev/null @@ -1,206 +0,0 @@ -import "crypto_driver_common" -import "crypto_types" -import "../utils" - -{.compile: "./mbedtls/library/psa_crypto_se.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.pragma: impcrypto_se_driverHdr, - header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_se_driver.h".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(psa_key_creation_method_t) - -const - PSA_KEY_CREATION_IMPORT* = (0).psa_key_creation_method_t - PSA_KEY_CREATION_GENERATE* = (PSA_KEY_CREATION_IMPORT + 1).psa_key_creation_method_t - PSA_KEY_CREATION_DERIVE* = (PSA_KEY_CREATION_GENERATE + 1).psa_key_creation_method_t - PSA_KEY_CREATION_COPY* = (PSA_KEY_CREATION_DERIVE + 1).psa_key_creation_method_t - PSA_KEY_CREATION_REGISTER* = (PSA_KEY_CREATION_COPY + 1).psa_key_creation_method_t - PSA_DRV_SE_HAL_VERSION* = 0x00000005 -type - psa_drv_se_context_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object - private_persistent_data*: pointer - private_persistent_data_size*: uint - private_transient_data*: ptr uint - - psa_drv_se_init_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; persistent_data: pointer; - location: psa_key_location_t): psa_status_t {.cdecl.} - psa_key_slot_number_t* {.importc, impcrypto_se_driverHdr.} = uint64 - psa_drv_se_mac_setup_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; op_context: pointer; - key_slot: psa_key_slot_number_t; algorithm: psa_algorithm_t): psa_status_t {. - cdecl.} - psa_drv_se_mac_update_t* {.importc, impcrypto_se_driverHdr.} = proc ( - op_context: pointer; p_input: ptr uint8; input_length: uint): psa_status_t {. - cdecl.} - psa_drv_se_mac_finish_t* {.importc, impcrypto_se_driverHdr.} = proc ( - op_context: pointer; p_mac: ptr uint8; mac_size: uint; - p_mac_length: ptr uint): psa_status_t {.cdecl.} - psa_drv_se_mac_finish_verify_t* {.importc, impcrypto_se_driverHdr.} = proc ( - op_context: pointer; p_mac: ptr uint8; mac_length: uint): psa_status_t {. - cdecl.} - psa_drv_se_mac_abort_t* {.importc, impcrypto_se_driverHdr.} = proc ( - op_context: pointer): psa_status_t {.cdecl.} - psa_drv_se_mac_generate_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; p_input: ptr uint8; - input_length: uint; key_slot: psa_key_slot_number_t; alg: psa_algorithm_t; - p_mac: ptr uint8; mac_size: uint; p_mac_length: ptr uint): psa_status_t {. - cdecl.} - psa_drv_se_mac_verify_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; p_input: ptr uint8; - input_length: uint; key_slot: psa_key_slot_number_t; alg: psa_algorithm_t; - p_mac: ptr uint8; mac_length: uint): psa_status_t {.cdecl.} - psa_drv_se_mac_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object - private_context_size*: uint - private_p_setup*: psa_drv_se_mac_setup_t - private_p_update*: psa_drv_se_mac_update_t - private_p_finish*: psa_drv_se_mac_finish_t - private_p_finish_verify*: psa_drv_se_mac_finish_verify_t - private_p_abort*: psa_drv_se_mac_abort_t - private_p_mac*: psa_drv_se_mac_generate_t - private_p_mac_verify*: psa_drv_se_mac_verify_t - - psa_drv_se_cipher_setup_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; op_context: pointer; - key_slot: psa_key_slot_number_t; algorithm: psa_algorithm_t; - direction: psa_encrypt_or_decrypt_t): psa_status_t {.cdecl.} - psa_drv_se_cipher_set_iv_t* {.importc, impcrypto_se_driverHdr.} = proc ( - op_context: pointer; p_iv: ptr uint8; iv_length: uint): psa_status_t {. - cdecl.} - psa_drv_se_cipher_update_t* {.importc, impcrypto_se_driverHdr.} = proc ( - op_context: pointer; p_input: ptr uint8; input_size: uint; - p_output: ptr uint8; output_size: uint; p_output_length: ptr uint): psa_status_t {. - cdecl.} - psa_drv_se_cipher_finish_t* {.importc, impcrypto_se_driverHdr.} = proc ( - op_context: pointer; p_output: ptr uint8; output_size: uint; - p_output_length: ptr uint): psa_status_t {.cdecl.} - psa_drv_se_cipher_abort_t* {.importc, impcrypto_se_driverHdr.} = proc ( - op_context: pointer): psa_status_t {.cdecl.} - psa_drv_se_cipher_ecb_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; - algorithm: psa_algorithm_t; direction: psa_encrypt_or_decrypt_t; - p_input: ptr uint8; input_size: uint; p_output: ptr uint8; - output_size: uint): psa_status_t {.cdecl.} - psa_drv_se_cipher_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object - private_context_size*: uint - private_p_setup*: psa_drv_se_cipher_setup_t - private_p_set_iv*: psa_drv_se_cipher_set_iv_t - private_p_update*: psa_drv_se_cipher_update_t - private_p_finish*: psa_drv_se_cipher_finish_t - private_p_abort*: psa_drv_se_cipher_abort_t - private_p_ecb*: psa_drv_se_cipher_ecb_t - - psa_drv_se_asymmetric_sign_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; - alg: psa_algorithm_t; p_hash: ptr uint8; hash_length: uint; - p_signature: ptr uint8; signature_size: uint; p_signature_length: ptr uint): psa_status_t {. - cdecl.} - psa_drv_se_asymmetric_verify_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; - alg: psa_algorithm_t; p_hash: ptr uint8; hash_length: uint; - p_signature: ptr uint8; signature_length: uint): psa_status_t {.cdecl.} - psa_drv_se_asymmetric_encrypt_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; - alg: psa_algorithm_t; p_input: ptr uint8; input_length: uint; - p_salt: ptr uint8; salt_length: uint; p_output: ptr uint8; - output_size: uint; p_output_length: ptr uint): psa_status_t {.cdecl.} - psa_drv_se_asymmetric_decrypt_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; - alg: psa_algorithm_t; p_input: ptr uint8; input_length: uint; - p_salt: ptr uint8; salt_length: uint; p_output: ptr uint8; - output_size: uint; p_output_length: ptr uint): psa_status_t {.cdecl.} - psa_drv_se_asymmetric_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object - private_p_sign*: psa_drv_se_asymmetric_sign_t - private_p_verify*: psa_drv_se_asymmetric_verify_t - private_p_encrypt*: psa_drv_se_asymmetric_encrypt_t - private_p_decrypt*: psa_drv_se_asymmetric_decrypt_t - - psa_drv_se_aead_encrypt_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; - algorithm: psa_algorithm_t; p_nonce: ptr uint8; nonce_length: uint; - p_additional_data: ptr uint8; additional_data_length: uint; - p_plaintext: ptr uint8; plaintext_length: uint; p_ciphertext: ptr uint8; - ciphertext_size: uint; p_ciphertext_length: ptr uint): psa_status_t {. - cdecl.} - psa_drv_se_aead_decrypt_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; - algorithm: psa_algorithm_t; p_nonce: ptr uint8; nonce_length: uint; - p_additional_data: ptr uint8; additional_data_length: uint; - p_ciphertext: ptr uint8; ciphertext_length: uint; p_plaintext: ptr uint8; - plaintext_size: uint; p_plaintext_length: ptr uint): psa_status_t {.cdecl.} - psa_drv_se_aead_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object - private_p_encrypt*: psa_drv_se_aead_encrypt_t - private_p_decrypt*: psa_drv_se_aead_decrypt_t - - psa_drv_se_allocate_key_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; persistent_data: pointer; - attributes: ptr psa_key_attributes_t; `method`: psa_key_creation_method_t; - key_slot: ptr psa_key_slot_number_t): psa_status_t {.cdecl.} - psa_drv_se_validate_slot_number_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; persistent_data: pointer; - attributes: ptr psa_key_attributes_t; `method`: psa_key_creation_method_t; - key_slot: psa_key_slot_number_t): psa_status_t {.cdecl.} - psa_drv_se_import_key_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; - attributes: ptr psa_key_attributes_t; data: ptr uint8; data_length: uint; - bits: ptr uint): psa_status_t {.cdecl.} - psa_drv_se_destroy_key_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; persistent_data: pointer; - key_slot: psa_key_slot_number_t): psa_status_t {.cdecl.} - psa_drv_se_export_key_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; key: psa_key_slot_number_t; - p_data: ptr uint8; data_size: uint; p_data_length: ptr uint): psa_status_t {. - cdecl.} - psa_drv_se_generate_key_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; key_slot: psa_key_slot_number_t; - attributes: ptr psa_key_attributes_t; pubkey: ptr uint8; - pubkey_size: uint; pubkey_length: ptr uint): psa_status_t {.cdecl.} - psa_drv_se_key_management_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object - private_p_allocate*: psa_drv_se_allocate_key_t - private_p_validate_slot_number*: psa_drv_se_validate_slot_number_t - private_p_import*: psa_drv_se_import_key_t - private_p_generate*: psa_drv_se_generate_key_t - private_p_destroy*: psa_drv_se_destroy_key_t - private_p_export*: psa_drv_se_export_key_t - private_p_export_public*: psa_drv_se_export_key_t - - psa_drv_se_key_derivation_setup_t* {.importc, impcrypto_se_driverHdr.} = proc ( - drv_context: ptr psa_drv_se_context_t; op_context: pointer; - kdf_alg: psa_algorithm_t; source_key: psa_key_slot_number_t): psa_status_t {. - cdecl.} - psa_drv_se_key_derivation_collateral_t* {.importc, impcrypto_se_driverHdr.} = proc ( - op_context: pointer; collateral_id: uint32; p_collateral: ptr uint8; - collateral_size: uint): psa_status_t {.cdecl.} - psa_drv_se_key_derivation_derive_t* {.importc, impcrypto_se_driverHdr.} = proc ( - op_context: pointer; dest_key: psa_key_slot_number_t): psa_status_t {. - cdecl.} - psa_drv_se_key_derivation_export_t* {.importc, impcrypto_se_driverHdr.} = proc ( - op_context: pointer; p_output: ptr uint8; output_size: uint; - p_output_length: ptr uint): psa_status_t {.cdecl.} - psa_drv_se_key_derivation_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object - private_context_size*: uint - private_p_setup*: psa_drv_se_key_derivation_setup_t - private_p_collateral*: psa_drv_se_key_derivation_collateral_t - private_p_derive*: psa_drv_se_key_derivation_derive_t - private_p_export*: psa_drv_se_key_derivation_export_t - - psa_drv_se_t* {.bycopy, importc, impcrypto_se_driverHdr.} = object - private_hal_version*: uint32 - private_persistent_data_size*: uint - private_p_init*: psa_drv_se_init_t - private_key_management*: ptr psa_drv_se_key_management_t - private_mac*: ptr psa_drv_se_mac_t - private_cipher*: ptr psa_drv_se_cipher_t - private_aead*: ptr psa_drv_se_aead_t - private_asymmetric*: ptr psa_drv_se_asymmetric_t - private_derivation*: ptr psa_drv_se_key_derivation_t - -proc psa_register_se_driver*(location: psa_key_location_t; - methods: ptr psa_drv_se_t): psa_status_t {.importc, - cdecl, impcrypto_se_driverHdr.} -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_sizes.nim b/webrtc/mbedtls/psa/crypto_sizes.nim deleted file mode 100644 index 63fdd09..0000000 --- a/webrtc/mbedtls/psa/crypto_sizes.nim +++ /dev/null @@ -1,33 +0,0 @@ -# const 'PSA_MAC_MAX_SIZE' has unsupported value 'PSA_HASH_MAX_SIZE' -# const 'PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE' has unsupported value 'PSA_ECDSA_SIGNATURE_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)' -# const 'PSA_SIGNATURE_MAX_SIZE' has unsupported value '(PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS) > PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE ? PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS) : PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE)' -# const 'PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE' has unsupported value '(PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS))' -# const 'PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE' has unsupported value '(PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS))' -# const 'PSA_EXPORT_KEY_PAIR_MAX_SIZE' has unsupported value '(PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) > PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS) ? PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) : PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS))' -# const 'PSA_EXPORT_PUBLIC_KEY_MAX_SIZE' has unsupported value '(PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) > PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS) ? PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) : PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS))' -# const 'PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE' has unsupported value '(PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS))' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.pragma: impcrypto_sizesHdr, - header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_sizes.h".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - PSA_HASH_MAX_SIZE* = 64 - PSA_HMAC_MAX_HASH_BLOCK_SIZE* = 128 - PSA_AEAD_TAG_MAX_SIZE* = 16 - PSA_VENDOR_RSA_MAX_KEY_BITS* = 4096 - PSA_VENDOR_ECC_MAX_CURVE_BITS* = 521 - PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE* = 128 - PSA_TLS12_ECJPAKE_TO_PMS_INPUT_SIZE* = 65 - PSA_TLS12_ECJPAKE_TO_PMS_DATA_SIZE* = 32 - PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE* = 16 - PSA_AEAD_NONCE_MAX_SIZE* = 13 - PSA_AEAD_FINISH_OUTPUT_MAX_SIZE* = (PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE) - PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE* = (PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE) - PSA_CIPHER_IV_MAX_SIZE* = 16 - PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE* = (PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE) -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_struct.nim b/webrtc/mbedtls/psa/crypto_struct.nim deleted file mode 100644 index 70ebb39..0000000 --- a/webrtc/mbedtls/psa/crypto_struct.nim +++ /dev/null @@ -1,85 +0,0 @@ -import "crypto_types" -{.compile: "./mbedtls/library/psa_crypto_client.c".} - -# const 'PSA_HASH_OPERATION_INIT' has unsupported value '{ 0, { 0 } }' -# const 'PSA_CIPHER_OPERATION_INIT' has unsupported value '{ 0, 0, 0, 0, { 0 } }' -# const 'PSA_MAC_OPERATION_INIT' has unsupported value '{ 0, 0, 0, { 0 } }' -# const 'PSA_AEAD_OPERATION_INIT' has unsupported value '{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { 0 } }' -# const 'PSA_KEY_DERIVATION_OPERATION_INIT' has unsupported value '{ 0, 0, 0, { 0 } }' -# const 'PSA_KEY_POLICY_INIT' has unsupported value '{ 0, 0, 0 }' -# const 'PSA_KEY_BITS_TOO_LARGE' has unsupported value '((psa_key_bits_t) -1)' -# const 'PSA_CORE_KEY_ATTRIBUTES_INIT' has unsupported value '{ PSA_KEY_TYPE_NONE, 0, PSA_KEY_LIFETIME_VOLATILE, MBEDTLS_SVC_KEY_ID_INIT, PSA_KEY_POLICY_INIT, 0 }' -# const 'PSA_KEY_ATTRIBUTES_INIT' has unsupported value '{ PSA_CORE_KEY_ATTRIBUTES_INIT, NULL, 0 }' -# const 'PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT' has unsupported value '{ 0, { 0 }, 0, 0 }' -# const 'PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT' has unsupported value '{ 0, { 0 }, 0, 0 }' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.pragma: impcrypto_structHdr, - header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_struct.h".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - PSA_MAX_KEY_BITS* = 0x0000FFF8 - MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER* = ( - cast[psa_key_attributes_flag_t](0x00000001)) - MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY* = (MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER or - typeof(MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER)(0)) - MBEDTLS_PSA_KA_MASK_DUAL_USE* = (0) - -proc psa_hash_operation_init*(): psa_hash_operation_s {.importc, cdecl, - impcrypto_structHdr.} -proc psa_cipher_operation_init*(): psa_cipher_operation_s {.importc, cdecl, - impcrypto_structHdr.} -proc psa_mac_operation_init*(): psa_mac_operation_s {.importc, cdecl, - impcrypto_structHdr.} -proc psa_aead_operation_init*(): psa_aead_operation_s {.importc, cdecl, - impcrypto_structHdr.} -proc psa_key_derivation_operation_init*(): psa_key_derivation_s {.importc, - cdecl, impcrypto_structHdr.} -proc psa_key_policy_init*(): psa_key_policy_s {.importc, cdecl, - impcrypto_structHdr.} -proc psa_key_attributes_init*(): psa_key_attributes_s {.importc, cdecl, - impcrypto_structHdr.} -proc psa_set_key_id*(attributes: ptr psa_key_attributes_t; - key: mbedtls_svc_key_id_t) {.importc, cdecl, - impcrypto_structHdr.} -proc psa_get_key_id*(attributes: ptr psa_key_attributes_t): mbedtls_svc_key_id_t {. - importc, cdecl, impcrypto_structHdr.} -proc psa_set_key_lifetime*(attributes: ptr psa_key_attributes_t; - lifetime: psa_key_lifetime_t) {.importc, cdecl, - impcrypto_structHdr.} -proc psa_get_key_lifetime*(attributes: ptr psa_key_attributes_t): psa_key_lifetime_t {. - importc, cdecl, impcrypto_structHdr.} -proc psa_extend_key_usage_flags*(usage_flags: ptr psa_key_usage_t) {.importc, - cdecl, impcrypto_structHdr.} -proc psa_set_key_usage_flags*(attributes: ptr psa_key_attributes_t; - usage_flags: psa_key_usage_t) {.importc, cdecl, - impcrypto_structHdr.} -proc psa_get_key_usage_flags*(attributes: ptr psa_key_attributes_t): psa_key_usage_t {. - importc, cdecl, impcrypto_structHdr.} -proc psa_set_key_algorithm*(attributes: ptr psa_key_attributes_t; - alg: psa_algorithm_t) {.importc, cdecl, - impcrypto_structHdr.} -proc psa_get_key_algorithm*(attributes: ptr psa_key_attributes_t): psa_algorithm_t {. - importc, cdecl, impcrypto_structHdr.} -proc psa_set_key_domain_parameters*(attributes: ptr psa_key_attributes_t; - `type`: psa_key_type_t; data: ptr uint8; - data_length: uint): psa_status_t {.importc, - cdecl, impcrypto_structHdr.} -proc psa_set_key_type*(attributes: ptr psa_key_attributes_t; - `type`: psa_key_type_t) {.importc, cdecl, - impcrypto_structHdr.} -proc psa_get_key_type*(attributes: ptr psa_key_attributes_t): psa_key_type_t {. - importc, cdecl, impcrypto_structHdr.} -proc psa_set_key_bits*(attributes: ptr psa_key_attributes_t; bits: uint) {. - importc, cdecl, impcrypto_structHdr.} -proc psa_get_key_bits*(attributes: ptr psa_key_attributes_t): uint {.importc, - cdecl, impcrypto_structHdr.} -proc psa_sign_hash_interruptible_operation_init*(): psa_sign_hash_interruptible_operation_s {. - importc, cdecl, impcrypto_structHdr.} -proc psa_verify_hash_interruptible_operation_init*(): psa_verify_hash_interruptible_operation_s {. - importc, cdecl, impcrypto_structHdr.} -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_types.nim b/webrtc/mbedtls/psa/crypto_types.nim deleted file mode 100644 index a0a2428..0000000 --- a/webrtc/mbedtls/psa/crypto_types.nim +++ /dev/null @@ -1,295 +0,0 @@ -import "../md5" -import "../ripemd160" -import "../sha1" -import "../sha256" -import "../sha512" -import "../cipher" -import "../ccm" -import "../gcm" -import "../chachapoly" -import "../ecjpake" -import "../utils" - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.pragma: impcrypto_builtin_key_derivationHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_builtin_key_derivation.h".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(psa_tls12_prf_key_derivation_state_t) - -const - PSA_TLS12_PRF_STATE_INIT* = (0).psa_tls12_prf_key_derivation_state_t - PSA_TLS12_PRF_STATE_SEED_SET* = (PSA_TLS12_PRF_STATE_INIT + 1).psa_tls12_prf_key_derivation_state_t - PSA_TLS12_PRF_STATE_OTHER_KEY_SET* = (PSA_TLS12_PRF_STATE_SEED_SET + 1).psa_tls12_prf_key_derivation_state_t - PSA_TLS12_PRF_STATE_KEY_SET* = (PSA_TLS12_PRF_STATE_OTHER_KEY_SET + 1).psa_tls12_prf_key_derivation_state_t - PSA_TLS12_PRF_STATE_LABEL_SET* = (PSA_TLS12_PRF_STATE_KEY_SET + 1).psa_tls12_prf_key_derivation_state_t - PSA_TLS12_PRF_STATE_OUTPUT* = (PSA_TLS12_PRF_STATE_LABEL_SET + 1).psa_tls12_prf_key_derivation_state_t - - -{.pragma: impcrypto_typesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_types.h".} -{.pragma: impcrypto_builtin_primitivesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_builtin_primitives.h".} -{.pragma: impcrypto_driver_contexts_primitivesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_driver_contexts_primitives.h".} -{.pragma: impcrypto_structHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_struct.h".} -{.pragma: impcrypto_builtin_compositesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_builtin_composites.h".} -{.pragma: impcrypto_driver_contexts_compositesHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_driver_contexts_composites.h".} -{.pragma: impcrypto_builtin_key_derivationHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_builtin_key_derivation.h".} -{.pragma: impcrypto_driver_contexts_key_derivationHdr, header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_driver_contexts_key_derivation.h".} -{.experimental: "codeReordering".} -{.experimental: "codeReordering".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} -type - psa_hkdf_key_derivation_t* {.bycopy, importc, - impcrypto_builtin_key_derivationHdr.} = object - private_info*: ptr uint8 - private_info_length*: uint - private_offset_in_block*: uint8 - private_block_number*: uint8 - private_state* {.bitsize: 2.}: cuint - private_info_set* {.bitsize: 1.}: cuint - private_output_block*: array[64, uint8] - private_prk*: array[64, uint8] - private_hmac*: psa_mac_operation_s - - psa_tls12_ecjpake_to_pms_t* {.bycopy, importc, - impcrypto_builtin_key_derivationHdr.} = object - private_data*: array[32, uint8] - - psa_tls12_prf_key_derivation_s* {.bycopy, impcrypto_builtin_key_derivationHdr, importc: "struct psa_tls12_prf_key_derivation_s".} = object - private_left_in_block*: uint8 - private_block_number*: uint8 - private_state*: psa_tls12_prf_key_derivation_state_t - private_secret*: ptr uint8 - private_secret_length*: uint - private_seed*: ptr uint8 - private_seed_length*: uint - private_label*: ptr uint8 - private_label_length*: uint - private_other_secret*: ptr uint8 - private_other_secret_length*: uint - private_Ai*: array[64, uint8] - private_output_block*: array[64, uint8] - - psa_tls12_prf_key_derivation_t* {.importc, impcrypto_builtin_key_derivationHdr.} = psa_tls12_prf_key_derivation_s - psa_driver_key_derivation_context_t* {.union, bycopy, importc, - impcrypto_driver_contexts_key_derivationHdr.} = object - dummy*: cuint - private_hkdf*: psa_hkdf_key_derivation_t - private_tls12_prf*: psa_tls12_prf_key_derivation_t - private_tls12_ecjpake_to_pms*: psa_tls12_ecjpake_to_pms_t - - mbedtls_psa_hmac_operation_t* {.bycopy, importc, - impcrypto_builtin_compositesHdr.} = object - private_alg*: psa_algorithm_t - hash_ctx*: psa_hash_operation_s - private_opad*: array[128, uint8] - - Union_crypto_builtin_compositesh1* {.union, bycopy, - impcrypto_builtin_compositesHdr, importc: "union Union_crypto_builtin_compositesh1".} = object - private_dummy*: cuint - private_hmac*: mbedtls_psa_hmac_operation_t - private_cmac*: mbedtls_cipher_context_t - - mbedtls_psa_mac_operation_t* {.bycopy, importc, - impcrypto_builtin_compositesHdr.} = object - private_alg*: psa_algorithm_t - private_ctx*: Union_crypto_builtin_compositesh1 - - Union_crypto_builtin_compositesh2* {.union, bycopy, - impcrypto_builtin_compositesHdr, importc: "union Union_crypto_builtin_compositesh2".} = object - dummy*: cuint - private_ccm*: mbedtls_ccm_context - private_gcm*: mbedtls_gcm_context - private_chachapoly*: mbedtls_chachapoly_context - - mbedtls_psa_aead_operation_t* {.bycopy, importc, - impcrypto_builtin_compositesHdr.} = object - private_alg*: psa_algorithm_t - private_key_type*: psa_key_type_t - private_is_encrypt* {.bitsize: 1.}: cuint - private_tag_length*: uint8 - ctx*: Union_crypto_builtin_compositesh2 - - mbedtls_psa_sign_hash_interruptible_operation_t* {.bycopy, importc, - impcrypto_builtin_compositesHdr.} = object - private_dummy*: cuint - - mbedtls_psa_verify_hash_interruptible_operation_t* {.bycopy, importc, - impcrypto_builtin_compositesHdr.} = object - private_dummy*: cuint - - Union_crypto_builtin_compositesh3* {.union, bycopy, - impcrypto_builtin_compositesHdr, importc: "union Union_crypto_builtin_compositesh3".} = object - private_dummy*: cuint - private_jpake*: mbedtls_ecjpake_context - - mbedtls_psa_pake_operation_t* {.bycopy, importc, - impcrypto_builtin_compositesHdr.} = object - private_alg*: psa_algorithm_t - private_password*: ptr uint8 - private_password_len*: uint - private_role*: uint8 - private_buffer*: array[((3 + typeof(3)(1) + typeof(3)(65) + typeof(3)(1) + - typeof(3)(65) + - typeof(3)(1) + - typeof(3)(32)) * - typeof(3)(2)), uint8] - private_buffer_length*: uint - private_buffer_offset*: uint - private_ctx*: Union_crypto_builtin_compositesh3 - - psa_driver_mac_context_t* {.union, bycopy, importc, - impcrypto_driver_contexts_compositesHdr.} = object - dummy*: cuint - mbedtls_ctx*: mbedtls_psa_mac_operation_t - - psa_driver_aead_context_t* {.union, bycopy, importc, - impcrypto_driver_contexts_compositesHdr.} = object - dummy*: cuint - mbedtls_ctx*: mbedtls_psa_aead_operation_t - - psa_driver_sign_hash_interruptible_context_t* {.union, bycopy, importc, - impcrypto_driver_contexts_compositesHdr.} = object - dummy*: cuint - mbedtls_ctx*: mbedtls_psa_sign_hash_interruptible_operation_t - - psa_driver_verify_hash_interruptible_context_t* {.union, bycopy, importc, - impcrypto_driver_contexts_compositesHdr.} = object - dummy*: cuint - mbedtls_ctx*: mbedtls_psa_verify_hash_interruptible_operation_t - - psa_driver_pake_context_t* {.union, bycopy, importc, - impcrypto_driver_contexts_compositesHdr.} = object - dummy*: cuint - mbedtls_ctx*: mbedtls_psa_pake_operation_t - - Union_crypto_builtin_primitivesh1* {.union, bycopy, - impcrypto_builtin_primitivesHdr, importc: "union Union_crypto_builtin_primitivesh1".} = object - dummy*: cuint - md5*: mbedtls_md5_context - ripemd160*: mbedtls_ripemd160_context - sha1*: mbedtls_sha1_context - sha256*: mbedtls_sha256_context - sha512*: mbedtls_sha512_context - - mbedtls_psa_hash_operation_t* {.bycopy, importc, - impcrypto_builtin_primitivesHdr.} = object - private_alg*: psa_algorithm_t - private_ctx*: Union_crypto_builtin_primitivesh1 - - Union_crypto_builtin_primitivesh2* {.union, bycopy, - impcrypto_builtin_primitivesHdr, importc: "union Union_crypto_builtin_primitivesh2".} = object - private_dummy*: cuint - private_cipher*: mbedtls_cipher_context_t - - mbedtls_psa_cipher_operation_t* {.bycopy, importc, - impcrypto_builtin_primitivesHdr.} = object - private_alg*: psa_algorithm_t - private_iv_length*: uint8 - private_block_length*: uint8 - private_ctx*: Union_crypto_builtin_primitivesh2 - psa_driver_hash_context_t* {.union, bycopy, importc, - impcrypto_driver_contexts_primitivesHdr.} = object - dummy*: cuint - mbedtls_ctx*: mbedtls_psa_hash_operation_t - - psa_driver_cipher_context_t* {.union, bycopy, importc, - impcrypto_driver_contexts_primitivesHdr.} = object - dummy*: cuint - mbedtls_ctx*: mbedtls_psa_cipher_operation_t - - psa_hash_operation_s* {.bycopy, impcrypto_structHdr, - importc: "struct psa_hash_operation_s".} = object - private_id*: cuint - private_ctx*: psa_driver_hash_context_t - - psa_cipher_operation_s* {.bycopy, impcrypto_structHdr, - importc: "struct psa_cipher_operation_s".} = object - private_id*: cuint - private_iv_required* {.bitsize: 1.}: cuint - private_iv_set* {.bitsize: 1.}: cuint - private_default_iv_length*: uint8 - private_ctx*: psa_driver_cipher_context_t - - psa_mac_operation_s* {.bycopy, impcrypto_structHdr, - importc: "struct psa_mac_operation_s".} = object - private_id*: cuint - private_mac_size*: uint8 - private_is_sign* {.bitsize: 1.}: cuint - private_ctx*: psa_driver_mac_context_t - - psa_aead_operation_s* {.bycopy, impcrypto_structHdr, - importc: "struct psa_aead_operation_s".} = object - private_id*: cuint - private_alg*: psa_algorithm_t - private_key_type*: psa_key_type_t - private_ad_remaining*: uint - private_body_remaining*: uint - private_nonce_set* {.bitsize: 1.}: cuint - private_lengths_set* {.bitsize: 1.}: cuint - private_ad_started* {.bitsize: 1.}: cuint - private_body_started* {.bitsize: 1.}: cuint - private_is_encrypt* {.bitsize: 1.}: cuint - private_ctx*: psa_driver_aead_context_t - - psa_key_derivation_s* {.bycopy, impcrypto_structHdr, - importc: "struct psa_key_derivation_s".} = object - private_alg*: psa_algorithm_t - private_can_output_key* {.bitsize: 1.}: cuint - private_capacity*: uint - private_ctx*: psa_driver_key_derivation_context_t - - psa_key_policy_s* {.bycopy, impcrypto_structHdr, - importc: "struct psa_key_policy_s".} = object - private_usage*: psa_key_usage_t - private_alg*: psa_algorithm_t - private_alg2*: psa_algorithm_t - - psa_key_policy_t* {.importc, impcrypto_structHdr.} = psa_key_policy_s - psa_key_bits_t* {.importc, impcrypto_structHdr.} = uint16 - psa_key_attributes_flag_t* {.importc, impcrypto_structHdr.} = uint16 - psa_core_key_attributes_t* {.bycopy, importc, impcrypto_structHdr.} = object - private_type*: psa_key_type_t - private_bits*: psa_key_bits_t - private_lifetime*: psa_key_lifetime_t - private_id*: mbedtls_svc_key_id_t - private_policy*: psa_key_policy_t - private_flags*: psa_key_attributes_flag_t - - psa_key_attributes_s* {.bycopy, impcrypto_structHdr, - importc: "struct psa_key_attributes_s".} = object - private_core*: psa_core_key_attributes_t - private_domain_parameters*: pointer - private_domain_parameters_size*: uint - - psa_sign_hash_interruptible_operation_s* {.bycopy, impcrypto_structHdr, - importc: "struct psa_sign_hash_interruptible_operation_s".} = object - private_id*: cuint - private_ctx*: psa_driver_sign_hash_interruptible_context_t - private_error_occurred* {.bitsize: 1.}: cuint - private_num_ops*: uint32 - - psa_verify_hash_interruptible_operation_s* {.bycopy, impcrypto_structHdr, - importc: "struct psa_verify_hash_interruptible_operation_s".} = object - private_id*: cuint - private_ctx*: psa_driver_verify_hash_interruptible_context_t - private_error_occurred* {.bitsize: 1.}: cuint - private_num_ops*: uint32 - - psa_status_t* {.importc, impcrypto_typesHdr.} = int32 - psa_key_type_t* {.importc, impcrypto_typesHdr.} = uint16 - psa_ecc_family_t* {.importc, impcrypto_typesHdr.} = uint8 - psa_dh_family_t* {.importc, impcrypto_typesHdr.} = uint8 - psa_algorithm_t* {.importc, impcrypto_typesHdr.} = uint32 - psa_key_lifetime_t* {.importc, impcrypto_typesHdr.} = uint32 - psa_key_persistence_t* {.importc, impcrypto_typesHdr.} = uint8 - psa_key_location_t* {.importc, impcrypto_typesHdr.} = uint32 - psa_key_id_t* {.importc, impcrypto_typesHdr.} = uint32 - mbedtls_svc_key_id_t* {.importc, impcrypto_typesHdr.} = psa_key_id_t - psa_key_usage_t* {.importc, impcrypto_typesHdr.} = uint32 - psa_key_attributes_t* {.importc, impcrypto_typesHdr.} = psa_key_attributes_s - psa_key_derivation_step_t* {.importc, impcrypto_typesHdr.} = uint16 -{.pop.} diff --git a/webrtc/mbedtls/psa/crypto_values.nim b/webrtc/mbedtls/psa/crypto_values.nim deleted file mode 100644 index 1718ee5..0000000 --- a/webrtc/mbedtls/psa/crypto_values.nim +++ /dev/null @@ -1,199 +0,0 @@ -import "crypto_types" - -# const 'PSA_ERROR_GENERIC_ERROR' has unsupported value '((psa_status_t)-132)' -# const 'PSA_ERROR_NOT_SUPPORTED' has unsupported value '((psa_status_t)-134)' -# const 'PSA_ERROR_NOT_PERMITTED' has unsupported value '((psa_status_t)-133)' -# const 'PSA_ERROR_BUFFER_TOO_SMALL' has unsupported value '((psa_status_t)-138)' -# const 'PSA_ERROR_ALREADY_EXISTS' has unsupported value '((psa_status_t)-139)' -# const 'PSA_ERROR_DOES_NOT_EXIST' has unsupported value '((psa_status_t)-140)' -# const 'PSA_ERROR_BAD_STATE' has unsupported value '((psa_status_t)-137)' -# const 'PSA_ERROR_INVALID_ARGUMENT' has unsupported value '((psa_status_t)-135)' -# const 'PSA_ERROR_INSUFFICIENT_MEMORY' has unsupported value '((psa_status_t)-141)' -# const 'PSA_ERROR_INSUFFICIENT_STORAGE' has unsupported value '((psa_status_t)-142)' -# const 'PSA_ERROR_COMMUNICATION_FAILURE' has unsupported value '((psa_status_t)-145)' -# const 'PSA_ERROR_STORAGE_FAILURE' has unsupported value '((psa_status_t)-146)' -# const 'PSA_ERROR_HARDWARE_FAILURE' has unsupported value '((psa_status_t)-147)' -# const 'PSA_ERROR_CORRUPTION_DETECTED' has unsupported value '((psa_status_t)-151)' -# const 'PSA_ERROR_INSUFFICIENT_ENTROPY' has unsupported value '((psa_status_t)-148)' -# const 'PSA_ERROR_INVALID_SIGNATURE' has unsupported value '((psa_status_t)-149)' -# const 'PSA_ERROR_INVALID_PADDING' has unsupported value '((psa_status_t)-150)' -# const 'PSA_ERROR_INSUFFICIENT_DATA' has unsupported value '((psa_status_t)-143)' -# const 'PSA_ERROR_INVALID_HANDLE' has unsupported value '((psa_status_t)-136)' -# const 'PSA_ERROR_DATA_CORRUPT' has unsupported value '((psa_status_t)-152)' -# const 'PSA_ERROR_DATA_INVALID' has unsupported value '((psa_status_t)-153)' -# const 'PSA_OPERATION_INCOMPLETE' has unsupported value '((psa_status_t)-248)' -# const 'PSA_ALG_RSA_PKCS1V15_SIGN_RAW' has unsupported value 'PSA_ALG_RSA_PKCS1V15_SIGN_BASE' -# const 'PSA_ALG_ECDSA_ANY' has unsupported value 'PSA_ALG_ECDSA_BASE' -# const 'PSA_INTERRUPTIBLE_MAX_OPS_UNLIMITED' has unsupported value 'UINT32_MAX' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.pragma: impcrypto_valuesHdr, - header: "/home/lchenut/minnim/webrtc/mbedtls/include/psa/crypto_values.h".} -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - PSA_SUCCESS* = (cast[psa_status_t](0)) - PSA_KEY_TYPE_NONE* = (cast[psa_key_type_t](0x00000000)) - PSA_KEY_TYPE_VENDOR_FLAG* = (cast[psa_key_type_t](0x00008000)) - PSA_KEY_TYPE_CATEGORY_MASK* = (cast[psa_key_type_t](0x00007000)) - PSA_KEY_TYPE_CATEGORY_RAW* = (cast[psa_key_type_t](0x00001000)) - PSA_KEY_TYPE_CATEGORY_SYMMETRIC* = (cast[psa_key_type_t](0x00002000)) - PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY* = (cast[psa_key_type_t](0x00004000)) - PSA_KEY_TYPE_CATEGORY_KEY_PAIR* = (cast[psa_key_type_t](0x00007000)) - PSA_KEY_TYPE_CATEGORY_FLAG_PAIR* = (cast[psa_key_type_t](0x00003000)) - PSA_KEY_TYPE_RAW_DATA* = (cast[psa_key_type_t](0x00001001)) - PSA_KEY_TYPE_HMAC* = (cast[psa_key_type_t](0x00001100)) - PSA_KEY_TYPE_DERIVE* = (cast[psa_key_type_t](0x00001200)) - PSA_KEY_TYPE_PASSWORD* = (cast[psa_key_type_t](0x00001203)) - PSA_KEY_TYPE_PASSWORD_HASH* = (cast[psa_key_type_t](0x00001205)) - PSA_KEY_TYPE_PEPPER* = (cast[psa_key_type_t](0x00001206)) - PSA_KEY_TYPE_AES* = (cast[psa_key_type_t](0x00002400)) - PSA_KEY_TYPE_ARIA* = (cast[psa_key_type_t](0x00002406)) - PSA_KEY_TYPE_DES* = (cast[psa_key_type_t](0x00002301)) - PSA_KEY_TYPE_CAMELLIA* = (cast[psa_key_type_t](0x00002403)) - PSA_KEY_TYPE_CHACHA20* = (cast[psa_key_type_t](0x00002004)) - PSA_KEY_TYPE_RSA_PUBLIC_KEY* = (cast[psa_key_type_t](0x00004001)) - PSA_KEY_TYPE_RSA_KEY_PAIR* = (cast[psa_key_type_t](0x00007001)) - PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE* = (cast[psa_key_type_t](0x00004100)) - PSA_KEY_TYPE_ECC_KEY_PAIR_BASE* = (cast[psa_key_type_t](0x00007100)) - PSA_KEY_TYPE_ECC_CURVE_MASK* = (cast[psa_key_type_t](0x000000FF)) - PSA_ECC_FAMILY_SECP_K1* = (cast[psa_ecc_family_t](0x00000017)) - PSA_ECC_FAMILY_SECP_R1* = (cast[psa_ecc_family_t](0x00000012)) - PSA_ECC_FAMILY_SECP_R2* = (cast[psa_ecc_family_t](0x0000001B)) - PSA_ECC_FAMILY_SECT_K1* = (cast[psa_ecc_family_t](0x00000027)) - PSA_ECC_FAMILY_SECT_R1* = (cast[psa_ecc_family_t](0x00000022)) - PSA_ECC_FAMILY_SECT_R2* = (cast[psa_ecc_family_t](0x0000002B)) - PSA_ECC_FAMILY_BRAINPOOL_P_R1* = (cast[psa_ecc_family_t](0x00000030)) - PSA_ECC_FAMILY_MONTGOMERY* = (cast[psa_ecc_family_t](0x00000041)) - PSA_ECC_FAMILY_TWISTED_EDWARDS* = (cast[psa_ecc_family_t](0x00000042)) - PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE* = (cast[psa_key_type_t](0x00004200)) - PSA_KEY_TYPE_DH_KEY_PAIR_BASE* = (cast[psa_key_type_t](0x00007200)) - PSA_KEY_TYPE_DH_GROUP_MASK* = (cast[psa_key_type_t](0x000000FF)) - PSA_DH_FAMILY_RFC7919* = (cast[psa_dh_family_t](0x00000003)) - PSA_ALG_VENDOR_FLAG* = (cast[psa_algorithm_t](0x80000000)) - PSA_ALG_CATEGORY_MASK* = (cast[psa_algorithm_t](0x7F000000)) - PSA_ALG_CATEGORY_HASH* = (cast[psa_algorithm_t](0x02000000)) - PSA_ALG_CATEGORY_MAC* = (cast[psa_algorithm_t](0x03000000)) - PSA_ALG_CATEGORY_CIPHER* = (cast[psa_algorithm_t](0x04000000)) - PSA_ALG_CATEGORY_AEAD* = (cast[psa_algorithm_t](0x05000000)) - PSA_ALG_CATEGORY_SIGN* = (cast[psa_algorithm_t](0x06000000)) - PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION* = (cast[psa_algorithm_t](0x07000000)) - PSA_ALG_CATEGORY_KEY_DERIVATION* = (cast[psa_algorithm_t](0x08000000)) - PSA_ALG_CATEGORY_KEY_AGREEMENT* = (cast[psa_algorithm_t](0x09000000)) - PSA_ALG_NONE* = (cast[psa_algorithm_t](0)) - PSA_ALG_HASH_MASK* = (cast[psa_algorithm_t](0x000000FF)) - PSA_ALG_MD5* = (cast[psa_algorithm_t](0x02000003)) - PSA_ALG_RIPEMD160* = (cast[psa_algorithm_t](0x02000004)) - PSA_ALG_SHA_1* = (cast[psa_algorithm_t](0x02000005)) - PSA_ALG_SHA_224* = (cast[psa_algorithm_t](0x02000008)) - PSA_ALG_SHA_256* = (cast[psa_algorithm_t](0x02000009)) - PSA_ALG_SHA_384* = (cast[psa_algorithm_t](0x0200000A)) - PSA_ALG_SHA_512* = (cast[psa_algorithm_t](0x0200000B)) - PSA_ALG_SHA_512_224* = (cast[psa_algorithm_t](0x0200000C)) - PSA_ALG_SHA_512_256* = (cast[psa_algorithm_t](0x0200000D)) - PSA_ALG_SHA3_224* = (cast[psa_algorithm_t](0x02000010)) - PSA_ALG_SHA3_256* = (cast[psa_algorithm_t](0x02000011)) - PSA_ALG_SHA3_384* = (cast[psa_algorithm_t](0x02000012)) - PSA_ALG_SHA3_512* = (cast[psa_algorithm_t](0x02000013)) - PSA_ALG_SHAKE256_512* = (cast[psa_algorithm_t](0x02000015)) - PSA_ALG_ANY_HASH* = (cast[psa_algorithm_t](0x020000FF)) - PSA_ALG_MAC_SUBCATEGORY_MASK* = (cast[psa_algorithm_t](0x00C00000)) - PSA_ALG_HMAC_BASE* = (cast[psa_algorithm_t](0x03800000)) - PSA_ALG_MAC_TRUNCATION_MASK* = (cast[psa_algorithm_t](0x003F0000)) - PSA_MAC_TRUNCATION_OFFSET* = 16 - PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG* = (cast[psa_algorithm_t](0x00008000)) - PSA_ALG_CIPHER_MAC_BASE* = (cast[psa_algorithm_t](0x03C00000)) - PSA_ALG_CBC_MAC* = (cast[psa_algorithm_t](0x03C00100)) - PSA_ALG_CMAC* = (cast[psa_algorithm_t](0x03C00200)) - PSA_ALG_CIPHER_STREAM_FLAG* = (cast[psa_algorithm_t](0x00800000)) - PSA_ALG_CIPHER_FROM_BLOCK_FLAG* = (cast[psa_algorithm_t](0x00400000)) - PSA_ALG_STREAM_CIPHER* = (cast[psa_algorithm_t](0x04800100)) - PSA_ALG_CTR* = (cast[psa_algorithm_t](0x04C01000)) - PSA_ALG_CFB* = (cast[psa_algorithm_t](0x04C01100)) - PSA_ALG_OFB* = (cast[psa_algorithm_t](0x04C01200)) - PSA_ALG_XTS* = (cast[psa_algorithm_t](0x0440FF00)) - PSA_ALG_ECB_NO_PADDING* = (cast[psa_algorithm_t](0x04404400)) - PSA_ALG_CBC_NO_PADDING* = (cast[psa_algorithm_t](0x04404000)) - PSA_ALG_CBC_PKCS7* = (cast[psa_algorithm_t](0x04404100)) - PSA_ALG_AEAD_FROM_BLOCK_FLAG* = (cast[psa_algorithm_t](0x00400000)) - PSA_ALG_CCM* = (cast[psa_algorithm_t](0x05500100)) - PSA_ALG_CCM_STAR_NO_TAG* = (cast[psa_algorithm_t](0x04C01300)) - PSA_ALG_GCM* = (cast[psa_algorithm_t](0x05500200)) - PSA_ALG_CHACHA20_POLY1305* = (cast[psa_algorithm_t](0x05100500)) - PSA_ALG_AEAD_TAG_LENGTH_MASK* = (cast[psa_algorithm_t](0x003F0000)) - PSA_AEAD_TAG_LENGTH_OFFSET* = 16 - PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG* = (cast[psa_algorithm_t](0x00008000)) - PSA_ALG_RSA_PKCS1V15_SIGN_BASE* = (cast[psa_algorithm_t](0x06000200)) - PSA_ALG_RSA_PSS_BASE* = (cast[psa_algorithm_t](0x06000300)) - PSA_ALG_RSA_PSS_ANY_SALT_BASE* = (cast[psa_algorithm_t](0x06001300)) - PSA_ALG_ECDSA_BASE* = (cast[psa_algorithm_t](0x06000600)) - PSA_ALG_DETERMINISTIC_ECDSA_BASE* = (cast[psa_algorithm_t](0x06000700)) - PSA_ALG_ECDSA_DETERMINISTIC_FLAG* = (cast[psa_algorithm_t](0x00000100)) - PSA_ALG_PURE_EDDSA* = (cast[psa_algorithm_t](0x06000800)) - PSA_ALG_HASH_EDDSA_BASE* = (cast[psa_algorithm_t](0x06000900)) - PSA_ALG_ED25519PH* = (PSA_ALG_HASH_EDDSA_BASE or - typeof(PSA_ALG_HASH_EDDSA_BASE)((PSA_ALG_SHA_512 and - typeof(PSA_ALG_HASH_EDDSA_BASE)(PSA_ALG_HASH_MASK)))) - PSA_ALG_ED448PH* = (PSA_ALG_HASH_EDDSA_BASE or - typeof(PSA_ALG_HASH_EDDSA_BASE)((PSA_ALG_SHAKE256_512 and - typeof(PSA_ALG_HASH_EDDSA_BASE)(PSA_ALG_HASH_MASK)))) - PSA_ALG_RSA_PKCS1V15_CRYPT* = (cast[psa_algorithm_t](0x07000200)) - PSA_ALG_RSA_OAEP_BASE* = (cast[psa_algorithm_t](0x07000300)) - PSA_ALG_HKDF_BASE* = (cast[psa_algorithm_t](0x08000100)) - PSA_ALG_HKDF_EXTRACT_BASE* = (cast[psa_algorithm_t](0x08000400)) - PSA_ALG_HKDF_EXPAND_BASE* = (cast[psa_algorithm_t](0x08000500)) - PSA_ALG_TLS12_PRF_BASE* = (cast[psa_algorithm_t](0x08000200)) - PSA_ALG_TLS12_PSK_TO_MS_BASE* = (cast[psa_algorithm_t](0x08000300)) - PSA_ALG_TLS12_ECJPAKE_TO_PMS* = (cast[psa_algorithm_t](0x08000609)) - PSA_ALG_KEY_DERIVATION_STRETCHING_FLAG* = (cast[psa_algorithm_t](0x00800000)) - PSA_ALG_PBKDF2_HMAC_BASE* = (cast[psa_algorithm_t](0x08800100)) - PSA_ALG_PBKDF2_AES_CMAC_PRF_128* = (cast[psa_algorithm_t](0x08800200)) - PSA_ALG_KEY_DERIVATION_MASK* = (cast[psa_algorithm_t](0xFE00FFFF)) - PSA_ALG_KEY_AGREEMENT_MASK* = (cast[psa_algorithm_t](0xFFFF0000)) - PSA_ALG_FFDH* = (cast[psa_algorithm_t](0x09010000)) - PSA_ALG_ECDH* = (cast[psa_algorithm_t](0x09020000)) - PSA_KEY_LIFETIME_VOLATILE* = (cast[psa_key_lifetime_t](0x00000000)) - PSA_KEY_LIFETIME_PERSISTENT* = (cast[psa_key_lifetime_t](0x00000001)) - PSA_KEY_PERSISTENCE_VOLATILE* = (cast[psa_key_persistence_t](0x00000000)) - PSA_KEY_PERSISTENCE_DEFAULT* = (cast[psa_key_persistence_t](0x00000001)) - PSA_KEY_PERSISTENCE_READ_ONLY* = (cast[psa_key_persistence_t](0x000000FF)) - PSA_KEY_LOCATION_LOCAL_STORAGE* = (cast[psa_key_location_t](0x00000000)) - PSA_KEY_LOCATION_VENDOR_FLAG* = (cast[psa_key_location_t](0x00800000)) - PSA_KEY_ID_NULL* = (cast[psa_key_id_t](0)) - PSA_KEY_ID_USER_MIN* = (cast[psa_key_id_t](0x00000001)) - PSA_KEY_ID_USER_MAX* = (cast[psa_key_id_t](0x3FFFFFFF)) - PSA_KEY_ID_VENDOR_MIN* = (cast[psa_key_id_t](0x40000000)) - PSA_KEY_ID_VENDOR_MAX* = (cast[psa_key_id_t](0x7FFFFFFF)) - MBEDTLS_SVC_KEY_ID_INIT* = (cast[psa_key_id_t](0)) - PSA_KEY_USAGE_EXPORT* = (cast[psa_key_usage_t](0x00000001)) - PSA_KEY_USAGE_COPY* = (cast[psa_key_usage_t](0x00000002)) - PSA_KEY_USAGE_ENCRYPT* = (cast[psa_key_usage_t](0x00000100)) - PSA_KEY_USAGE_DECRYPT* = (cast[psa_key_usage_t](0x00000200)) - PSA_KEY_USAGE_SIGN_MESSAGE* = (cast[psa_key_usage_t](0x00000400)) - PSA_KEY_USAGE_VERIFY_MESSAGE* = (cast[psa_key_usage_t](0x00000800)) - PSA_KEY_USAGE_SIGN_HASH* = (cast[psa_key_usage_t](0x00001000)) - PSA_KEY_USAGE_VERIFY_HASH* = (cast[psa_key_usage_t](0x00002000)) - PSA_KEY_USAGE_DERIVE* = (cast[psa_key_usage_t](0x00004000)) - PSA_KEY_USAGE_VERIFY_DERIVATION* = (cast[psa_key_usage_t](0x00008000)) - PSA_KEY_DERIVATION_INPUT_SECRET* = ( - cast[psa_key_derivation_step_t](0x00000101)) - PSA_KEY_DERIVATION_INPUT_PASSWORD* = ( - cast[psa_key_derivation_step_t](0x00000102)) - PSA_KEY_DERIVATION_INPUT_OTHER_SECRET* = ( - cast[psa_key_derivation_step_t](0x00000103)) - PSA_KEY_DERIVATION_INPUT_LABEL* = (cast[psa_key_derivation_step_t](0x00000201)) - PSA_KEY_DERIVATION_INPUT_SALT* = (cast[psa_key_derivation_step_t](0x00000202)) - PSA_KEY_DERIVATION_INPUT_INFO* = (cast[psa_key_derivation_step_t](0x00000203)) - PSA_KEY_DERIVATION_INPUT_SEED* = (cast[psa_key_derivation_step_t](0x00000204)) - PSA_KEY_DERIVATION_INPUT_COST* = (cast[psa_key_derivation_step_t](0x00000205)) -proc mbedtls_svc_key_id_make*(unused: cuint; key_id: psa_key_id_t): mbedtls_svc_key_id_t {. - importc, cdecl, impcrypto_valuesHdr.} -proc mbedtls_svc_key_id_equal*(id1: mbedtls_svc_key_id_t; - id2: mbedtls_svc_key_id_t): cint {.importc, - cdecl, impcrypto_valuesHdr.} -proc mbedtls_svc_key_id_is_null*(key: mbedtls_svc_key_id_t): cint {.importc, - cdecl, impcrypto_valuesHdr.} -{.pop.} diff --git a/webrtc/mbedtls/psa_util.nim b/webrtc/mbedtls/psa_util.nim deleted file mode 100644 index a0340ae..0000000 --- a/webrtc/mbedtls/psa_util.nim +++ /dev/null @@ -1,43 +0,0 @@ -import "ctr_drbg" -import "pkcs5" -import "pkcs12" -# TODO: Remove pkcs5 and pkcs12, they're not used in this file. -import "psa/crypto_types" -{.compile: "./mbedtls/library/psa_util.c".} - -# proc 'mbedtls_psa_translate_cipher_type' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_psa_translate_cipher_mode' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_psa_translate_cipher_operation' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_psa_translate_md' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_psa_get_ecc_oid_from_id' skipped - static inline procs cannot work with '--noHeader | -H' -# const 'MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH' has unsupported value 'PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)' -# const 'MBEDTLS_PSA_MAX_EC_KEY_PAIR_LENGTH' has unsupported value 'PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)' -# const 'MBEDTLS_PSA_RANDOM_STATE' has unsupported value 'mbedtls_psa_random_state' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -type - mbedtls_f_rng_t* = proc (p_rng: pointer; output: ptr byte; output_size: uint): cint {. - cdecl.} - mbedtls_psa_drbg_context_t* = mbedtls_ctr_drbg_context - mbedtls_error_pair_t* {.bycopy.} = object - psa_status*: psa_status_t - mbedtls_error*: int16 - -var - mbedtls_psa_get_random* {.importc.}: ptr mbedtls_f_rng_t - mbedtls_psa_random_state* {.importc.}: ptr mbedtls_psa_drbg_context_t - psa_to_lms_errors* {.importc.}: array[3, mbedtls_error_pair_t] - psa_to_pk_rsa_errors* {.importc.}: array[8, mbedtls_error_pair_t] -proc psa_generic_status_to_mbedtls*(status: psa_status_t): cint {.importc, cdecl.} -proc psa_status_to_mbedtls*(status: psa_status_t; - local_translations: ptr mbedtls_error_pair_t; - local_errors_num: uint; - fallback_f: proc (a1: psa_status_t): cint {.cdecl.}): cint {. - importc, cdecl.} -proc psa_pk_status_to_mbedtls*(status: psa_status_t): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/ripemd160.nim b/webrtc/mbedtls/ripemd160.nim deleted file mode 100644 index 85a0db8..0000000 --- a/webrtc/mbedtls/ripemd160.nim +++ /dev/null @@ -1,36 +0,0 @@ -import "platform_time" - -{.compile: "./mbedtls/library/ripemd160.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -type - mbedtls_ripemd160_context* {.bycopy.} = object - private_total*: array[2, uint32] - private_state*: array[5, uint32] - private_buffer*: array[64, byte] - -proc mbedtls_ripemd160_init*(ctx: ptr mbedtls_ripemd160_context) {.importc, - cdecl.} -proc mbedtls_ripemd160_free*(ctx: ptr mbedtls_ripemd160_context) {.importc, - cdecl.} -proc mbedtls_ripemd160_clone*(dst: ptr mbedtls_ripemd160_context; - src: ptr mbedtls_ripemd160_context) {.importc, - cdecl.} -proc mbedtls_ripemd160_starts*(ctx: ptr mbedtls_ripemd160_context): cint {. - importc, cdecl.} -proc mbedtls_ripemd160_update*(ctx: ptr mbedtls_ripemd160_context; - input: ptr byte; ilen: uint): cint {.importc, - cdecl.} -proc mbedtls_ripemd160_finish*(ctx: ptr mbedtls_ripemd160_context; - output: array[20, byte]): cint {.importc, cdecl.} -proc mbedtls_internal_ripemd160_process*(ctx: ptr mbedtls_ripemd160_context; - data: array[64, byte]): cint {.importc, cdecl.} -proc mbedtls_ripemd160*(input: ptr byte; ilen: uint; output: array[20, byte]): cint {. - importc, cdecl.} -proc mbedtls_ripemd160_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/rsa.nim b/webrtc/mbedtls/rsa.nim deleted file mode 100644 index 43c2c1a..0000000 --- a/webrtc/mbedtls/rsa.nim +++ /dev/null @@ -1,165 +0,0 @@ -import "hash_info" -import "bignum" -import "md" - -{.compile: "./mbedtls/library/oid.c"} -{.compile: "./mbedtls/library/rsa.c"} -{.compile: "./mbedtls/library/rsa_alt_helpers.c"} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_RSA_BAD_INPUT_DATA* = -0x00004080 - MBEDTLS_ERR_RSA_INVALID_PADDING* = -0x00004100 - MBEDTLS_ERR_RSA_KEY_GEN_FAILED* = -0x00004180 - MBEDTLS_ERR_RSA_KEY_CHECK_FAILED* = -0x00004200 - MBEDTLS_ERR_RSA_PUBLIC_FAILED* = -0x00004280 - MBEDTLS_ERR_RSA_PRIVATE_FAILED* = -0x00004300 - MBEDTLS_ERR_RSA_VERIFY_FAILED* = -0x00004380 - MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE* = -0x00004400 - MBEDTLS_ERR_RSA_RNG_FAILED* = -0x00004480 - MBEDTLS_RSA_PKCS_V15* = 0 - MBEDTLS_RSA_PKCS_V21* = 1 - MBEDTLS_RSA_SIGN* = 1 - MBEDTLS_RSA_CRYPT* = 2 - MBEDTLS_RSA_SALT_LEN_ANY* = -1 -type - mbedtls_rsa_context* {.bycopy.} = object - private_ver*: cint - private_len*: uint - private_N*: mbedtls_mpi - private_E*: mbedtls_mpi - private_D*: mbedtls_mpi - private_P*: mbedtls_mpi - private_Q*: mbedtls_mpi - private_DP*: mbedtls_mpi - private_DQ*: mbedtls_mpi - private_QP*: mbedtls_mpi - private_RN*: mbedtls_mpi - private_RP*: mbedtls_mpi - private_RQ*: mbedtls_mpi - private_Vi*: mbedtls_mpi - private_Vf*: mbedtls_mpi - private_padding*: cint - private_hash_id*: cint - -proc mbedtls_rsa_init*(ctx: ptr mbedtls_rsa_context) {.importc, cdecl.} -proc mbedtls_rsa_set_padding*(ctx: ptr mbedtls_rsa_context; padding: cint; - hash_id: mbedtls_md_type_t): cint {.importc, cdecl.} -proc mbedtls_rsa_get_padding_mode*(ctx: ptr mbedtls_rsa_context): cint {. - importc, cdecl.} -proc mbedtls_rsa_get_md_alg*(ctx: ptr mbedtls_rsa_context): cint {.importc, - cdecl.} -proc mbedtls_rsa_import*(ctx: ptr mbedtls_rsa_context; N: ptr mbedtls_mpi; - P: ptr mbedtls_mpi; Q: ptr mbedtls_mpi; - D: ptr mbedtls_mpi; E: ptr mbedtls_mpi): cint {. - importc, cdecl.} -proc mbedtls_rsa_import_raw*(ctx: ptr mbedtls_rsa_context; N: ptr byte; - N_len: uint; P: ptr byte; P_len: uint; - Q: ptr byte; Q_len: uint; D: ptr byte; - D_len: uint; E: ptr byte; E_len: uint): cint {. - importc, cdecl.} -proc mbedtls_rsa_complete*(ctx: ptr mbedtls_rsa_context): cint {.importc, cdecl.} -proc mbedtls_rsa_export*(ctx: ptr mbedtls_rsa_context; N: ptr mbedtls_mpi; - P: ptr mbedtls_mpi; Q: ptr mbedtls_mpi; - D: ptr mbedtls_mpi; E: ptr mbedtls_mpi): cint {. - importc, cdecl.} -proc mbedtls_rsa_export_raw*(ctx: ptr mbedtls_rsa_context; N: ptr byte; - N_len: uint; P: ptr byte; P_len: uint; - Q: ptr byte; Q_len: uint; D: ptr byte; - D_len: uint; E: ptr byte; E_len: uint): cint {. - importc, cdecl.} -proc mbedtls_rsa_export_crt*(ctx: ptr mbedtls_rsa_context; DP: ptr mbedtls_mpi; - DQ: ptr mbedtls_mpi; QP: ptr mbedtls_mpi): cint {. - importc, cdecl.} -proc mbedtls_rsa_get_len*(ctx: ptr mbedtls_rsa_context): uint {.importc, cdecl.} -proc mbedtls_rsa_gen_key*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; - nbits: cuint; exponent: cint): cint {.importc, cdecl.} -proc mbedtls_rsa_check_pubkey*(ctx: ptr mbedtls_rsa_context): cint {.importc, - cdecl.} -proc mbedtls_rsa_check_privkey*(ctx: ptr mbedtls_rsa_context): cint {.importc, - cdecl.} -proc mbedtls_rsa_check_pub_priv*(pub: ptr mbedtls_rsa_context; - prv: ptr mbedtls_rsa_context): cint {.importc, - cdecl.} -proc mbedtls_rsa_public*(ctx: ptr mbedtls_rsa_context; input: ptr byte; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_rsa_private*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; - input: ptr byte; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_rsa_pkcs1_encrypt*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; - ilen: uint; input: ptr byte; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_rsa_rsaes_pkcs1_v15_encrypt*(ctx: ptr mbedtls_rsa_context; - f_rng: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; - p_rng: pointer; ilen: uint; input: ptr byte; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_rsa_rsaes_oaep_encrypt*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; - label: ptr byte; label_len: uint; - ilen: uint; input: ptr byte; - output: ptr byte): cint {.importc, cdecl.} -proc mbedtls_rsa_pkcs1_decrypt*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; - olen: ptr uint; input: ptr byte; - output: ptr byte; output_max_len: uint): cint {. - importc, cdecl.} -proc mbedtls_rsa_rsaes_pkcs1_v15_decrypt*(ctx: ptr mbedtls_rsa_context; - f_rng: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; - p_rng: pointer; olen: ptr uint; input: ptr byte; output: ptr byte; - output_max_len: uint): cint {.importc, cdecl.} -proc mbedtls_rsa_rsaes_oaep_decrypt*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; - label: ptr byte; label_len: uint; - olen: ptr uint; input: ptr byte; - output: ptr byte; output_max_len: uint): cint {. - importc, cdecl.} -proc mbedtls_rsa_pkcs1_sign*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; - md_alg: mbedtls_md_type_t; hashlen: cuint; - hash: ptr byte; sig: ptr byte): cint {.importc, - cdecl.} -proc mbedtls_rsa_rsassa_pkcs1_v15_sign*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; - md_alg: mbedtls_md_type_t; - hashlen: cuint; hash: ptr byte; - sig: ptr byte): cint {.importc, cdecl.} -proc mbedtls_rsa_rsassa_pss_sign_ext*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; - md_alg: mbedtls_md_type_t; hashlen: cuint; - hash: ptr byte; saltlen: cint; - sig: ptr byte): cint {.importc, cdecl.} -proc mbedtls_rsa_rsassa_pss_sign*(ctx: ptr mbedtls_rsa_context; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; - md_alg: mbedtls_md_type_t; hashlen: cuint; - hash: ptr byte; sig: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_rsa_pkcs1_verify*(ctx: ptr mbedtls_rsa_context; - md_alg: mbedtls_md_type_t; hashlen: cuint; - hash: ptr byte; sig: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_rsa_rsassa_pkcs1_v15_verify*(ctx: ptr mbedtls_rsa_context; - md_alg: mbedtls_md_type_t; hashlen: cuint; hash: ptr byte; sig: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_rsa_rsassa_pss_verify*(ctx: ptr mbedtls_rsa_context; - md_alg: mbedtls_md_type_t; hashlen: cuint; - hash: ptr byte; sig: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_rsa_rsassa_pss_verify_ext*(ctx: ptr mbedtls_rsa_context; - md_alg: mbedtls_md_type_t; - hashlen: cuint; hash: ptr byte; - mgf1_hash_id: mbedtls_md_type_t; - expected_salt_len: cint; sig: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_rsa_copy*(dst: ptr mbedtls_rsa_context; - src: ptr mbedtls_rsa_context): cint {.importc, cdecl.} -proc mbedtls_rsa_free*(ctx: ptr mbedtls_rsa_context) {.importc, cdecl.} -proc mbedtls_rsa_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/sha1.nim b/webrtc/mbedtls/sha1.nim deleted file mode 100644 index 087d7fc..0000000 --- a/webrtc/mbedtls/sha1.nim +++ /dev/null @@ -1,34 +0,0 @@ -import "platform_time" - -{.compile: "./mbedtls/library/sha1.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_SHA1_BAD_INPUT_DATA* = -0x00000073 -type - mbedtls_sha1_context* {.bycopy.} = object - private_total*: array[2, uint32] - private_state*: array[5, uint32] - private_buffer*: array[64, byte] - -proc mbedtls_sha1_init*(ctx: ptr mbedtls_sha1_context) {.importc, cdecl.} -proc mbedtls_sha1_free*(ctx: ptr mbedtls_sha1_context) {.importc, cdecl.} -proc mbedtls_sha1_clone*(dst: ptr mbedtls_sha1_context; - src: ptr mbedtls_sha1_context) {.importc, cdecl.} -proc mbedtls_sha1_starts*(ctx: ptr mbedtls_sha1_context): cint {.importc, cdecl.} -proc mbedtls_sha1_update*(ctx: ptr mbedtls_sha1_context; input: ptr byte; - ilen: uint): cint {.importc, cdecl.} -proc mbedtls_sha1_finish*(ctx: ptr mbedtls_sha1_context; - output: array[20, byte]): cint {.importc, cdecl.} -proc mbedtls_internal_sha1_process*(ctx: ptr mbedtls_sha1_context; - data: array[64, byte]): cint {.importc, - cdecl.} -proc mbedtls_sha1*(input: ptr byte; ilen: uint; output: array[20, byte]): cint {. - importc, cdecl.} -proc mbedtls_sha1_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/sha256.nim b/webrtc/mbedtls/sha256.nim deleted file mode 100644 index 9f845c0..0000000 --- a/webrtc/mbedtls/sha256.nim +++ /dev/null @@ -1,37 +0,0 @@ -import "platform_time" - -{.compile: "./mbedtls/library/sha256.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_SHA256_BAD_INPUT_DATA* = -0x00000074 -type - mbedtls_sha256_context* {.bycopy.} = object - private_total*: array[2, uint32] - private_state*: array[8, uint32] - private_buffer*: array[64, byte] - private_is224*: cint - -proc mbedtls_sha256_init*(ctx: ptr mbedtls_sha256_context) {.importc, cdecl.} -proc mbedtls_sha256_free*(ctx: ptr mbedtls_sha256_context) {.importc, cdecl.} -proc mbedtls_sha256_clone*(dst: ptr mbedtls_sha256_context; - src: ptr mbedtls_sha256_context) {.importc, cdecl.} -proc mbedtls_sha256_starts*(ctx: ptr mbedtls_sha256_context; is224: cint): cint {. - importc, cdecl.} -proc mbedtls_sha256_update*(ctx: ptr mbedtls_sha256_context; input: ptr byte; - ilen: uint): cint {.importc, cdecl.} -proc mbedtls_sha256_finish*(ctx: ptr mbedtls_sha256_context; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_internal_sha256_process*(ctx: ptr mbedtls_sha256_context; - data: array[64, byte]): cint {.importc, - cdecl.} -proc mbedtls_sha256*(input: ptr byte; ilen: uint; output: ptr byte; - is224: cint): cint {.importc, cdecl.} -proc mbedtls_sha224_self_test*(verbose: cint): cint {.importc, cdecl.} -proc mbedtls_sha256_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/sha512.nim b/webrtc/mbedtls/sha512.nim deleted file mode 100644 index b675262..0000000 --- a/webrtc/mbedtls/sha512.nim +++ /dev/null @@ -1,37 +0,0 @@ -import "platform_time" - -{.compile: "./mbedtls/library/sha512.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_SHA512_BAD_INPUT_DATA* = -0x00000075 -type - mbedtls_sha512_context* {.bycopy.} = object - private_total*: array[2, uint64] - private_state*: array[8, uint64] - private_buffer*: array[128, byte] - private_is384*: cint - -proc mbedtls_sha512_init*(ctx: ptr mbedtls_sha512_context) {.importc, cdecl.} -proc mbedtls_sha512_free*(ctx: ptr mbedtls_sha512_context) {.importc, cdecl.} -proc mbedtls_sha512_clone*(dst: ptr mbedtls_sha512_context; - src: ptr mbedtls_sha512_context) {.importc, cdecl.} -proc mbedtls_sha512_starts*(ctx: ptr mbedtls_sha512_context; is384: cint): cint {. - importc, cdecl.} -proc mbedtls_sha512_update*(ctx: ptr mbedtls_sha512_context; input: ptr byte; - ilen: uint): cint {.importc, cdecl.} -proc mbedtls_sha512_finish*(ctx: ptr mbedtls_sha512_context; output: ptr byte): cint {. - importc, cdecl.} -proc mbedtls_internal_sha512_process*(ctx: ptr mbedtls_sha512_context; - data: array[128, byte]): cint {.importc, - cdecl.} -proc mbedtls_sha512*(input: ptr byte; ilen: uint; output: ptr byte; - is384: cint): cint {.importc, cdecl.} -proc mbedtls_sha384_self_test*(verbose: cint): cint {.importc, cdecl.} -proc mbedtls_sha512_self_test*(verbose: cint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/ssl.nim b/webrtc/mbedtls/ssl.nim deleted file mode 100644 index 4f7049e..0000000 --- a/webrtc/mbedtls/ssl.nim +++ /dev/null @@ -1,821 +0,0 @@ -import "ssl_ciphersuites" -import "platform_time" -import "bignum" -import "ecp" -import "pk" -import "x509_crt" -import "x509_crl" -import "dhm" -import "utils" - -{.compile: "./mbedtls/library/debug.c".} -{.compile: "./mbedtls/library/ssl_debug_helpers_generated.c".} -{.compile: "./mbedtls/library/ssl_msg.c".} -{.compile: "./mbedtls/library/ssl_tls12_server.c".} -{.compile: "./mbedtls/library/ssl_tls.c".} -{.compile: "./mbedtls/library/ssl_client.c".} -{.compile: "./mbedtls/library/ssl_tls12_client.c".} - -# const 'MBEDTLS_PREMASTER_SIZE' has unsupported value 'sizeof(union mbedtls_ssl_premaster_secret)' -# const 'MBEDTLS_TLS1_3_MD_MAX_SIZE' has unsupported value 'PSA_HASH_MAX_SIZE' -# proc 'mbedtls_ssl_context_get_config' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_conf_cert_cb' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_conf_set_user_data_p' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_conf_set_user_data_n' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_conf_get_user_data_p' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_conf_get_user_data_n' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_set_user_data_p' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_set_user_data_n' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_get_user_data_p' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_get_user_data_n' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_conf_dn_hints' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_conf_max_tls_version' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_conf_min_tls_version' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_get_version_number' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_is_handshake_over' skipped - static inline procs cannot work with '--noHeader | -H' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(mbedtls_ssl_states) -defineEnum(mbedtls_ssl_protocol_version) -defineEnum(mbedtls_tls_prf_types) -defineEnum(mbedtls_ssl_key_export_type) - -const - MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS* = -0x00007000 - MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE* = -0x00007080 - MBEDTLS_ERR_SSL_BAD_INPUT_DATA* = -0x00007100 - MBEDTLS_ERR_SSL_INVALID_MAC* = -0x00007180 - MBEDTLS_ERR_SSL_INVALID_RECORD* = -0x00007200 - MBEDTLS_ERR_SSL_CONN_EOF* = -0x00007280 - MBEDTLS_ERR_SSL_DECODE_ERROR* = -0x00007300 - MBEDTLS_ERR_SSL_NO_RNG* = -0x00007400 - MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE* = -0x00007480 - MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION* = -0x00007500 - MBEDTLS_ERR_SSL_NO_APPLICATION_PROTOCOL* = -0x00007580 - MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED* = -0x00007600 - MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED* = -0x00007680 - MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE* = -0x00007700 - MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE* = -0x00007780 - MBEDTLS_ERR_SSL_UNRECOGNIZED_NAME* = -0x00007800 - MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY* = -0x00007880 - MBEDTLS_ERR_SSL_BAD_CERTIFICATE* = -0x00007A00 - MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET* = -0x00007B00 - MBEDTLS_ERR_SSL_CANNOT_READ_EARLY_DATA* = -0x00007B80 - MBEDTLS_ERR_SSL_CANNOT_WRITE_EARLY_DATA* = -0x00007C00 - MBEDTLS_ERR_SSL_CACHE_ENTRY_NOT_FOUND* = -0x00007E80 - MBEDTLS_ERR_SSL_ALLOC_FAILED* = -0x00007F00 - MBEDTLS_ERR_SSL_HW_ACCEL_FAILED* = -0x00007F80 - MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH* = -0x00006F80 - MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION* = -0x00006E80 - MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE* = -0x00006E00 - MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED* = -0x00006D80 - MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH* = -0x00006D00 - MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY* = -0x00006C80 - MBEDTLS_ERR_SSL_INTERNAL_ERROR* = -0x00006C00 - MBEDTLS_ERR_SSL_COUNTER_WRAPPING* = -0x00006B80 - MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO* = -0x00006B00 - MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED* = -0x00006A80 - MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL* = -0x00006A00 - MBEDTLS_ERR_SSL_WANT_READ* = -0x00006900 - MBEDTLS_ERR_SSL_WANT_WRITE* = -0x00006880 - MBEDTLS_ERR_SSL_TIMEOUT* = -0x00006800 - MBEDTLS_ERR_SSL_CLIENT_RECONNECT* = -0x00006780 - MBEDTLS_ERR_SSL_UNEXPECTED_RECORD* = -0x00006700 - MBEDTLS_ERR_SSL_NON_FATAL* = -0x00006680 - MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER* = -0x00006600 - MBEDTLS_ERR_SSL_CONTINUE_PROCESSING* = -0x00006580 - MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS* = -0x00006500 - MBEDTLS_ERR_SSL_EARLY_MESSAGE* = -0x00006480 - MBEDTLS_ERR_SSL_UNEXPECTED_CID* = -0x00006000 - MBEDTLS_ERR_SSL_VERSION_MISMATCH* = -0x00005F00 - MBEDTLS_ERR_SSL_BAD_CONFIG* = -0x00005E80 - MBEDTLS_SSL_TLS1_3_PSK_MODE_PURE* = 0 - MBEDTLS_SSL_TLS1_3_PSK_MODE_ECDHE* = 1 - MBEDTLS_SSL_IANA_TLS_GROUP_NONE* = 0 - MBEDTLS_SSL_IANA_TLS_GROUP_SECP192K1* = 0x00000012 - MBEDTLS_SSL_IANA_TLS_GROUP_SECP192R1* = 0x00000013 - MBEDTLS_SSL_IANA_TLS_GROUP_SECP224K1* = 0x00000014 - MBEDTLS_SSL_IANA_TLS_GROUP_SECP224R1* = 0x00000015 - MBEDTLS_SSL_IANA_TLS_GROUP_SECP256K1* = 0x00000016 - MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1* = 0x00000017 - MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1* = 0x00000018 - MBEDTLS_SSL_IANA_TLS_GROUP_SECP521R1* = 0x00000019 - MBEDTLS_SSL_IANA_TLS_GROUP_BP256R1* = 0x0000001A - MBEDTLS_SSL_IANA_TLS_GROUP_BP384R1* = 0x0000001B - MBEDTLS_SSL_IANA_TLS_GROUP_BP512R1* = 0x0000001C - MBEDTLS_SSL_IANA_TLS_GROUP_X25519* = 0x0000001D - MBEDTLS_SSL_IANA_TLS_GROUP_X448* = 0x0000001E - MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE2048* = 0x00000100 - MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE3072* = 0x00000101 - MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE4096* = 0x00000102 - MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE6144* = 0x00000103 - MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE8192* = 0x00000104 - MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK* = (1'u shl typeof(1'u)(0)) - MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL* = (1'u shl typeof(1'u)(1)) - MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL* = (1'u shl typeof(1'u)(2)) - MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_ALL* = (MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK or - typeof(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK)( - MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL) or - typeof(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK)( - MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL)) - MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ALL* = (MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK or - typeof(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK)( - MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL)) - MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ALL* = (MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL or - typeof(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL)( - MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL)) - MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_NONE* = (0) - MBEDTLS_SSL_MAJOR_VERSION_3* = 3 - MBEDTLS_SSL_MINOR_VERSION_3* = 3 - MBEDTLS_SSL_MINOR_VERSION_4* = 4 - MBEDTLS_SSL_TRANSPORT_STREAM* = 0 - MBEDTLS_SSL_TRANSPORT_DATAGRAM* = 1 - MBEDTLS_SSL_MAX_HOST_NAME_LEN* = 255 - MBEDTLS_SSL_MAX_ALPN_NAME_LEN* = 255 - MBEDTLS_SSL_MAX_ALPN_LIST_LEN* = 65535 - MBEDTLS_SSL_MAX_FRAG_LEN_NONE* = 0 - MBEDTLS_SSL_MAX_FRAG_LEN_512* = 1 - MBEDTLS_SSL_MAX_FRAG_LEN_1024* = 2 - MBEDTLS_SSL_MAX_FRAG_LEN_2048* = 3 - MBEDTLS_SSL_MAX_FRAG_LEN_4096* = 4 - MBEDTLS_SSL_MAX_FRAG_LEN_INVALID* = 5 - MBEDTLS_SSL_IS_CLIENT* = 0 - MBEDTLS_SSL_IS_SERVER* = 1 - MBEDTLS_SSL_EXTENDED_MS_DISABLED* = 0 - MBEDTLS_SSL_EXTENDED_MS_ENABLED* = 1 - MBEDTLS_SSL_CID_DISABLED* = 0 - MBEDTLS_SSL_CID_ENABLED* = 1 - MBEDTLS_SSL_ETM_DISABLED* = 0 - MBEDTLS_SSL_ETM_ENABLED* = 1 - MBEDTLS_SSL_COMPRESS_NULL* = 0 - MBEDTLS_SSL_VERIFY_NONE* = 0 - MBEDTLS_SSL_VERIFY_OPTIONAL* = 1 - MBEDTLS_SSL_VERIFY_REQUIRED* = 2 - MBEDTLS_SSL_VERIFY_UNSET* = 3 - MBEDTLS_SSL_LEGACY_RENEGOTIATION* = 0 - MBEDTLS_SSL_SECURE_RENEGOTIATION* = 1 - MBEDTLS_SSL_RENEGOTIATION_DISABLED* = 0 - MBEDTLS_SSL_RENEGOTIATION_ENABLED* = 1 - MBEDTLS_SSL_ANTI_REPLAY_DISABLED* = 0 - MBEDTLS_SSL_ANTI_REPLAY_ENABLED* = 1 - MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED* = -1 - MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT* = 16 - MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION* = 0 - MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION* = 1 - MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE* = 2 - MBEDTLS_SSL_TRUNC_HMAC_DISABLED* = 0 - MBEDTLS_SSL_TRUNC_HMAC_ENABLED* = 1 - MBEDTLS_SSL_TRUNCATED_HMAC_LEN* = 10 - MBEDTLS_SSL_SESSION_TICKETS_DISABLED* = 0 - MBEDTLS_SSL_SESSION_TICKETS_ENABLED* = 1 - MBEDTLS_SSL_PRESET_DEFAULT* = 0 - MBEDTLS_SSL_PRESET_SUITEB* = 2 - MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED* = 1 - MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED* = 0 - MBEDTLS_SSL_EARLY_DATA_DISABLED* = 0 - MBEDTLS_SSL_EARLY_DATA_ENABLED* = 1 - MBEDTLS_SSL_DTLS_SRTP_MKI_UNSUPPORTED* = 0 - MBEDTLS_SSL_DTLS_SRTP_MKI_SUPPORTED* = 1 - MBEDTLS_SSL_SRV_CIPHERSUITE_ORDER_CLIENT* = 1 - MBEDTLS_SSL_SRV_CIPHERSUITE_ORDER_SERVER* = 0 - MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN* = 1000 - MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX* = 60000 - MBEDTLS_SSL_IN_CONTENT_LEN* = 16384 - MBEDTLS_SSL_OUT_CONTENT_LEN* = 16384 - MBEDTLS_SSL_DTLS_MAX_BUFFERING* = 32768 - MBEDTLS_SSL_CID_IN_LEN_MAX* = 32 - MBEDTLS_SSL_CID_OUT_LEN_MAX* = 32 - MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY* = 16 - MBEDTLS_SSL_VERIFY_DATA_MAX_LEN* = 12 - MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO* = 0x000000FF - MBEDTLS_SSL_HASH_NONE* = 0 - MBEDTLS_SSL_HASH_MD5* = 1 - MBEDTLS_SSL_HASH_SHA1* = 2 - MBEDTLS_SSL_HASH_SHA224* = 3 - MBEDTLS_SSL_HASH_SHA256* = 4 - MBEDTLS_SSL_HASH_SHA384* = 5 - MBEDTLS_SSL_HASH_SHA512* = 6 - MBEDTLS_SSL_SIG_ANON* = 0 - MBEDTLS_SSL_SIG_RSA* = 1 - MBEDTLS_SSL_SIG_ECDSA* = 3 - MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA256* = 0x00000401 - MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA384* = 0x00000501 - MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA512* = 0x00000601 - MBEDTLS_TLS1_3_SIG_ECDSA_SECP256R1_SHA256* = 0x00000403 - MBEDTLS_TLS1_3_SIG_ECDSA_SECP384R1_SHA384* = 0x00000503 - MBEDTLS_TLS1_3_SIG_ECDSA_SECP521R1_SHA512* = 0x00000603 - MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA256* = 0x00000804 - MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA384* = 0x00000805 - MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA512* = 0x00000806 - MBEDTLS_TLS1_3_SIG_ED25519* = 0x00000807 - MBEDTLS_TLS1_3_SIG_ED448* = 0x00000808 - MBEDTLS_TLS1_3_SIG_RSA_PSS_PSS_SHA256* = 0x00000809 - MBEDTLS_TLS1_3_SIG_RSA_PSS_PSS_SHA384* = 0x0000080A - MBEDTLS_TLS1_3_SIG_RSA_PSS_PSS_SHA512* = 0x0000080B - MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA1* = 0x00000201 - MBEDTLS_TLS1_3_SIG_ECDSA_SHA1* = 0x00000203 - MBEDTLS_TLS1_3_SIG_NONE* = 0x00000000 - MBEDTLS_SSL_CERT_TYPE_RSA_SIGN* = 1 - MBEDTLS_SSL_CERT_TYPE_ECDSA_SIGN* = 64 - MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC* = 20 - MBEDTLS_SSL_MSG_ALERT* = 21 - MBEDTLS_SSL_MSG_HANDSHAKE* = 22 - MBEDTLS_SSL_MSG_APPLICATION_DATA* = 23 - MBEDTLS_SSL_MSG_CID* = 25 - MBEDTLS_SSL_ALERT_LEVEL_WARNING* = 1 - MBEDTLS_SSL_ALERT_LEVEL_FATAL* = 2 - MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY* = 0 - MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE* = 10 - MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC* = 20 - MBEDTLS_SSL_ALERT_MSG_DECRYPTION_FAILED* = 21 - MBEDTLS_SSL_ALERT_MSG_RECORD_OVERFLOW* = 22 - MBEDTLS_SSL_ALERT_MSG_DECOMPRESSION_FAILURE* = 30 - MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE* = 40 - MBEDTLS_SSL_ALERT_MSG_NO_CERT* = 41 - MBEDTLS_SSL_ALERT_MSG_BAD_CERT* = 42 - MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT* = 43 - MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED* = 44 - MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED* = 45 - MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN* = 46 - MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER* = 47 - MBEDTLS_SSL_ALERT_MSG_UNKNOWN_CA* = 48 - MBEDTLS_SSL_ALERT_MSG_ACCESS_DENIED* = 49 - MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR* = 50 - MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR* = 51 - MBEDTLS_SSL_ALERT_MSG_EXPORT_RESTRICTION* = 60 - MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION* = 70 - MBEDTLS_SSL_ALERT_MSG_INSUFFICIENT_SECURITY* = 71 - MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR* = 80 - MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK* = 86 - MBEDTLS_SSL_ALERT_MSG_USER_CANCELED* = 90 - MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION* = 100 - MBEDTLS_SSL_ALERT_MSG_MISSING_EXTENSION* = 109 - MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT* = 110 - MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME* = 112 - MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY* = 115 - MBEDTLS_SSL_ALERT_MSG_CERT_REQUIRED* = 116 - MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL* = 120 - MBEDTLS_SSL_HS_HELLO_REQUEST* = 0 - MBEDTLS_SSL_HS_CLIENT_HELLO* = 1 - MBEDTLS_SSL_HS_SERVER_HELLO* = 2 - MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST* = 3 - MBEDTLS_SSL_HS_NEW_SESSION_TICKET* = 4 - MBEDTLS_SSL_HS_END_OF_EARLY_DATA* = 5 - MBEDTLS_SSL_HS_ENCRYPTED_EXTENSIONS* = 8 - MBEDTLS_SSL_HS_CERTIFICATE* = 11 - MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE* = 12 - MBEDTLS_SSL_HS_CERTIFICATE_REQUEST* = 13 - MBEDTLS_SSL_HS_SERVER_HELLO_DONE* = 14 - MBEDTLS_SSL_HS_CERTIFICATE_VERIFY* = 15 - MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE* = 16 - MBEDTLS_SSL_HS_FINISHED* = 20 - MBEDTLS_SSL_HS_MESSAGE_HASH* = 254 - MBEDTLS_TLS_EXT_SERVERNAME* = 0 - MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME* = 0 - MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH* = 1 - MBEDTLS_TLS_EXT_TRUNCATED_HMAC* = 4 - MBEDTLS_TLS_EXT_STATUS_REQUEST* = 5 - MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES* = 10 - MBEDTLS_TLS_EXT_SUPPORTED_GROUPS* = 10 - MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS* = 11 - MBEDTLS_TLS_EXT_SIG_ALG* = 13 - MBEDTLS_TLS_EXT_USE_SRTP* = 14 - MBEDTLS_TLS_EXT_HEARTBEAT* = 15 - MBEDTLS_TLS_EXT_ALPN* = 16 - MBEDTLS_TLS_EXT_SCT* = 18 - MBEDTLS_TLS_EXT_CLI_CERT_TYPE* = 19 - MBEDTLS_TLS_EXT_SERV_CERT_TYPE* = 20 - MBEDTLS_TLS_EXT_PADDING* = 21 - MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC* = 22 - MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET* = 0x00000017 - MBEDTLS_TLS_EXT_RECORD_SIZE_LIMIT* = 28 - MBEDTLS_TLS_EXT_SESSION_TICKET* = 35 - MBEDTLS_TLS_EXT_PRE_SHARED_KEY* = 41 - MBEDTLS_TLS_EXT_EARLY_DATA* = 42 - MBEDTLS_TLS_EXT_SUPPORTED_VERSIONS* = 43 - MBEDTLS_TLS_EXT_COOKIE* = 44 - MBEDTLS_TLS_EXT_PSK_KEY_EXCHANGE_MODES* = 45 - MBEDTLS_TLS_EXT_CERT_AUTH* = 47 - MBEDTLS_TLS_EXT_OID_FILTERS* = 48 - MBEDTLS_TLS_EXT_POST_HANDSHAKE_AUTH* = 49 - MBEDTLS_TLS_EXT_SIG_ALG_CERT* = 50 - MBEDTLS_TLS_EXT_KEY_SHARE* = 51 - MBEDTLS_TLS_EXT_CID* = 54 - MBEDTLS_TLS_EXT_ECJPAKE_KKPP* = 256 - MBEDTLS_TLS_EXT_RENEGOTIATION_INFO* = 0x0000FF01 - MBEDTLS_PSK_MAX_LEN* = 32 - MBEDTLS_SSL_SEQUENCE_NUMBER_LEN* = 8 - MBEDTLS_SSL_HELLO_REQUEST* = (0).mbedtls_ssl_states - MBEDTLS_SSL_CLIENT_HELLO* = (MBEDTLS_SSL_HELLO_REQUEST + 1).mbedtls_ssl_states - MBEDTLS_SSL_SERVER_HELLO* = (MBEDTLS_SSL_CLIENT_HELLO + 1).mbedtls_ssl_states - MBEDTLS_SSL_SERVER_CERTIFICATE* = (MBEDTLS_SSL_SERVER_HELLO + 1).mbedtls_ssl_states - MBEDTLS_SSL_SERVER_KEY_EXCHANGE* = (MBEDTLS_SSL_SERVER_CERTIFICATE + 1).mbedtls_ssl_states - MBEDTLS_SSL_CERTIFICATE_REQUEST* = (MBEDTLS_SSL_SERVER_KEY_EXCHANGE + 1).mbedtls_ssl_states - MBEDTLS_SSL_SERVER_HELLO_DONE* = (MBEDTLS_SSL_CERTIFICATE_REQUEST + 1).mbedtls_ssl_states - MBEDTLS_SSL_CLIENT_CERTIFICATE* = (MBEDTLS_SSL_SERVER_HELLO_DONE + 1).mbedtls_ssl_states - MBEDTLS_SSL_CLIENT_KEY_EXCHANGE* = (MBEDTLS_SSL_CLIENT_CERTIFICATE + 1).mbedtls_ssl_states - MBEDTLS_SSL_CERTIFICATE_VERIFY* = (MBEDTLS_SSL_CLIENT_KEY_EXCHANGE + 1).mbedtls_ssl_states - MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC* = (MBEDTLS_SSL_CERTIFICATE_VERIFY + 1).mbedtls_ssl_states - MBEDTLS_SSL_CLIENT_FINISHED* = (MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC + 1).mbedtls_ssl_states - MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC* = (MBEDTLS_SSL_CLIENT_FINISHED + 1).mbedtls_ssl_states - MBEDTLS_SSL_SERVER_FINISHED* = (MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC + 1).mbedtls_ssl_states - MBEDTLS_SSL_FLUSH_BUFFERS* = (MBEDTLS_SSL_SERVER_FINISHED + 1).mbedtls_ssl_states - MBEDTLS_SSL_HANDSHAKE_WRAPUP* = (MBEDTLS_SSL_FLUSH_BUFFERS + 1).mbedtls_ssl_states - MBEDTLS_SSL_NEW_SESSION_TICKET* = (MBEDTLS_SSL_HANDSHAKE_WRAPUP + 1).mbedtls_ssl_states - MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT* = ( - MBEDTLS_SSL_NEW_SESSION_TICKET + 1).mbedtls_ssl_states - MBEDTLS_SSL_HELLO_RETRY_REQUEST* = (MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT + - 1).mbedtls_ssl_states - MBEDTLS_SSL_ENCRYPTED_EXTENSIONS* = (MBEDTLS_SSL_HELLO_RETRY_REQUEST + 1).mbedtls_ssl_states - MBEDTLS_SSL_END_OF_EARLY_DATA* = (MBEDTLS_SSL_ENCRYPTED_EXTENSIONS + 1).mbedtls_ssl_states - MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY* = (MBEDTLS_SSL_END_OF_EARLY_DATA + 1).mbedtls_ssl_states - MBEDTLS_SSL_CLIENT_CCS_AFTER_SERVER_FINISHED* = ( - MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY + 1).mbedtls_ssl_states - MBEDTLS_SSL_CLIENT_CCS_BEFORE_2ND_CLIENT_HELLO* = ( - MBEDTLS_SSL_CLIENT_CCS_AFTER_SERVER_FINISHED + 1).mbedtls_ssl_states - MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO* = ( - MBEDTLS_SSL_CLIENT_CCS_BEFORE_2ND_CLIENT_HELLO + 1).mbedtls_ssl_states - MBEDTLS_SSL_CLIENT_CCS_AFTER_CLIENT_HELLO* = ( - MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO + 1).mbedtls_ssl_states - MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST* = ( - MBEDTLS_SSL_CLIENT_CCS_AFTER_CLIENT_HELLO + 1).mbedtls_ssl_states - MBEDTLS_SSL_HANDSHAKE_OVER* = (MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST + - 1).mbedtls_ssl_states - MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET* = (MBEDTLS_SSL_HANDSHAKE_OVER + 1).mbedtls_ssl_states - MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH* = ( - MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET + 1).mbedtls_ssl_states - MBEDTLS_SSL_VERSION_UNKNOWN* = (0).mbedtls_ssl_protocol_version - MBEDTLS_SSL_VERSION_TLS1_2* = (0x00000303).mbedtls_ssl_protocol_version - MBEDTLS_SSL_VERSION_TLS1_3* = (0x00000304).mbedtls_ssl_protocol_version - MBEDTLS_SSL_TLS_PRF_NONE* = (0).mbedtls_tls_prf_types - MBEDTLS_SSL_TLS_PRF_SHA384* = (MBEDTLS_SSL_TLS_PRF_NONE + 1).mbedtls_tls_prf_types - MBEDTLS_SSL_TLS_PRF_SHA256* = (MBEDTLS_SSL_TLS_PRF_SHA384 + 1).mbedtls_tls_prf_types - MBEDTLS_SSL_HKDF_EXPAND_SHA384* = (MBEDTLS_SSL_TLS_PRF_SHA256 + 1).mbedtls_tls_prf_types - MBEDTLS_SSL_HKDF_EXPAND_SHA256* = (MBEDTLS_SSL_HKDF_EXPAND_SHA384 + 1).mbedtls_tls_prf_types - MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET* = (0).mbedtls_ssl_key_export_type - MBEDTLS_SSL_UNEXPECTED_CID_IGNORE* = 0 - MBEDTLS_SSL_UNEXPECTED_CID_FAIL* = 1 -type - mbedtls_ssl_premaster_secret* {.union, bycopy.} = object - u_pms_rsa*: array[48, byte] - u_pms_dhm*: array[1024, byte] - u_pms_ecdh*: array[(typeof(521)((521 + typeof(521)(7)) / typeof(521)(8))), - byte] - u_pms_psk*: array[4 + typeof(4)(2 * typeof(4)(32)), byte] - u_pms_dhe_psk*: array[4 + typeof(4)(1024) + typeof(4)(32), byte] - uu_pms_rsa_psk*: array[52 + typeof(52)(32), byte] - uu_pms_ecdhe_psk*: array[4 + - typeof(4)((typeof(4)((521 + typeof(4)(7)) / typeof(4)(8)))) + - typeof(4)(32), byte] - - mbedtls_ssl_send_t* = proc (ctx: pointer; buf: ptr byte; len: uint): cint {. - cdecl.} - mbedtls_ssl_recv_t* = proc (ctx: pointer; buf: ptr byte; len: uint): cint {. - cdecl.} - mbedtls_ssl_recv_timeout_t* = proc (ctx: pointer; buf: ptr byte; len: uint; - timeout: uint32): cint {.cdecl.} - mbedtls_ssl_set_timer_t* = proc (ctx: pointer; int_ms: uint32; fin_ms: uint32) {. - cdecl.} - mbedtls_ssl_get_timer_t* = proc (ctx: pointer): cint {.cdecl.} - mbedtls_ssl_session* {.bycopy.} = object - private_mfl_code*: byte - private_exported*: byte - private_tls_version*: mbedtls_ssl_protocol_version - private_start*: mbedtls_time_t - private_ciphersuite*: cint - private_id_len*: uint - private_id*: array[32, byte] - private_master*: array[48, byte] - private_peer_cert*: ptr mbedtls_x509_crt - private_verify_result*: uint32 - private_ticket*: ptr byte - private_ticket_len*: uint - private_ticket_lifetime*: uint32 - private_encrypt_then_mac*: cint - - mbedtls_ssl_context* {.bycopy.} = object - private_conf*: ptr mbedtls_ssl_config - private_state*: cint - private_renego_status*: cint - private_renego_records_seen*: cint - private_tls_version*: mbedtls_ssl_protocol_version - private_badmac_seen*: cuint - private_f_vrfy*: proc (a1: pointer; a2: ptr mbedtls_x509_crt; a3: cint; - a4: ptr uint32): cint {.cdecl.} - private_p_vrfy*: pointer - private_f_send*: ptr mbedtls_ssl_send_t - private_f_recv*: ptr mbedtls_ssl_recv_t - private_f_recv_timeout*: ptr mbedtls_ssl_recv_timeout_t - private_p_bio*: pointer - private_session_in*: ptr mbedtls_ssl_session - private_session_out*: ptr mbedtls_ssl_session - private_session*: ptr mbedtls_ssl_session - private_session_negotiate*: ptr mbedtls_ssl_session - private_handshake*: ptr mbedtls_ssl_handshake_params - private_transform_in*: ptr mbedtls_ssl_transform - private_transform_out*: ptr mbedtls_ssl_transform - private_transform*: ptr mbedtls_ssl_transform - private_transform_negotiate*: ptr mbedtls_ssl_transform - private_p_timer*: pointer - private_f_set_timer*: ptr mbedtls_ssl_set_timer_t - private_f_get_timer*: ptr mbedtls_ssl_get_timer_t - private_in_buf*: ptr byte - private_in_ctr*: ptr byte - private_in_hdr*: ptr byte - private_in_cid*: ptr byte - private_in_len*: ptr byte - private_in_iv*: ptr byte - private_in_msg*: ptr byte - private_in_offt*: ptr byte - private_in_msgtype*: cint - private_in_msglen*: uint - private_in_left*: uint - private_in_epoch*: uint16 - private_next_record_offset*: uint - private_in_window_top*: uint64 - private_in_window*: uint64 - private_in_hslen*: uint - private_nb_zero*: cint - private_keep_current_message*: cint - private_send_alert*: byte - private_alert_type*: byte - private_alert_reason*: cint - private_disable_datagram_packing*: uint8 - private_out_buf*: ptr byte - private_out_ctr*: ptr byte - private_out_hdr*: ptr byte - private_out_cid*: ptr byte - private_out_len*: ptr byte - private_out_iv*: ptr byte - private_out_msg*: ptr byte - private_out_msgtype*: cint - private_out_msglen*: uint - private_out_left*: uint - private_cur_out_ctr*: array[8, byte] - private_mtu*: uint16 - private_hostname*: cstring - private_alpn_chosen*: cstring - private_cli_id*: ptr byte - private_cli_id_len*: uint - private_secure_renegotiation*: cint - private_verify_data_len*: uint - private_own_verify_data*: array[12, cchar] - private_peer_verify_data*: array[12, cchar] - private_own_cid*: array[32, byte] - private_own_cid_len*: uint8 - private_negotiate_cid*: uint8 - private_f_export_keys*: ptr mbedtls_ssl_export_keys_t - private_p_export_keys*: pointer - private_user_data*: mbedtls_ssl_user_data_t - - mbedtls_ssl_config* {.bycopy.} = object - private_max_tls_version*: mbedtls_ssl_protocol_version - private_min_tls_version*: mbedtls_ssl_protocol_version - private_endpoint*: uint8 - private_transport*: uint8 - private_authmode*: uint8 - private_allow_legacy_renegotiation*: uint8 - private_mfl_code*: uint8 - private_encrypt_then_mac*: uint8 - private_extended_ms*: uint8 - private_anti_replay*: uint8 - private_disable_renegotiation*: uint8 - private_session_tickets*: uint8 - private_cert_req_ca_list*: uint8 - private_respect_cli_pref*: uint8 - private_ignore_unexpected_cid*: uint8 - private_ciphersuite_list*: ptr cint - private_f_dbg*: proc (a1: pointer; a2: cint; a3: cstring; a4: cint; - a5: cstring) {.cdecl.} - private_p_dbg*: pointer - private_f_rng*: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.} - private_p_rng*: pointer - private_f_get_cache*: ptr mbedtls_ssl_cache_get_t - private_f_set_cache*: ptr mbedtls_ssl_cache_set_t - private_p_cache*: pointer - private_f_sni*: proc (a1: pointer; a2: ptr mbedtls_ssl_context; - a3: ptr byte; a4: uint): cint {.cdecl.} - private_p_sni*: pointer - private_f_vrfy*: proc (a1: pointer; a2: ptr mbedtls_x509_crt; a3: cint; - a4: ptr uint32): cint {.cdecl.} - private_p_vrfy*: pointer - private_f_psk*: proc (a1: pointer; a2: ptr mbedtls_ssl_context; - a3: ptr byte; a4: uint): cint {.cdecl.} - private_p_psk*: pointer - private_f_cookie_write*: proc (a1: pointer; a2: ptr ptr byte; - a3: ptr byte; a4: ptr byte; a5: uint): cint {. - cdecl.} - private_f_cookie_check*: proc (a1: pointer; a2: ptr byte; a3: uint; - a4: ptr byte; a5: uint): cint {.cdecl.} - private_p_cookie*: pointer - private_f_ticket_write*: proc (a1: pointer; a2: ptr mbedtls_ssl_session; - a3: ptr byte; a4: ptr byte; a5: ptr uint; - a6: ptr uint32): cint {.cdecl.} - private_f_ticket_parse*: proc (a1: pointer; a2: ptr mbedtls_ssl_session; - a3: ptr byte; a4: uint): cint {.cdecl.} - private_p_ticket*: pointer - private_cid_len*: uint - private_cert_profile*: ptr mbedtls_x509_crt_profile - private_key_cert*: ptr mbedtls_ssl_key_cert - private_ca_chain*: ptr mbedtls_x509_crt - private_ca_crl*: ptr mbedtls_x509_crl - private_sig_hashes*: ptr cint - private_sig_algs*: ptr uint16 - private_curve_list*: ptr mbedtls_ecp_group_id - private_group_list*: ptr uint16 - private_dhm_P*: mbedtls_mpi - private_dhm_G*: mbedtls_mpi - private_psk*: ptr byte - private_psk_len*: uint - private_psk_identity*: ptr byte - private_psk_identity_len*: uint - private_alpn_list*: ptr cstring - private_read_timeout*: uint32 - private_hs_timeout_min*: uint32 - private_hs_timeout_max*: uint32 - private_renego_max_records*: cint - private_renego_period*: array[8, byte] - private_badmac_limit*: cuint - private_dhm_min_bitlen*: cuint - private_user_data*: mbedtls_ssl_user_data_t - private_f_cert_cb*: mbedtls_ssl_hs_cb_t - private_dn_hints*: ptr mbedtls_x509_crt - - mbedtls_ssl_transform* {.incompleteStruct.} = object - mbedtls_ssl_handshake_params* {.incompleteStruct.} = object - mbedtls_ssl_sig_hash_set_t* {.incompleteStruct.} = object - mbedtls_ssl_key_cert* {.incompleteStruct.} = object - mbedtls_ssl_flight_item* {.incompleteStruct.} = object - mbedtls_ssl_cache_get_t* = proc (data: pointer; session_id: ptr byte; - session_id_len: uint; - session: ptr mbedtls_ssl_session): cint {. - cdecl.} - mbedtls_ssl_cache_set_t* = proc (data: pointer; session_id: ptr byte; - session_id_len: uint; - session: ptr mbedtls_ssl_session): cint {. - cdecl.} - mbedtls_ssl_tls13_application_secrets* {.bycopy.} = object - client_application_traffic_secret_N*: array[64, byte] - server_application_traffic_secret_N*: array[64, byte] - exporter_master_secret*: array[64, byte] - resumption_master_secret*: array[64, byte] - - mbedtls_ssl_export_keys_t* = proc (p_expkey: pointer; - `type`: mbedtls_ssl_key_export_type; - secret: ptr byte; secret_len: uint; - client_random: array[32, byte]; - server_random: array[32, byte]; - tls_prf_type: mbedtls_tls_prf_types) {. - cdecl.} - mbedtls_ssl_hs_cb_t* = proc (ssl: ptr mbedtls_ssl_context): cint {.cdecl.} - mbedtls_ssl_user_data_t* {.union, bycopy.} = object - n*: ptr uint - p*: pointer - - mbedtls_ssl_ticket_write_t* = proc (p_ticket: pointer; - session: ptr mbedtls_ssl_session; - start: ptr byte; `end`: ptr byte; - tlen: ptr uint; lifetime: ptr uint32): cint {. - cdecl.} - mbedtls_ssl_ticket_parse_t* = proc (p_ticket: pointer; - session: ptr mbedtls_ssl_session; - buf: ptr byte; len: uint): cint {.cdecl.} - mbedtls_ssl_cookie_write_t* = proc (ctx: pointer; p: ptr ptr byte; - `end`: ptr byte; info: ptr byte; - ilen: uint): cint {.cdecl.} - mbedtls_ssl_cookie_check_t* = proc (ctx: pointer; cookie: ptr byte; - clen: uint; info: ptr byte; ilen: uint): cint {. - cdecl.} -proc mbedtls_ssl_get_ciphersuite_name*(ciphersuite_id: cint): cstring {.importc, - cdecl.} -proc mbedtls_ssl_get_ciphersuite_id*(ciphersuite_name: cstring): cint {.importc, - cdecl.} -proc mbedtls_ssl_init*(ssl: ptr mbedtls_ssl_context) {.importc, cdecl.} -proc mbedtls_ssl_setup*(ssl: ptr mbedtls_ssl_context; - conf: ptr mbedtls_ssl_config): cint {.importc, cdecl.} -proc mbedtls_ssl_session_reset*(ssl: ptr mbedtls_ssl_context): cint {.importc, - cdecl.} -proc mbedtls_ssl_conf_endpoint*(conf: ptr mbedtls_ssl_config; endpoint: cint) {. - importc, cdecl.} -proc mbedtls_ssl_conf_transport*(conf: ptr mbedtls_ssl_config; transport: cint) {. - importc, cdecl.} -proc mbedtls_ssl_conf_authmode*(conf: ptr mbedtls_ssl_config; authmode: cint) {. - importc, cdecl.} -proc mbedtls_ssl_conf_verify*(conf: ptr mbedtls_ssl_config; f_vrfy: proc ( - a1: pointer; a2: ptr mbedtls_x509_crt; a3: cint; a4: ptr uint32): cint {. - cdecl.}; p_vrfy: pointer) {.importc, cdecl.} -proc mbedtls_ssl_conf_rng*(conf: ptr mbedtls_ssl_config; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer) {. - importc, cdecl.} -proc mbedtls_ssl_conf_dbg*(conf: ptr mbedtls_ssl_config; f_dbg: proc ( - a1: pointer; a2: cint; a3: cstring; a4: cint; a5: cstring) {.cdecl.}; - p_dbg: pointer) {.importc, cdecl.} -proc mbedtls_ssl_set_bio*(ssl: ptr mbedtls_ssl_context; p_bio: pointer; - f_send: ptr mbedtls_ssl_send_t; - f_recv: ptr mbedtls_ssl_recv_t; - f_recv_timeout: ptr mbedtls_ssl_recv_timeout_t) {. - importc, cdecl.} -proc mbedtls_ssl_set_cid*(ssl: ptr mbedtls_ssl_context; enable: cint; - own_cid: ptr byte; own_cid_len: uint): cint {. - importc, cdecl.} -proc mbedtls_ssl_get_own_cid*(ssl: ptr mbedtls_ssl_context; enabled: ptr cint; - own_cid: array[32, byte]; own_cid_len: ptr uint): cint {. - importc, cdecl.} -proc mbedtls_ssl_get_peer_cid*(ssl: ptr mbedtls_ssl_context; enabled: ptr cint; - peer_cid: array[32, byte]; - peer_cid_len: ptr uint): cint {.importc, cdecl.} -proc mbedtls_ssl_set_mtu*(ssl: ptr mbedtls_ssl_context; mtu: uint16) {.importc, - cdecl.} -proc mbedtls_ssl_set_verify*(ssl: ptr mbedtls_ssl_context; f_vrfy: proc ( - a1: pointer; a2: ptr mbedtls_x509_crt; a3: cint; a4: ptr uint32): cint {. - cdecl.}; p_vrfy: pointer) {.importc, cdecl.} -proc mbedtls_ssl_conf_read_timeout*(conf: ptr mbedtls_ssl_config; - timeout: uint32) {.importc, cdecl.} -proc mbedtls_ssl_check_record*(ssl: ptr mbedtls_ssl_context; buf: ptr byte; - buflen: uint): cint {.importc, cdecl.} -proc mbedtls_ssl_set_timer_cb*(ssl: ptr mbedtls_ssl_context; p_timer: pointer; - f_set_timer: ptr mbedtls_ssl_set_timer_t; - f_get_timer: ptr mbedtls_ssl_get_timer_t) {. - importc, cdecl.} -proc mbedtls_ssl_conf_session_tickets_cb*(conf: ptr mbedtls_ssl_config; - f_ticket_write: ptr mbedtls_ssl_ticket_write_t; - f_ticket_parse: ptr mbedtls_ssl_ticket_parse_t; p_ticket: pointer) {. - importc, cdecl.} -proc mbedtls_ssl_set_export_keys_cb*(ssl: ptr mbedtls_ssl_context; f_export_keys: ptr mbedtls_ssl_export_keys_t; - p_export_keys: pointer) {.importc, cdecl.} -proc mbedtls_ssl_conf_dtls_cookies*(conf: ptr mbedtls_ssl_config; f_cookie_write: ptr mbedtls_ssl_cookie_write_t; - f_cookie_check: ptr mbedtls_ssl_cookie_check_t; p_cookie: pointer) {. - importc, cdecl.} -proc mbedtls_ssl_set_client_transport_id*(ssl: ptr mbedtls_ssl_context; - info: ptr byte; ilen: uint): cint {.importc, cdecl.} -proc mbedtls_ssl_conf_dtls_anti_replay*(conf: ptr mbedtls_ssl_config; - mode: cchar) {.importc, cdecl.} -proc mbedtls_ssl_conf_dtls_badmac_limit*(conf: ptr mbedtls_ssl_config; - limit: cuint) {.importc, cdecl.} -proc mbedtls_ssl_set_datagram_packing*(ssl: ptr mbedtls_ssl_context; - allow_packing: cuint) {.importc, cdecl.} -proc mbedtls_ssl_conf_handshake_timeout*(conf: ptr mbedtls_ssl_config; - min: uint32; max: uint32) {.importc, cdecl.} -proc mbedtls_ssl_conf_session_cache*(conf: ptr mbedtls_ssl_config; - p_cache: pointer; - f_get_cache: ptr mbedtls_ssl_cache_get_t; - f_set_cache: ptr mbedtls_ssl_cache_set_t) {. - importc, cdecl.} -proc mbedtls_ssl_set_session*(ssl: ptr mbedtls_ssl_context; - session: ptr mbedtls_ssl_session): cint {.importc, - cdecl.} -proc mbedtls_ssl_session_load*(session: ptr mbedtls_ssl_session; - buf: ptr byte; len: uint): cint {.importc, - cdecl.} -proc mbedtls_ssl_session_save*(session: ptr mbedtls_ssl_session; - buf: ptr byte; buf_len: uint; olen: ptr uint): cint {. - importc, cdecl.} -proc mbedtls_ssl_conf_ciphersuites*(conf: ptr mbedtls_ssl_config; - ciphersuites: ptr cint) {.importc, cdecl.} -proc mbedtls_ssl_conf_cid*(conf: ptr mbedtls_ssl_config; len: uint; - ignore_other_cids: cint): cint {.importc, cdecl.} -proc mbedtls_ssl_conf_cert_profile*(conf: ptr mbedtls_ssl_config; - profile: ptr mbedtls_x509_crt_profile) {. - importc, cdecl.} -proc mbedtls_ssl_conf_ca_chain*(conf: ptr mbedtls_ssl_config; - ca_chain: ptr mbedtls_x509_crt; - ca_crl: ptr mbedtls_x509_crl) {.importc, cdecl.} -proc mbedtls_ssl_conf_own_cert*(conf: ptr mbedtls_ssl_config; - own_cert: ptr mbedtls_x509_crt; - pk_key: ptr mbedtls_pk_context): cint {.importc, - cdecl.} -proc mbedtls_ssl_conf_psk*(conf: ptr mbedtls_ssl_config; psk: ptr byte; - psk_len: uint; psk_identity: ptr byte; - psk_identity_len: uint): cint {.importc, cdecl.} -proc mbedtls_ssl_set_hs_psk*(ssl: ptr mbedtls_ssl_context; psk: ptr byte; - psk_len: uint): cint {.importc, cdecl.} -proc mbedtls_ssl_conf_psk_cb*(conf: ptr mbedtls_ssl_config; f_psk: proc ( - a1: pointer; a2: ptr mbedtls_ssl_context; a3: ptr byte; a4: uint): cint {. - cdecl.}; p_psk: pointer) {.importc, cdecl.} -proc mbedtls_ssl_conf_dh_param_bin*(conf: ptr mbedtls_ssl_config; - dhm_P: ptr byte; P_len: uint; - dhm_G: ptr byte; G_len: uint): cint {. - importc, cdecl.} -proc mbedtls_ssl_conf_dh_param_ctx*(conf: ptr mbedtls_ssl_config; - dhm_ctx: ptr mbedtls_dhm_context): cint {. - importc, cdecl.} -proc mbedtls_ssl_conf_dhm_min_bitlen*(conf: ptr mbedtls_ssl_config; - bitlen: cuint) {.importc, cdecl.} -proc mbedtls_ssl_conf_curves*(conf: ptr mbedtls_ssl_config; - curves: ptr mbedtls_ecp_group_id) {.importc, cdecl.} -proc mbedtls_ssl_conf_groups*(conf: ptr mbedtls_ssl_config; groups: ptr uint16) {. - importc, cdecl.} -proc mbedtls_ssl_conf_sig_hashes*(conf: ptr mbedtls_ssl_config; hashes: ptr cint) {. - importc, cdecl.} -proc mbedtls_ssl_conf_sig_algs*(conf: ptr mbedtls_ssl_config; - sig_algs: ptr uint16) {.importc, cdecl.} -proc mbedtls_ssl_set_hostname*(ssl: ptr mbedtls_ssl_context; hostname: cstring): cint {. - importc, cdecl.} -proc mbedtls_ssl_get_hs_sni*(ssl: ptr mbedtls_ssl_context; name_len: ptr uint): ptr byte {. - importc, cdecl.} -proc mbedtls_ssl_set_hs_own_cert*(ssl: ptr mbedtls_ssl_context; - own_cert: ptr mbedtls_x509_crt; - pk_key: ptr mbedtls_pk_context): cint {. - importc, cdecl.} -proc mbedtls_ssl_set_hs_ca_chain*(ssl: ptr mbedtls_ssl_context; - ca_chain: ptr mbedtls_x509_crt; - ca_crl: ptr mbedtls_x509_crl) {.importc, cdecl.} -proc mbedtls_ssl_set_hs_dn_hints*(ssl: ptr mbedtls_ssl_context; - crt: ptr mbedtls_x509_crt) {.importc, cdecl.} -proc mbedtls_ssl_set_hs_authmode*(ssl: ptr mbedtls_ssl_context; authmode: cint) {. - importc, cdecl.} -proc mbedtls_ssl_conf_sni*(conf: ptr mbedtls_ssl_config; f_sni: proc ( - a1: pointer; a2: ptr mbedtls_ssl_context; a3: ptr byte; a4: uint): cint {. - cdecl.}; p_sni: pointer) {.importc, cdecl.} -proc mbedtls_ssl_conf_alpn_protocols*(conf: ptr mbedtls_ssl_config; - protos: ptr cstring): cint {.importc, - cdecl.} -proc mbedtls_ssl_get_alpn_protocol*(ssl: ptr mbedtls_ssl_context): cstring {. - importc, cdecl.} -proc mbedtls_ssl_conf_max_version*(conf: ptr mbedtls_ssl_config; major: cint; - minor: cint) {.importc, cdecl.} -proc mbedtls_ssl_conf_min_version*(conf: ptr mbedtls_ssl_config; major: cint; - minor: cint) {.importc, cdecl.} -proc mbedtls_ssl_conf_encrypt_then_mac*(conf: ptr mbedtls_ssl_config; etm: cchar) {. - importc, cdecl.} -proc mbedtls_ssl_conf_extended_master_secret*(conf: ptr mbedtls_ssl_config; - ems: cchar) {.importc, cdecl.} -proc mbedtls_ssl_conf_cert_req_ca_list*(conf: ptr mbedtls_ssl_config; - cert_req_ca_list: cchar) {.importc, - cdecl.} -proc mbedtls_ssl_conf_max_frag_len*(conf: ptr mbedtls_ssl_config; - mfl_code: byte): cint {.importc, cdecl.} -proc mbedtls_ssl_conf_preference_order*(conf: ptr mbedtls_ssl_config; - order: cint) {.importc, cdecl.} -proc mbedtls_ssl_conf_session_tickets*(conf: ptr mbedtls_ssl_config; - use_tickets: cint) {.importc, cdecl.} -proc mbedtls_ssl_conf_renegotiation*(conf: ptr mbedtls_ssl_config; - renegotiation: cint) {.importc, cdecl.} -proc mbedtls_ssl_conf_legacy_renegotiation*(conf: ptr mbedtls_ssl_config; - allow_legacy: cint) {.importc, cdecl.} -proc mbedtls_ssl_conf_renegotiation_enforced*(conf: ptr mbedtls_ssl_config; - max_records: cint) {.importc, cdecl.} -proc mbedtls_ssl_conf_renegotiation_period*(conf: ptr mbedtls_ssl_config; - period: array[8, byte]) {.importc, cdecl.} -proc mbedtls_ssl_check_pending*(ssl: ptr mbedtls_ssl_context): cint {.importc, - cdecl.} -proc mbedtls_ssl_get_bytes_avail*(ssl: ptr mbedtls_ssl_context): uint {.importc, - cdecl.} -proc mbedtls_ssl_get_verify_result*(ssl: ptr mbedtls_ssl_context): uint32 {. - importc, cdecl.} -proc mbedtls_ssl_get_ciphersuite_id_from_ssl*(ssl: ptr mbedtls_ssl_context): cint {. - importc, cdecl.} -proc mbedtls_ssl_get_ciphersuite*(ssl: ptr mbedtls_ssl_context): cstring {. - importc, cdecl.} -proc mbedtls_ssl_get_version*(ssl: ptr mbedtls_ssl_context): cstring {.importc, - cdecl.} -proc mbedtls_ssl_get_record_expansion*(ssl: ptr mbedtls_ssl_context): cint {. - importc, cdecl.} -proc mbedtls_ssl_get_max_out_record_payload*(ssl: ptr mbedtls_ssl_context): cint {. - importc, cdecl.} -proc mbedtls_ssl_get_max_in_record_payload*(ssl: ptr mbedtls_ssl_context): cint {. - importc, cdecl.} -proc mbedtls_ssl_get_peer_cert*(ssl: ptr mbedtls_ssl_context): ptr mbedtls_x509_crt {. - importc, cdecl.} -proc mbedtls_ssl_get_session*(ssl: ptr mbedtls_ssl_context; - session: ptr mbedtls_ssl_session): cint {.importc, - cdecl.} -proc mbedtls_ssl_handshake*(ssl: ptr mbedtls_ssl_context): cint {.importc, cdecl.} -proc mbedtls_ssl_handshake_step*(ssl: ptr mbedtls_ssl_context): cint {.importc, - cdecl.} -proc mbedtls_ssl_renegotiate*(ssl: ptr mbedtls_ssl_context): cint {.importc, - cdecl.} -proc mbedtls_ssl_read*(ssl: ptr mbedtls_ssl_context; buf: ptr byte; len: uint): cint {. - importc, cdecl.} -proc mbedtls_ssl_write*(ssl: ptr mbedtls_ssl_context; buf: ptr byte; len: uint): cint {. - importc, cdecl.} -proc mbedtls_ssl_send_alert_message*(ssl: ptr mbedtls_ssl_context; - level: byte; message: byte): cint {. - importc, cdecl.} -proc mbedtls_ssl_close_notify*(ssl: ptr mbedtls_ssl_context): cint {.importc, - cdecl.} -proc mbedtls_ssl_free*(ssl: ptr mbedtls_ssl_context) {.importc, cdecl.} -proc mbedtls_ssl_context_save*(ssl: ptr mbedtls_ssl_context; buf: ptr byte; - buf_len: uint; olen: ptr uint): cint {.importc, - cdecl.} -proc mbedtls_ssl_context_load*(ssl: ptr mbedtls_ssl_context; buf: ptr byte; - len: uint): cint {.importc, cdecl.} -proc mbedtls_ssl_config_init*(conf: ptr mbedtls_ssl_config) {.importc, cdecl.} -proc mbedtls_ssl_config_defaults*(conf: ptr mbedtls_ssl_config; endpoint: cint; - transport: cint; preset: cint): cint {. - importc, cdecl.} -proc mbedtls_ssl_config_free*(conf: ptr mbedtls_ssl_config) {.importc, cdecl.} -proc mbedtls_ssl_session_init*(session: ptr mbedtls_ssl_session) {.importc, - cdecl.} -proc mbedtls_ssl_session_free*(session: ptr mbedtls_ssl_session) {.importc, - cdecl.} -proc mbedtls_ssl_tls_prf*(prf: mbedtls_tls_prf_types; secret: ptr byte; - slen: uint; label: cstring; random: ptr byte; - rlen: uint; dstbuf: ptr byte; dlen: uint): cint {. - importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/ssl_cache.nim b/webrtc/mbedtls/ssl_cache.nim deleted file mode 100644 index b073669..0000000 --- a/webrtc/mbedtls/ssl_cache.nim +++ /dev/null @@ -1,47 +0,0 @@ -import "ssl" -import "platform_time" - -{.compile: "./mbedtls/library/ssl_cache.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT* = 86400 - MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES* = 50 -type - mbedtls_ssl_cache_context* {.bycopy.} = object - private_chain*: ptr mbedtls_ssl_cache_entry - private_timeout*: cint - private_max_entries*: cint - - mbedtls_ssl_cache_entry* {.bycopy.} = object - private_timestamp*: mbedtls_time_t - private_session_id*: array[32, byte] - private_session_id_len*: uint - private_session*: ptr byte - private_session_len*: uint - private_next*: ptr mbedtls_ssl_cache_entry - -proc mbedtls_ssl_cache_init*(cache: ptr mbedtls_ssl_cache_context) {.importc, - cdecl.} -proc mbedtls_ssl_cache_get*(data: pointer; session_id: ptr byte; - session_id_len: uint; - session: ptr mbedtls_ssl_session): cint {.importc, - cdecl.} -proc mbedtls_ssl_cache_set*(data: pointer; session_id: ptr byte; - session_id_len: uint; - session: ptr mbedtls_ssl_session): cint {.importc, - cdecl.} -proc mbedtls_ssl_cache_remove*(data: pointer; session_id: ptr byte; - session_id_len: uint): cint {.importc, cdecl.} -proc mbedtls_ssl_cache_set_timeout*(cache: ptr mbedtls_ssl_cache_context; - timeout: cint) {.importc, cdecl.} -proc mbedtls_ssl_cache_set_max_entries*(cache: ptr mbedtls_ssl_cache_context; - max: cint) {.importc, cdecl.} -proc mbedtls_ssl_cache_free*(cache: ptr mbedtls_ssl_cache_context) {.importc, - cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/ssl_ciphersuites.nim b/webrtc/mbedtls/ssl_ciphersuites.nim deleted file mode 100644 index 5517a46..0000000 --- a/webrtc/mbedtls/ssl_ciphersuites.nim +++ /dev/null @@ -1,256 +0,0 @@ -import "pk" -import "utils" - -{.compile: "./mbedtls/library/ssl_ciphersuites.c".} - -# proc 'mbedtls_ssl_ciphersuite_get_name' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_ciphersuite_has_pfs' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_ciphersuite_no_pfs' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_ciphersuite_uses_ecdh' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_ciphersuite_cert_req_allowed' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_ciphersuite_uses_srv_cert' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_ciphersuite_uses_dhe' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_ciphersuite_uses_ecdhe' skipped - static inline procs cannot work with '--noHeader | -H' -# proc 'mbedtls_ssl_ciphersuite_uses_server_signature' skipped - static inline procs cannot work with '--noHeader | -H' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -defineEnum(mbedtls_key_exchange_type_t) - -const - MBEDTLS_TLS_RSA_WITH_NULL_MD5* = 0x00000001 - MBEDTLS_TLS_RSA_WITH_NULL_SHA* = 0x00000002 - MBEDTLS_TLS_PSK_WITH_NULL_SHA* = 0x0000002C - MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA* = 0x0000002D - MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA* = 0x0000002E - MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA* = 0x0000002F - MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA* = 0x00000033 - MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA* = 0x00000035 - MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA* = 0x00000039 - MBEDTLS_TLS_RSA_WITH_NULL_SHA256* = 0x0000003B - MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256* = 0x0000003C - MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256* = 0x0000003D - MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA* = 0x00000041 - MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA* = 0x00000045 - MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256* = 0x00000067 - MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256* = 0x0000006B - MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA* = 0x00000084 - MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA* = 0x00000088 - MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA* = 0x0000008C - MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA* = 0x0000008D - MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA* = 0x00000090 - MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA* = 0x00000091 - MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA* = 0x00000094 - MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA* = 0x00000095 - MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256* = 0x0000009C - MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384* = 0x0000009D - MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256* = 0x0000009E - MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384* = 0x0000009F - MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256* = 0x000000A8 - MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384* = 0x000000A9 - MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256* = 0x000000AA - MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384* = 0x000000AB - MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256* = 0x000000AC - MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384* = 0x000000AD - MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256* = 0x000000AE - MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384* = 0x000000AF - MBEDTLS_TLS_PSK_WITH_NULL_SHA256* = 0x000000B0 - MBEDTLS_TLS_PSK_WITH_NULL_SHA384* = 0x000000B1 - MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256* = 0x000000B2 - MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384* = 0x000000B3 - MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256* = 0x000000B4 - MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384* = 0x000000B5 - MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256* = 0x000000B6 - MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384* = 0x000000B7 - MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256* = 0x000000B8 - MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384* = 0x000000B9 - MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256* = 0x000000BA - MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256* = 0x000000BE - MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256* = 0x000000C0 - MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256* = 0x000000C4 - MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA* = 0x0000C001 - MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA* = 0x0000C004 - MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA* = 0x0000C005 - MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA* = 0x0000C006 - MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA* = 0x0000C009 - MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA* = 0x0000C00A - MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA* = 0x0000C00B - MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA* = 0x0000C00E - MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA* = 0x0000C00F - MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA* = 0x0000C010 - MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA* = 0x0000C013 - MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA* = 0x0000C014 - MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256* = 0x0000C023 - MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384* = 0x0000C024 - MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256* = 0x0000C025 - MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384* = 0x0000C026 - MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256* = 0x0000C027 - MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384* = 0x0000C028 - MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256* = 0x0000C029 - MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384* = 0x0000C02A - MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256* = 0x0000C02B - MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384* = 0x0000C02C - MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256* = 0x0000C02D - MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384* = 0x0000C02E - MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256* = 0x0000C02F - MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384* = 0x0000C030 - MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256* = 0x0000C031 - MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384* = 0x0000C032 - MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA* = 0x0000C035 - MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA* = 0x0000C036 - MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256* = 0x0000C037 - MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384* = 0x0000C038 - MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA* = 0x0000C039 - MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256* = 0x0000C03A - MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384* = 0x0000C03B - MBEDTLS_TLS_RSA_WITH_ARIA_128_CBC_SHA256* = 0x0000C03C - MBEDTLS_TLS_RSA_WITH_ARIA_256_CBC_SHA384* = 0x0000C03D - MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256* = 0x0000C044 - MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384* = 0x0000C045 - MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256* = 0x0000C048 - MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384* = 0x0000C049 - MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256* = 0x0000C04A - MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384* = 0x0000C04B - MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256* = 0x0000C04C - MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384* = 0x0000C04D - MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256* = 0x0000C04E - MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384* = 0x0000C04F - MBEDTLS_TLS_RSA_WITH_ARIA_128_GCM_SHA256* = 0x0000C050 - MBEDTLS_TLS_RSA_WITH_ARIA_256_GCM_SHA384* = 0x0000C051 - MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256* = 0x0000C052 - MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384* = 0x0000C053 - MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256* = 0x0000C05C - MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384* = 0x0000C05D - MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256* = 0x0000C05E - MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384* = 0x0000C05F - MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256* = 0x0000C060 - MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384* = 0x0000C061 - MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256* = 0x0000C062 - MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384* = 0x0000C063 - MBEDTLS_TLS_PSK_WITH_ARIA_128_CBC_SHA256* = 0x0000C064 - MBEDTLS_TLS_PSK_WITH_ARIA_256_CBC_SHA384* = 0x0000C065 - MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256* = 0x0000C066 - MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384* = 0x0000C067 - MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256* = 0x0000C068 - MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384* = 0x0000C069 - MBEDTLS_TLS_PSK_WITH_ARIA_128_GCM_SHA256* = 0x0000C06A - MBEDTLS_TLS_PSK_WITH_ARIA_256_GCM_SHA384* = 0x0000C06B - MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256* = 0x0000C06C - MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384* = 0x0000C06D - MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256* = 0x0000C06E - MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384* = 0x0000C06F - MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256* = 0x0000C070 - MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384* = 0x0000C071 - MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C072 - MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C073 - MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C074 - MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C075 - MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C076 - MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C077 - MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C078 - MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C079 - MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C07A - MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C07B - MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C07C - MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C07D - MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C086 - MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C087 - MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C088 - MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C089 - MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C08A - MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C08B - MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C08C - MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C08D - MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C08E - MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C08F - MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C090 - MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C091 - MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256* = 0x0000C092 - MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384* = 0x0000C093 - MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C094 - MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C095 - MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C096 - MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C097 - MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C098 - MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C099 - MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256* = 0x0000C09A - MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384* = 0x0000C09B - MBEDTLS_TLS_RSA_WITH_AES_128_CCM* = 0x0000C09C - MBEDTLS_TLS_RSA_WITH_AES_256_CCM* = 0x0000C09D - MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM* = 0x0000C09E - MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM* = 0x0000C09F - MBEDTLS_TLS_RSA_WITH_AES_128_CCM_8* = 0x0000C0A0 - MBEDTLS_TLS_RSA_WITH_AES_256_CCM_8* = 0x0000C0A1 - MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM_8* = 0x0000C0A2 - MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM_8* = 0x0000C0A3 - MBEDTLS_TLS_PSK_WITH_AES_128_CCM* = 0x0000C0A4 - MBEDTLS_TLS_PSK_WITH_AES_256_CCM* = 0x0000C0A5 - MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM* = 0x0000C0A6 - MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM* = 0x0000C0A7 - MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8* = 0x0000C0A8 - MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8* = 0x0000C0A9 - MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM_8* = 0x0000C0AA - MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM_8* = 0x0000C0AB - MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM* = 0x0000C0AC - MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM* = 0x0000C0AD - MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8* = 0x0000C0AE - MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8* = 0x0000C0AF - MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8* = 0x0000C0FF - MBEDTLS_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256* = 0x0000CCA8 - MBEDTLS_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256* = 0x0000CCA9 - MBEDTLS_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256* = 0x0000CCAA - MBEDTLS_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256* = 0x0000CCAB - MBEDTLS_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256* = 0x0000CCAC - MBEDTLS_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256* = 0x0000CCAD - MBEDTLS_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256* = 0x0000CCAE - MBEDTLS_TLS1_3_AES_128_GCM_SHA256* = 0x00001301 - MBEDTLS_TLS1_3_AES_256_GCM_SHA384* = 0x00001302 - MBEDTLS_TLS1_3_CHACHA20_POLY1305_SHA256* = 0x00001303 - MBEDTLS_TLS1_3_AES_128_CCM_SHA256* = 0x00001304 - MBEDTLS_TLS1_3_AES_128_CCM_8_SHA256* = 0x00001305 - MBEDTLS_KEY_EXCHANGE_NONE* = (0).mbedtls_key_exchange_type_t - MBEDTLS_KEY_EXCHANGE_RSA* = (MBEDTLS_KEY_EXCHANGE_NONE + 1).mbedtls_key_exchange_type_t - MBEDTLS_KEY_EXCHANGE_DHE_RSA* = (MBEDTLS_KEY_EXCHANGE_RSA + 1).mbedtls_key_exchange_type_t - MBEDTLS_KEY_EXCHANGE_ECDHE_RSA* = (MBEDTLS_KEY_EXCHANGE_DHE_RSA + 1).mbedtls_key_exchange_type_t - MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA* = (MBEDTLS_KEY_EXCHANGE_ECDHE_RSA + 1).mbedtls_key_exchange_type_t - MBEDTLS_KEY_EXCHANGE_PSK* = (MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA + 1).mbedtls_key_exchange_type_t - MBEDTLS_KEY_EXCHANGE_DHE_PSK* = (MBEDTLS_KEY_EXCHANGE_PSK + 1).mbedtls_key_exchange_type_t - MBEDTLS_KEY_EXCHANGE_RSA_PSK* = (MBEDTLS_KEY_EXCHANGE_DHE_PSK + 1).mbedtls_key_exchange_type_t - MBEDTLS_KEY_EXCHANGE_ECDHE_PSK* = (MBEDTLS_KEY_EXCHANGE_RSA_PSK + 1).mbedtls_key_exchange_type_t - MBEDTLS_KEY_EXCHANGE_ECDH_RSA* = (MBEDTLS_KEY_EXCHANGE_ECDHE_PSK + 1).mbedtls_key_exchange_type_t - MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA* = (MBEDTLS_KEY_EXCHANGE_ECDH_RSA + 1).mbedtls_key_exchange_type_t - MBEDTLS_KEY_EXCHANGE_ECJPAKE* = (MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA + 1).mbedtls_key_exchange_type_t - MBEDTLS_CIPHERSUITE_WEAK* = 0x00000001 - MBEDTLS_CIPHERSUITE_SHORT_TAG* = 0x00000002 - MBEDTLS_CIPHERSUITE_NODTLS* = 0x00000004 -type - mbedtls_ssl_ciphersuite_t* {.bycopy.} = object - private_id*: cint - private_name*: cstring - private_cipher*: uint8 - private_mac*: uint8 - private_key_exchange*: uint8 - private_flags*: uint8 - private_min_tls_version*: uint16 - private_max_tls_version*: uint16 - -proc mbedtls_ssl_list_ciphersuites*(): ptr cint {.importc, cdecl.} -proc mbedtls_ssl_ciphersuite_from_string*(ciphersuite_name: cstring): ptr mbedtls_ssl_ciphersuite_t {. - importc, cdecl.} -proc mbedtls_ssl_ciphersuite_from_id*(ciphersuite_id: cint): ptr mbedtls_ssl_ciphersuite_t {. - importc, cdecl.} -proc mbedtls_ssl_get_ciphersuite_sig_pk_alg*(info: ptr mbedtls_ssl_ciphersuite_t): mbedtls_pk_type_t {. - importc, cdecl.} -proc mbedtls_ssl_get_ciphersuite_sig_alg*(info: ptr mbedtls_ssl_ciphersuite_t): mbedtls_pk_type_t {. - importc, cdecl.} -proc mbedtls_ssl_ciphersuite_uses_ec*(info: ptr mbedtls_ssl_ciphersuite_t): cint {. - importc, cdecl.} -proc mbedtls_ssl_ciphersuite_uses_psk*(info: ptr mbedtls_ssl_ciphersuite_t): cint {. - importc, cdecl.} -proc mbedtls_ssl_ciphersuite_get_cipher_key_bitlen*( - info: ptr mbedtls_ssl_ciphersuite_t): uint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/ssl_cookie.nim b/webrtc/mbedtls/ssl_cookie.nim deleted file mode 100644 index 214b466..0000000 --- a/webrtc/mbedtls/ssl_cookie.nim +++ /dev/null @@ -1,29 +0,0 @@ -import "ssl" -import "md" - -{.compile: "./mbedtls/library/ssl_cookie.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_SSL_COOKIE_TIMEOUT* = 60 -type - mbedtls_ssl_cookie_ctx* {.bycopy.} = object - private_hmac_ctx*: mbedtls_md_context_t - private_timeout*: culong - -var - mbedtls_ssl_cookie_write* {.importc.}: mbedtls_ssl_cookie_write_t - mbedtls_ssl_cookie_check* {.importc.}: mbedtls_ssl_cookie_check_t -proc mbedtls_ssl_cookie_init*(ctx: ptr mbedtls_ssl_cookie_ctx) {.importc, cdecl.} -proc mbedtls_ssl_cookie_setup*(ctx: ptr mbedtls_ssl_cookie_ctx; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_ssl_cookie_set_timeout*(ctx: ptr mbedtls_ssl_cookie_ctx; - delay: culong) {.importc, cdecl.} -proc mbedtls_ssl_cookie_free*(ctx: ptr mbedtls_ssl_cookie_ctx) {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/ssl_ticket.nim b/webrtc/mbedtls/ssl_ticket.nim deleted file mode 100644 index 2dce02e..0000000 --- a/webrtc/mbedtls/ssl_ticket.nim +++ /dev/null @@ -1,45 +0,0 @@ -import "ssl" -import "platform_time" -import "ssl_ciphersuites" -import "cipher" - -{.compile: "./mbedtls/library/ssl_ticket.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_SSL_TICKET_MAX_KEY_BYTES* = 32 - MBEDTLS_SSL_TICKET_KEY_NAME_BYTES* = 4 -type - mbedtls_ssl_ticket_key* {.bycopy.} = object - private_name*: array[4, byte] - private_generation_time*: mbedtls_time_t - private_ctx*: mbedtls_cipher_context_t - - mbedtls_ssl_ticket_context* {.bycopy.} = object - private_keys*: array[2, mbedtls_ssl_ticket_key] - private_active*: byte - private_ticket_lifetime*: uint32 - private_f_rng*: proc (a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.} - private_p_rng*: pointer - -var - mbedtls_ssl_ticket_write* {.importc.}: mbedtls_ssl_ticket_write_t - mbedtls_ssl_ticket_parse* {.importc.}: mbedtls_ssl_ticket_parse_t -proc mbedtls_ssl_ticket_init*(ctx: ptr mbedtls_ssl_ticket_context) {.importc, - cdecl.} -proc mbedtls_ssl_ticket_setup*(ctx: ptr mbedtls_ssl_ticket_context; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer; - cipher: mbedtls_cipher_type_t; lifetime: uint32): cint {. - importc, cdecl.} -proc mbedtls_ssl_ticket_rotate*(ctx: ptr mbedtls_ssl_ticket_context; - name: ptr byte; nlength: uint; k: ptr byte; - klength: uint; lifetime: uint32): cint {. - importc, cdecl.} -proc mbedtls_ssl_ticket_free*(ctx: ptr mbedtls_ssl_ticket_context) {.importc, - cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/threading.nim b/webrtc/mbedtls/threading.nim deleted file mode 100644 index e4a193d..0000000 --- a/webrtc/mbedtls/threading.nim +++ /dev/null @@ -1,10 +0,0 @@ -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_ERR_THREADING_BAD_INPUT_DATA* = -0x0000001C - MBEDTLS_ERR_THREADING_MUTEX_ERROR* = -0x0000001E -{.pop.} diff --git a/webrtc/mbedtls/timing.nim b/webrtc/mbedtls/timing.nim deleted file mode 100644 index 557a188..0000000 --- a/webrtc/mbedtls/timing.nim +++ /dev/null @@ -1,25 +0,0 @@ -{.compile: "./mbedtls/library/timing.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -type - mbedtls_timing_hr_time* {.bycopy.} = object - private_opaque*: array[4, uint64] - - mbedtls_timing_delay_context* {.bycopy.} = object - private_timer*: mbedtls_timing_hr_time - private_int_ms*: uint32 - private_fin_ms*: uint32 - -proc mbedtls_timing_get_timer*(val: ptr mbedtls_timing_hr_time; reset: cint): culong {. - importc, cdecl.} -proc mbedtls_timing_set_delay*(data: pointer; int_ms: uint32; fin_ms: uint32) {. - importc, cdecl.} -proc mbedtls_timing_get_delay*(data: pointer): cint {.importc, cdecl.} -proc mbedtls_timing_get_final_delay*(data: ptr mbedtls_timing_delay_context): uint32 {. - importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/version.nim b/webrtc/mbedtls/version.nim deleted file mode 100644 index 1851677..0000000 --- a/webrtc/mbedtls/version.nim +++ /dev/null @@ -1,14 +0,0 @@ -{.compile: "./mbedtls/library/version.c".} -{.compile: "./mbedtls/library/version_features.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -proc mbedtls_version_get_number*(): cuint {.importc, cdecl.} -proc mbedtls_version_get_string*(string: cstring) {.importc, cdecl.} -proc mbedtls_version_get_string_full*(string: cstring) {.importc, cdecl.} -proc mbedtls_version_check_feature*(feature: cstring): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/x509.nim b/webrtc/mbedtls/x509.nim deleted file mode 100644 index 4ea1f6b..0000000 --- a/webrtc/mbedtls/x509.nim +++ /dev/null @@ -1,212 +0,0 @@ -import "asn1" -import "pk" -import "md" - -{.compile: "./mbedtls/library/x509.c".} -{.compile: "./mbedtls/library/x509_create.c".} - -# const 'MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER' has unsupported value 'MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER' -# const 'MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER' has unsupported value 'MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER' -# const 'MBEDTLS_X509_EXT_KEY_USAGE' has unsupported value 'MBEDTLS_OID_X509_EXT_KEY_USAGE' -# const 'MBEDTLS_X509_EXT_CERTIFICATE_POLICIES' has unsupported value 'MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES' -# const 'MBEDTLS_X509_EXT_POLICY_MAPPINGS' has unsupported value 'MBEDTLS_OID_X509_EXT_POLICY_MAPPINGS' -# const 'MBEDTLS_X509_EXT_SUBJECT_ALT_NAME' has unsupported value 'MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME' -# const 'MBEDTLS_X509_EXT_ISSUER_ALT_NAME' has unsupported value 'MBEDTLS_OID_X509_EXT_ISSUER_ALT_NAME' -# const 'MBEDTLS_X509_EXT_SUBJECT_DIRECTORY_ATTRS' has unsupported value 'MBEDTLS_OID_X509_EXT_SUBJECT_DIRECTORY_ATTRS' -# const 'MBEDTLS_X509_EXT_BASIC_CONSTRAINTS' has unsupported value 'MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS' -# const 'MBEDTLS_X509_EXT_NAME_CONSTRAINTS' has unsupported value 'MBEDTLS_OID_X509_EXT_NAME_CONSTRAINTS' -# const 'MBEDTLS_X509_EXT_POLICY_CONSTRAINTS' has unsupported value 'MBEDTLS_OID_X509_EXT_POLICY_CONSTRAINTS' -# const 'MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE' has unsupported value 'MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE' -# const 'MBEDTLS_X509_EXT_CRL_DISTRIBUTION_POINTS' has unsupported value 'MBEDTLS_OID_X509_EXT_CRL_DISTRIBUTION_POINTS' -# const 'MBEDTLS_X509_EXT_INIHIBIT_ANYPOLICY' has unsupported value 'MBEDTLS_OID_X509_EXT_INIHIBIT_ANYPOLICY' -# const 'MBEDTLS_X509_EXT_FRESHEST_CRL' has unsupported value 'MBEDTLS_OID_X509_EXT_FRESHEST_CRL' -# const 'MBEDTLS_X509_EXT_NS_CERT_TYPE' has unsupported value 'MBEDTLS_OID_X509_EXT_NS_CERT_TYPE' -# proc 'mbedtls_x509_dn_get_next' skipped - static inline procs cannot work with '--noHeader | -H' -# const 'MBEDTLS_X509_SAFE_SNPRINTF' has unsupported value 'do { if (ret < 0 || (size_t) ret >= n) return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL; n -= (size_t) ret; p += (size_t) ret; } while (0)' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_X509_MAX_INTERMEDIATE_CA* = 8 - MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE* = -0x00002080 - MBEDTLS_ERR_X509_UNKNOWN_OID* = -0x00002100 - MBEDTLS_ERR_X509_INVALID_FORMAT* = -0x00002180 - MBEDTLS_ERR_X509_INVALID_VERSION* = -0x00002200 - MBEDTLS_ERR_X509_INVALID_SERIAL* = -0x00002280 - MBEDTLS_ERR_X509_INVALID_ALG* = -0x00002300 - MBEDTLS_ERR_X509_INVALID_NAME* = -0x00002380 - MBEDTLS_ERR_X509_INVALID_DATE* = -0x00002400 - MBEDTLS_ERR_X509_INVALID_SIGNATURE* = -0x00002480 - MBEDTLS_ERR_X509_INVALID_EXTENSIONS* = -0x00002500 - MBEDTLS_ERR_X509_UNKNOWN_VERSION* = -0x00002580 - MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG* = -0x00002600 - MBEDTLS_ERR_X509_SIG_MISMATCH* = -0x00002680 - MBEDTLS_ERR_X509_CERT_VERIFY_FAILED* = -0x00002700 - MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT* = -0x00002780 - MBEDTLS_ERR_X509_BAD_INPUT_DATA* = -0x00002800 - MBEDTLS_ERR_X509_ALLOC_FAILED* = -0x00002880 - MBEDTLS_ERR_X509_FILE_IO_ERROR* = -0x00002900 - MBEDTLS_ERR_X509_BUFFER_TOO_SMALL* = -0x00002980 - MBEDTLS_ERR_X509_FATAL_ERROR* = -0x00003000 - MBEDTLS_X509_BADCERT_EXPIRED* = 0x00000001 - MBEDTLS_X509_BADCERT_REVOKED* = 0x00000002 - MBEDTLS_X509_BADCERT_CN_MISMATCH* = 0x00000004 - MBEDTLS_X509_BADCERT_NOT_TRUSTED* = 0x00000008 - MBEDTLS_X509_BADCRL_NOT_TRUSTED* = 0x00000010 - MBEDTLS_X509_BADCRL_EXPIRED* = 0x00000020 - MBEDTLS_X509_BADCERT_MISSING* = 0x00000040 - MBEDTLS_X509_BADCERT_SKIP_VERIFY* = 0x00000080 - MBEDTLS_X509_BADCERT_OTHER* = 0x00000100 - MBEDTLS_X509_BADCERT_FUTURE* = 0x00000200 - MBEDTLS_X509_BADCRL_FUTURE* = 0x00000400 - MBEDTLS_X509_BADCERT_KEY_USAGE* = 0x00000800 - MBEDTLS_X509_BADCERT_EXT_KEY_USAGE* = 0x00001000 - MBEDTLS_X509_BADCERT_NS_CERT_TYPE* = 0x00002000 - MBEDTLS_X509_BADCERT_BAD_MD* = 0x00004000 - MBEDTLS_X509_BADCERT_BAD_PK* = 0x00008000 - MBEDTLS_X509_BADCERT_BAD_KEY* = 0x00010000 - MBEDTLS_X509_BADCRL_BAD_MD* = 0x00020000 - MBEDTLS_X509_BADCRL_BAD_PK* = 0x00040000 - MBEDTLS_X509_BADCRL_BAD_KEY* = 0x00080000 - MBEDTLS_X509_SAN_OTHER_NAME* = 0 - MBEDTLS_X509_SAN_RFC822_NAME* = 1 - MBEDTLS_X509_SAN_DNS_NAME* = 2 - MBEDTLS_X509_SAN_X400_ADDRESS_NAME* = 3 - MBEDTLS_X509_SAN_DIRECTORY_NAME* = 4 - MBEDTLS_X509_SAN_EDI_PARTY_NAME* = 5 - MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER* = 6 - MBEDTLS_X509_SAN_IP_ADDRESS* = 7 - MBEDTLS_X509_SAN_REGISTERED_ID* = 8 - MBEDTLS_X509_KU_DIGITAL_SIGNATURE* = (0x00000080) - MBEDTLS_X509_KU_NON_REPUDIATION* = (0x00000040) - MBEDTLS_X509_KU_KEY_ENCIPHERMENT* = (0x00000020) - MBEDTLS_X509_KU_DATA_ENCIPHERMENT* = (0x00000010) - MBEDTLS_X509_KU_KEY_AGREEMENT* = (0x00000008) - MBEDTLS_X509_KU_KEY_CERT_SIGN* = (0x00000004) - MBEDTLS_X509_KU_CRL_SIGN* = (0x00000002) - MBEDTLS_X509_KU_ENCIPHER_ONLY* = (0x00000001) - MBEDTLS_X509_KU_DECIPHER_ONLY* = (0x00008000) - MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT* = (0x00000080) - MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER* = (0x00000040) - MBEDTLS_X509_NS_CERT_TYPE_EMAIL* = (0x00000020) - MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING* = (0x00000010) - MBEDTLS_X509_NS_CERT_TYPE_RESERVED* = (0x00000008) - MBEDTLS_X509_NS_CERT_TYPE_SSL_CA* = (0x00000004) - MBEDTLS_X509_NS_CERT_TYPE_EMAIL_CA* = (0x00000002) - MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING_CA* = (0x00000001) - MBEDTLS_X509_FORMAT_DER* = 1 - MBEDTLS_X509_FORMAT_PEM* = 2 - MBEDTLS_X509_MAX_DN_NAME_SIZE* = 256 -type - mbedtls_x509_buf* = mbedtls_asn1_buf - mbedtls_x509_bitstring* = mbedtls_asn1_bitstring - mbedtls_x509_name* = mbedtls_asn1_named_data - mbedtls_x509_sequence* = mbedtls_asn1_sequence - mbedtls_x509_time* {.bycopy.} = object - year*: cint - mon*: cint - day*: cint - hour*: cint - min*: cint - sec*: cint - - Type_x509h1* {.bycopy.} = object - oid*: mbedtls_x509_buf - val*: mbedtls_x509_buf - - Union_x509h1* {.union, bycopy.} = object - hardware_module_name*: Type_x509h1 - - mbedtls_x509_san_other_name* {.bycopy.} = object - type_id*: mbedtls_x509_buf - value*: Union_x509h1 - - Union_x509h2* {.union, bycopy.} = object - other_name*: mbedtls_x509_san_other_name - directory_name*: mbedtls_x509_name - unstructured_name*: mbedtls_x509_buf - - mbedtls_x509_subject_alternative_name* {.bycopy.} = object - `type`*: cint - san*: Union_x509h2 - -proc mbedtls_x509_dn_gets*(buf: cstring; size: uint; dn: ptr mbedtls_x509_name): cint {. - importc, cdecl.} -proc mbedtls_x509_serial_gets*(buf: cstring; size: uint; - serial: ptr mbedtls_x509_buf): cint {.importc, - cdecl.} -proc mbedtls_x509_time_is_past*(to: ptr mbedtls_x509_time): cint {.importc, - cdecl.} -proc mbedtls_x509_time_is_future*(`from`: ptr mbedtls_x509_time): cint {. - importc, cdecl.} -proc mbedtls_x509_parse_subject_alt_name*(san_buf: ptr mbedtls_x509_buf; - san: ptr mbedtls_x509_subject_alternative_name): cint {.importc, cdecl.} -proc mbedtls_x509_free_subject_alt_name*( - san: ptr mbedtls_x509_subject_alternative_name) {.importc, cdecl.} -proc mbedtls_x509_get_name*(p: ptr ptr byte; `end`: ptr byte; - cur: ptr mbedtls_x509_name): cint {.importc, cdecl.} -proc mbedtls_x509_get_alg_null*(p: ptr ptr byte; `end`: ptr byte; - alg: ptr mbedtls_x509_buf): cint {.importc, - cdecl.} -proc mbedtls_x509_get_alg*(p: ptr ptr byte; `end`: ptr byte; - alg: ptr mbedtls_x509_buf; - params: ptr mbedtls_x509_buf): cint {.importc, cdecl.} -proc mbedtls_x509_get_rsassa_pss_params*(params: ptr mbedtls_x509_buf; - md_alg: ptr mbedtls_md_type_t; mgf_md: ptr mbedtls_md_type_t; - salt_len: ptr cint): cint {.importc, cdecl.} -proc mbedtls_x509_get_sig*(p: ptr ptr byte; `end`: ptr byte; - sig: ptr mbedtls_x509_buf): cint {.importc, cdecl.} -proc mbedtls_x509_get_sig_alg*(sig_oid: ptr mbedtls_x509_buf; - sig_params: ptr mbedtls_x509_buf; - md_alg: ptr mbedtls_md_type_t; - pk_alg: ptr mbedtls_pk_type_t; - sig_opts: ptr pointer): cint {.importc, cdecl.} -proc mbedtls_x509_get_time*(p: ptr ptr byte; `end`: ptr byte; - t: ptr mbedtls_x509_time): cint {.importc, cdecl.} -proc mbedtls_x509_get_serial*(p: ptr ptr byte; `end`: ptr byte; - serial: ptr mbedtls_x509_buf): cint {.importc, - cdecl.} -proc mbedtls_x509_get_ext*(p: ptr ptr byte; `end`: ptr byte; - ext: ptr mbedtls_x509_buf; tag: cint): cint {. - importc, cdecl.} -proc mbedtls_x509_sig_alg_gets*(buf: cstring; size: uint; - sig_oid: ptr mbedtls_x509_buf; - pk_alg: mbedtls_pk_type_t; - md_alg: mbedtls_md_type_t; sig_opts: pointer): cint {. - importc, cdecl.} -proc mbedtls_x509_key_size_helper*(buf: cstring; buf_size: uint; name: cstring): cint {. - importc, cdecl.} -proc mbedtls_x509_string_to_names*(head: ptr ptr mbedtls_asn1_named_data; - name: cstring): cint {.importc, cdecl.} -proc mbedtls_x509_set_extension*(head: ptr ptr mbedtls_asn1_named_data; - oid: cstring; oid_len: uint; critical: cint; - val: ptr byte; val_len: uint): cint {. - importc, cdecl.} -proc mbedtls_x509_write_extensions*(p: ptr ptr byte; start: ptr byte; - first: ptr mbedtls_asn1_named_data): cint {. - importc, cdecl.} -proc mbedtls_x509_write_names*(p: ptr ptr byte; start: ptr byte; - first: ptr mbedtls_asn1_named_data): cint {. - importc, cdecl.} -proc mbedtls_x509_write_sig*(p: ptr ptr byte; start: ptr byte; oid: cstring; - oid_len: uint; sig: ptr byte; size: uint): cint {. - importc, cdecl.} -proc mbedtls_x509_get_ns_cert_type*(p: ptr ptr byte; `end`: ptr byte; - ns_cert_type: ptr byte): cint {.importc, - cdecl.} -proc mbedtls_x509_get_key_usage*(p: ptr ptr byte; `end`: ptr byte; - key_usage: ptr cuint): cint {.importc, cdecl.} -proc mbedtls_x509_get_subject_alt_name*(p: ptr ptr byte; `end`: ptr byte; - subject_alt_name: ptr mbedtls_x509_sequence): cint {.importc, cdecl.} -proc mbedtls_x509_info_subject_alt_name*(buf: ptr cstring; size: ptr uint; - subject_alt_name: ptr mbedtls_x509_sequence; prefix: cstring): cint {. - importc, cdecl.} -proc mbedtls_x509_info_cert_type*(buf: ptr cstring; size: ptr uint; - ns_cert_type: byte): cint {.importc, cdecl.} -proc mbedtls_x509_info_key_usage*(buf: ptr cstring; size: ptr uint; - key_usage: cuint): cint {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/x509_crl.nim b/webrtc/mbedtls/x509_crl.nim deleted file mode 100644 index f9b7a1d..0000000 --- a/webrtc/mbedtls/x509_crl.nim +++ /dev/null @@ -1,49 +0,0 @@ -import "x509" -import "pk" -import "md" - -{.compile: "./mbedtls/library/x509_crl.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -type - mbedtls_x509_crl_entry* {.bycopy.} = object - raw*: mbedtls_x509_buf - serial*: mbedtls_x509_buf - revocation_date*: mbedtls_x509_time - entry_ext*: mbedtls_x509_buf - next*: ptr mbedtls_x509_crl_entry - - mbedtls_x509_crl* {.bycopy.} = object - raw*: mbedtls_x509_buf - tbs*: mbedtls_x509_buf - version*: cint - sig_oid*: mbedtls_x509_buf - issuer_raw*: mbedtls_x509_buf - issuer*: mbedtls_x509_name - this_update*: mbedtls_x509_time - next_update*: mbedtls_x509_time - entry*: mbedtls_x509_crl_entry - crl_ext*: mbedtls_x509_buf - private_sig_oid2*: mbedtls_x509_buf - private_sig*: mbedtls_x509_buf - private_sig_md*: mbedtls_md_type_t - private_sig_pk*: mbedtls_pk_type_t - private_sig_opts*: pointer - next*: ptr mbedtls_x509_crl - -proc mbedtls_x509_crl_parse_der*(chain: ptr mbedtls_x509_crl; buf: ptr byte; - buflen: uint): cint {.importc, cdecl.} -proc mbedtls_x509_crl_parse*(chain: ptr mbedtls_x509_crl; buf: ptr byte; - buflen: uint): cint {.importc, cdecl.} -proc mbedtls_x509_crl_parse_file*(chain: ptr mbedtls_x509_crl; path: cstring): cint {. - importc, cdecl.} -proc mbedtls_x509_crl_info*(buf: cstring; size: uint; prefix: cstring; - crl: ptr mbedtls_x509_crl): cint {.importc, cdecl.} -proc mbedtls_x509_crl_init*(crl: ptr mbedtls_x509_crl) {.importc, cdecl.} -proc mbedtls_x509_crl_free*(crl: ptr mbedtls_x509_crl) {.importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/x509_crt.nim b/webrtc/mbedtls/x509_crt.nim deleted file mode 100644 index bdd055c..0000000 --- a/webrtc/mbedtls/x509_crt.nim +++ /dev/null @@ -1,194 +0,0 @@ -import "x509" -import "x509_crl" -import "asn1" -import "bignum" -import "md" -import "pk" - -{.compile: "./mbedtls/library/x509_crt.c".} -{.compile: "./mbedtls/library/x509write_crt.c".} - -# const 'MBEDTLS_X509_CRT_ERROR_INFO_LIST' has unsupported value 'X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_EXPIRED, "MBEDTLS_X509_BADCERT_EXPIRED", "The certificate validity has expired") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_REVOKED, "MBEDTLS_X509_BADCERT_REVOKED", "The certificate has been revoked (is on a CRL)") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_CN_MISMATCH, "MBEDTLS_X509_BADCERT_CN_MISMATCH", "The certificate Common Name (CN) does not match with the expected CN") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_NOT_TRUSTED, "MBEDTLS_X509_BADCERT_NOT_TRUSTED", "The certificate is not correctly signed by the trusted CA") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_NOT_TRUSTED, "MBEDTLS_X509_BADCRL_NOT_TRUSTED", "The CRL is not correctly signed by the trusted CA") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_EXPIRED, "MBEDTLS_X509_BADCRL_EXPIRED", "The CRL is expired") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_MISSING, "MBEDTLS_X509_BADCERT_MISSING", "Certificate was missing") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_SKIP_VERIFY, "MBEDTLS_X509_BADCERT_SKIP_VERIFY", "Certificate verification was skipped") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_OTHER, "MBEDTLS_X509_BADCERT_OTHER", "Other reason (can be used by verify callback)") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_FUTURE, "MBEDTLS_X509_BADCERT_FUTURE", "The certificate validity starts in the future") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_FUTURE, "MBEDTLS_X509_BADCRL_FUTURE", "The CRL is from the future") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_KEY_USAGE, "MBEDTLS_X509_BADCERT_KEY_USAGE", "Usage does not match the keyUsage extension") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_EXT_KEY_USAGE, "MBEDTLS_X509_BADCERT_EXT_KEY_USAGE", "Usage does not match the extendedKeyUsage extension") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_NS_CERT_TYPE, "MBEDTLS_X509_BADCERT_NS_CERT_TYPE", "Usage does not match the nsCertType extension") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_MD, "MBEDTLS_X509_BADCERT_BAD_MD", "The certificate is signed with an unacceptable hash.") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_PK, "MBEDTLS_X509_BADCERT_BAD_PK", "The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA).") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_KEY, "MBEDTLS_X509_BADCERT_BAD_KEY", "The certificate is signed with an unacceptable key (eg bad curve, RSA too short).") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_MD, "MBEDTLS_X509_BADCRL_BAD_MD", "The CRL is signed with an unacceptable hash.") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_PK, "MBEDTLS_X509_BADCRL_BAD_PK", "The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA).") X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_KEY, "MBEDTLS_X509_BADCRL_BAD_KEY", "The CRL is signed with an unacceptable key (eg bad curve, RSA too short).")' -# const 'MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE' has unsupported value '(MBEDTLS_X509_MAX_INTERMEDIATE_CA + 2)' -# proc 'mbedtls_x509_crt_has_ext_type' skipped - static inline procs cannot work with '--noHeader | -H' - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -const - MBEDTLS_X509_CRT_VERSION_1* = 0 - MBEDTLS_X509_CRT_VERSION_2* = 1 - MBEDTLS_X509_CRT_VERSION_3* = 2 - MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN* = 20 - MBEDTLS_X509_RFC5280_UTC_TIME_LEN* = 15 - MBEDTLS_X509_MAX_FILE_PATH_LEN* = 512 -type - mbedtls_x509_crt* {.bycopy.} = object - private_own_buffer*: cint - raw*: mbedtls_x509_buf - tbs*: mbedtls_x509_buf - version*: cint - serial*: mbedtls_x509_buf - sig_oid*: mbedtls_x509_buf - issuer_raw*: mbedtls_x509_buf - subject_raw*: mbedtls_x509_buf - issuer*: mbedtls_x509_name - subject*: mbedtls_x509_name - valid_from*: mbedtls_x509_time - valid_to*: mbedtls_x509_time - pk_raw*: mbedtls_x509_buf - pk*: mbedtls_pk_context - issuer_id*: mbedtls_x509_buf - subject_id*: mbedtls_x509_buf - v3_ext*: mbedtls_x509_buf - subject_alt_names*: mbedtls_x509_sequence - certificate_policies*: mbedtls_x509_sequence - private_ext_types*: cint - private_ca_istrue*: cint - private_max_pathlen*: cint - private_key_usage*: cuint - ext_key_usage*: mbedtls_x509_sequence - private_ns_cert_type*: byte - private_sig*: mbedtls_x509_buf - private_sig_md*: mbedtls_md_type_t - private_sig_pk*: mbedtls_pk_type_t - private_sig_opts*: pointer - next*: ptr mbedtls_x509_crt - - mbedtls_x509_crt_profile* {.bycopy.} = object - allowed_mds*: uint32 - allowed_pks*: uint32 - allowed_curves*: uint32 - rsa_min_bitlen*: uint32 - - mbedtls_x509write_cert* {.bycopy.} = object - private_version*: cint - private_serial*: array[20, byte] - private_serial_len*: uint - private_subject_key*: ptr mbedtls_pk_context - private_issuer_key*: ptr mbedtls_pk_context - private_subject*: ptr mbedtls_asn1_named_data - private_issuer*: ptr mbedtls_asn1_named_data - private_md_alg*: mbedtls_md_type_t - private_not_before*: array[15 + typeof(15)(1), cchar] - private_not_after*: array[15 + typeof(15)(1), cchar] - private_extensions*: ptr mbedtls_asn1_named_data - - mbedtls_x509_crt_verify_chain_item* {.bycopy.} = object - private_crt*: ptr mbedtls_x509_crt - private_flags*: uint32 - - mbedtls_x509_crt_verify_chain* {.bycopy.} = object - private_items*: array[(8 + typeof(8)(2)), mbedtls_x509_crt_verify_chain_item] - private_len*: cuint - - mbedtls_x509_crt_restart_ctx* = object - mbedtls_x509_crt_ext_cb_t* = proc (p_ctx: pointer; crt: ptr mbedtls_x509_crt; - oid: ptr mbedtls_x509_buf; critical: cint; - p: ptr byte; `end`: ptr byte): cint {. - cdecl.} - mbedtls_x509_crt_ca_cb_t* = proc (p_ctx: pointer; child: ptr mbedtls_x509_crt; - candidate_cas: ptr ptr mbedtls_x509_crt): cint {. - cdecl.} -var - mbedtls_x509_crt_profile_default* {.importc.}: mbedtls_x509_crt_profile - mbedtls_x509_crt_profile_next* {.importc.}: mbedtls_x509_crt_profile - mbedtls_x509_crt_profile_suiteb* {.importc.}: mbedtls_x509_crt_profile - mbedtls_x509_crt_profile_none* {.importc.}: mbedtls_x509_crt_profile -proc mbedtls_x509_crt_parse_der*(chain: ptr mbedtls_x509_crt; buf: ptr byte; - buflen: uint): cint {.importc, cdecl.} -proc mbedtls_x509_crt_parse_der_with_ext_cb*(chain: ptr mbedtls_x509_crt; - buf: ptr byte; buflen: uint; make_copy: cint; - cb: mbedtls_x509_crt_ext_cb_t; p_ctx: pointer): cint {.importc, cdecl.} -proc mbedtls_x509_crt_parse_der_nocopy*(chain: ptr mbedtls_x509_crt; - buf: ptr byte; buflen: uint): cint {. - importc, cdecl.} -proc mbedtls_x509_crt_parse*(chain: ptr mbedtls_x509_crt; buf: ptr byte; - buflen: uint): cint {.importc, cdecl.} -proc mbedtls_x509_crt_parse_file*(chain: ptr mbedtls_x509_crt; path: cstring): cint {. - importc, cdecl.} -proc mbedtls_x509_crt_parse_path*(chain: ptr mbedtls_x509_crt; path: cstring): cint {. - importc, cdecl.} -proc mbedtls_x509_crt_info*(buf: cstring; size: uint; prefix: cstring; - crt: ptr mbedtls_x509_crt): cint {.importc, cdecl.} -proc mbedtls_x509_crt_verify_info*(buf: cstring; size: uint; prefix: cstring; - flags: uint32): cint {.importc, cdecl.} -proc mbedtls_x509_crt_verify*(crt: ptr mbedtls_x509_crt; - trust_ca: ptr mbedtls_x509_crt; - ca_crl: ptr mbedtls_x509_crl; cn: cstring; - flags: ptr uint32; f_vrfy: proc (a1: pointer; - a2: ptr mbedtls_x509_crt; a3: cint; a4: ptr uint32): cint {.cdecl.}; - p_vrfy: pointer): cint {.importc, cdecl.} -proc mbedtls_x509_crt_verify_with_profile*(crt: ptr mbedtls_x509_crt; - trust_ca: ptr mbedtls_x509_crt; ca_crl: ptr mbedtls_x509_crl; - profile: ptr mbedtls_x509_crt_profile; cn: cstring; flags: ptr uint32; - f_vrfy: proc (a1: pointer; a2: ptr mbedtls_x509_crt; a3: cint; - a4: ptr uint32): cint {.cdecl.}; p_vrfy: pointer): cint {. - importc, cdecl.} -proc mbedtls_x509_crt_verify_restartable*(crt: ptr mbedtls_x509_crt; - trust_ca: ptr mbedtls_x509_crt; ca_crl: ptr mbedtls_x509_crl; - profile: ptr mbedtls_x509_crt_profile; cn: cstring; flags: ptr uint32; - f_vrfy: proc (a1: pointer; a2: ptr mbedtls_x509_crt; a3: cint; - a4: ptr uint32): cint {.cdecl.}; p_vrfy: pointer; - rs_ctx: ptr mbedtls_x509_crt_restart_ctx): cint {.importc, cdecl.} -proc mbedtls_x509_crt_check_key_usage*(crt: ptr mbedtls_x509_crt; usage: cuint): cint {. - importc, cdecl.} -proc mbedtls_x509_crt_check_extended_key_usage*(crt: ptr mbedtls_x509_crt; - usage_oid: cstring; usage_len: uint): cint {.importc, cdecl.} -proc mbedtls_x509_crt_is_revoked*(crt: ptr mbedtls_x509_crt; - crl: ptr mbedtls_x509_crl): cint {.importc, - cdecl.} -proc mbedtls_x509_crt_init*(crt: ptr mbedtls_x509_crt) {.importc, cdecl.} -proc mbedtls_x509_crt_free*(crt: ptr mbedtls_x509_crt) {.importc, cdecl.} -proc mbedtls_x509write_crt_init*(ctx: ptr mbedtls_x509write_cert) {.importc, - cdecl.} -proc mbedtls_x509write_crt_set_version*(ctx: ptr mbedtls_x509write_cert; - version: cint) {.importc, cdecl.} -proc mbedtls_x509write_crt_set_serial*(ctx: ptr mbedtls_x509write_cert; - serial: ptr mbedtls_mpi): cint {.importc, - cdecl.} -proc mbedtls_x509write_crt_set_serial_raw*(ctx: ptr mbedtls_x509write_cert; - serial: ptr byte; serial_len: uint): cint {.importc, cdecl.} -proc mbedtls_x509write_crt_set_validity*(ctx: ptr mbedtls_x509write_cert; - not_before: cstring; not_after: cstring): cint {.importc, cdecl.} -proc mbedtls_x509write_crt_set_issuer_name*(ctx: ptr mbedtls_x509write_cert; - issuer_name: cstring): cint {.importc, cdecl.} -proc mbedtls_x509write_crt_set_subject_name*(ctx: ptr mbedtls_x509write_cert; - subject_name: cstring): cint {.importc, cdecl.} -proc mbedtls_x509write_crt_set_subject_key*(ctx: ptr mbedtls_x509write_cert; - key: ptr mbedtls_pk_context) {.importc, cdecl.} -proc mbedtls_x509write_crt_set_issuer_key*(ctx: ptr mbedtls_x509write_cert; - key: ptr mbedtls_pk_context) {.importc, cdecl.} -proc mbedtls_x509write_crt_set_md_alg*(ctx: ptr mbedtls_x509write_cert; - md_alg: mbedtls_md_type_t) {.importc, - cdecl.} -proc mbedtls_x509write_crt_set_extension*(ctx: ptr mbedtls_x509write_cert; - oid: cstring; oid_len: uint; critical: cint; val: ptr byte; val_len: uint): cint {. - importc, cdecl.} -proc mbedtls_x509write_crt_set_basic_constraints*( - ctx: ptr mbedtls_x509write_cert; is_ca: cint; max_pathlen: cint): cint {. - importc, cdecl.} -proc mbedtls_x509write_crt_set_subject_key_identifier*( - ctx: ptr mbedtls_x509write_cert): cint {.importc, cdecl.} -proc mbedtls_x509write_crt_set_authority_key_identifier*( - ctx: ptr mbedtls_x509write_cert): cint {.importc, cdecl.} -proc mbedtls_x509write_crt_set_key_usage*(ctx: ptr mbedtls_x509write_cert; - key_usage: cuint): cint {.importc, cdecl.} -proc mbedtls_x509write_crt_set_ext_key_usage*(ctx: ptr mbedtls_x509write_cert; - exts: ptr mbedtls_asn1_sequence): cint {.importc, cdecl.} -proc mbedtls_x509write_crt_set_ns_cert_type*(ctx: ptr mbedtls_x509write_cert; - ns_cert_type: byte): cint {.importc, cdecl.} -proc mbedtls_x509write_crt_free*(ctx: ptr mbedtls_x509write_cert) {.importc, - cdecl.} -proc mbedtls_x509write_crt_der*(ctx: ptr mbedtls_x509write_cert; - buf: ptr byte; size: uint; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -proc mbedtls_x509write_crt_pem*(ctx: ptr mbedtls_x509write_cert; - buf: ptr byte; size: uint; f_rng: proc ( - a1: pointer; a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {. - importc, cdecl.} -{.pop.} diff --git a/webrtc/mbedtls/x509_csr.nim b/webrtc/mbedtls/x509_csr.nim deleted file mode 100644 index 99be885..0000000 --- a/webrtc/mbedtls/x509_csr.nim +++ /dev/null @@ -1,83 +0,0 @@ -import "x509" -import "asn1" -import "pk" -import "md" - -{.compile: "./mbedtls/library/x509_csr.c".} -{.compile: "./mbedtls/library/x509write_csr.c".} - -{.push hint[ConvFromXtoItselfNotNeeded]: off.} - -{.experimental: "codeReordering".} -{.passc: "-I./mbedtls/include".} -{.passc: "-I./mbedtls/library".} - -type - mbedtls_x509_csr* {.bycopy.} = object - raw*: mbedtls_x509_buf - cri*: mbedtls_x509_buf - version*: cint - subject_raw*: mbedtls_x509_buf - subject*: mbedtls_x509_name - pk*: mbedtls_pk_context - key_usage*: cuint - ns_cert_type*: byte - subject_alt_names*: mbedtls_x509_sequence - private_ext_types*: cint - sig_oid*: mbedtls_x509_buf - private_sig*: mbedtls_x509_buf - private_sig_md*: mbedtls_md_type_t - private_sig_pk*: mbedtls_pk_type_t - private_sig_opts*: pointer - - mbedtls_x509write_csr* {.bycopy.} = object - private_key*: ptr mbedtls_pk_context - private_subject*: ptr mbedtls_asn1_named_data - private_md_alg*: mbedtls_md_type_t - private_extensions*: ptr mbedtls_asn1_named_data - - mbedtls_x509_san_list* {.bycopy.} = object - node*: mbedtls_x509_subject_alternative_name - next*: ptr mbedtls_x509_san_list - -proc mbedtls_x509_csr_parse_der*(csr: ptr mbedtls_x509_csr; buf: ptr byte; - buflen: uint): cint {.importc, cdecl.} -proc mbedtls_x509_csr_parse*(csr: ptr mbedtls_x509_csr; buf: ptr byte; - buflen: uint): cint {.importc, cdecl.} -proc mbedtls_x509_csr_parse_file*(csr: ptr mbedtls_x509_csr; path: cstring): cint {. - importc, cdecl.} -proc mbedtls_x509_csr_info*(buf: cstring; size: uint; prefix: cstring; - csr: ptr mbedtls_x509_csr): cint {.importc, cdecl.} -proc mbedtls_x509_csr_init*(csr: ptr mbedtls_x509_csr) {.importc, cdecl.} -proc mbedtls_x509_csr_free*(csr: ptr mbedtls_x509_csr) {.importc, cdecl.} -proc mbedtls_x509write_csr_init*(ctx: ptr mbedtls_x509write_csr) {.importc, - cdecl.} -proc mbedtls_x509write_csr_set_subject_name*(ctx: ptr mbedtls_x509write_csr; - subject_name: cstring): cint {.importc, cdecl.} -proc mbedtls_x509write_csr_set_key*(ctx: ptr mbedtls_x509write_csr; - key: ptr mbedtls_pk_context) {.importc, - cdecl.} -proc mbedtls_x509write_csr_set_md_alg*(ctx: ptr mbedtls_x509write_csr; - md_alg: mbedtls_md_type_t) {.importc, - cdecl.} -proc mbedtls_x509write_csr_set_key_usage*(ctx: ptr mbedtls_x509write_csr; - key_usage: byte): cint {.importc, cdecl.} -proc mbedtls_x509write_csr_set_subject_alternative_name*( - ctx: ptr mbedtls_x509write_csr; san_list: ptr mbedtls_x509_san_list): cint {. - importc, cdecl.} -proc mbedtls_x509write_csr_set_ns_cert_type*(ctx: ptr mbedtls_x509write_csr; - ns_cert_type: byte): cint {.importc, cdecl.} -proc mbedtls_x509write_csr_set_extension*(ctx: ptr mbedtls_x509write_csr; - oid: cstring; oid_len: uint; critical: cint; val: ptr byte; val_len: uint): cint {. - importc, cdecl.} -proc mbedtls_x509write_csr_free*(ctx: ptr mbedtls_x509write_csr) {.importc, - cdecl.} -proc mbedtls_x509write_csr_der*(ctx: ptr mbedtls_x509write_csr; buf: ptr byte; - size: uint; f_rng: proc (a1: pointer; - a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, - cdecl.} -proc mbedtls_x509write_csr_pem*(ctx: ptr mbedtls_x509write_csr; buf: ptr byte; - size: uint; f_rng: proc (a1: pointer; - a2: ptr byte; a3: uint): cint {.cdecl.}; p_rng: pointer): cint {.importc, - cdecl.} -{.pop.} From 70531d4117233956fcbb811e2129478f0cc3b69f Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 16 Jun 2023 17:34:24 +0200 Subject: [PATCH 14/66] Certificate & Keys generated using mbedtls --- webrtc/dtls.nim | 353 ++++++++++++++---------------------------------- 1 file changed, 105 insertions(+), 248 deletions(-) diff --git a/webrtc/dtls.nim b/webrtc/dtls.nim index 3e6230b..1d2a2f0 100644 --- a/webrtc/dtls.nim +++ b/webrtc/dtls.nim @@ -7,252 +7,109 @@ # This file may not be copied, modified, or distributed except according to # those terms. -import mbedtls/ssl +import std/times +import chronos +import webrtc_connection -# import std/[openssl, os] -# import posix -# import chronos, chronicles -# import stew/[byteutils, ptrops] -# -# export chronicles -# -# logScope: -# topics = "webrtc dtls" -# -# # Missing openssl procs things -# const -# BIO_NOCLOSE = 0x0 -# #BIO_CLOSE = 0x1 -# BIO_CTRL_DGRAM_SET_CONNECTED = 32 -# BIO_CTRL_DGRAM_GET_PEER = 46 -# DTLS_CTRL_GET_TIMEOUT = 73 -# BIO_C_SET_FD = 104 -# -# proc DTLS_client_method(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} -# proc DTLS_server_method(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.} -# proc BIO_new_dgram(fd: SocketHandle, closeFlag: int): BIO {.cdecl, dynlib: DLLUtilName, importc.} -# proc SSL_get_rbio(ssl: SslPtr): BIO {.cdecl, dynlib: DLLSSLName, importc.} -# proc RAND_bytes(buf: pointer, length: int): int {.cdecl, dynlib: DLLSSLName, importc.} -# proc DTLSv1_listen(ssl: SslPtr, peer: ptr): int {.cdecl, dynlib: DLLSSLName, importc.} -# proc SSL_CTX_set_cookie_generate_cb(ctx: SslCtx, cb: proc (ssl: SslPtr, cookie: ptr byte, cookieLen: ptr int): int {.cdecl.}) {.cdecl, dynlib: DLLSSLName, importc.} -# proc SSL_CTX_set_cookie_verify_cb(ctx: SslCtx, cb: proc (ssl: SslPtr, cookie: ptr byte, cookieLen: int): int {.cdecl.}) {.cdecl, dynlib: DLLSSLName, importc.} -# # --- openssl -# -# type -# DtlsSocket = ref object -# udp: DatagramTransport -# gotData: AsyncEvent -# sslCtx: SslCtx -# ctxIsView: bool -# ssl: SslPtr -# -# proc waitForData(socket: DtlsSocket) {.async.} = -# socket.gotData.clear() -# var timeout: Timeval -# if (SSL_ctrl(socket.ssl, DTLS_CTRL_GET_TIMEOUT, 0, addr timeout) == 1): -# let -# momentTimeout = seconds(clong(timeout.tv_sec)) + nanoseconds(timeout.tv_usec) -# fut = socket.gotData.wait() -# if not await fut.withTimeout(momentTimeout): -# fut.cancel -# else: -# await socket.gotData.wait() -# -# template wrapSslCallRes(dtlsSocket, call: untyped): untyped = -# block: -# var err: type(call) -# while true: -# err = call -# if err <= 0: -# let openSslErr = SSL_get_error(dtlsSocket.ssl, cint(err)) -# if openSslErr in [SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE]: -# await dtlsSocket.waitForData() -# continue -# elif openSslErr == SSL_ERROR_SYSCALL: -# let err = osLastError() -# if cint(err) == EAGAIN: -# await dtlsSocket.waitForData() -# continue -# raiseTransportOsError(err) -# let errorMsg = ERR_error_string(culong(ERR_peek_last_error()), nil) -# raise ValueError.newException("openssl error: " & $errorMsg) -# break -# err -# -# template wrapSslCall(dtlsSocket, call: untyped) = -# discard wrapSslCallRes(dtlsSocket, call) -# -# proc fromSAddr(storeAddr: Sockaddr_storage): TransportAddress = -# let size = -# if int(storeAddr.ss_family) == ord(Domain.AF_INET): -# sizeof(Sockaddr_in) -# elif int(storeAddr.ss_family) == ord(Domain.AF_INET6): -# sizeof(Sockaddr_in6) -# elif int(storeAddr.ss_family) == ord(Domain.AF_UNIX): -# sizeof(Sockaddr_storage) -# else: -1 -# fromSAddr(addr storeAddr, SockLen(size), result) -# -# var cookieSecret: array[32, byte] -# doAssert RAND_bytes(addr cookieSecret[0], cookieSecret.len) > 0 -# -# proc generateSslCookie(ssl: SslPtr, cookie: ptr byte, cookieLen: ptr int): int {.cdecl.} = -# var peerSockaddr: Sockaddr_storage -# if BIO_ctrl(SSL_get_rbio(ssl), BIO_CTRL_DGRAM_GET_PEER, 0, cast[cstring](addr peerSockaddr)) <= 0: -# return 0 -# -# let transportAddress = fromSAddr(peerSockaddr) -# if -# HMAC(EVP_sha1(), -# addr cookieSecret[0], cint(cookieSecret.len), -# cast[cstring](addr transportAddress), csize_t(sizeof(TransportAddress)), -# cast[cstring](cookie), cast[ptr cuint](cookieLen)) == nil: -# 0 -# else: -# 1 -# -# proc verifySslCookie(ssl: SslPtr, cookie: ptr byte, cookieLen: int): int {.cdecl.} = -# var peerSockaddr: Sockaddr_storage -# if BIO_ctrl(SSL_get_rbio(ssl), BIO_CTRL_DGRAM_GET_PEER, 0, cast[cstring](addr peerSockaddr)) <= 0: -# return 0 -# -# let transportAddress = fromSAddr(peerSockaddr) -# var -# buffer: array[1024, byte] -# bufferLength: cuint -# if -# HMAC(EVP_sha1(), -# addr cookieSecret[0], cint(cookieSecret.len), -# cast[cstring](addr transportAddress), csize_t(sizeof(TransportAddress)), -# cast[cstring](addr buffer[0]), addr bufferLength) == nil: -# return 0 -# -# if bufferLength != cuint(cookieLen): return 0 -# if cookie.makeOpenArray(byte, cookieLen) == buffer[0 ..< bufferLength]: -# 1 -# else: -# 0 -# -# proc createDtlsSocket( -# localAddress = AnyAddress, -# remoteAddress = AnyAddress, -# flags: set[ServerFlags] = {NoAutoRead}): DtlsSocket = -# -# let gotData = newAsyncEvent() -# proc callback(transp: DatagramTransport, remote: TransportAddress) {.async.} = discard -# proc callback2(udata: pointer) = -# gotData.fire() -# let datagram = newDatagramTransport( -# callback, -# local = localAddress, -# remote = remoteAddress, -# flags = flags) -# addReader(datagram.fd, callback2) -# return DtlsSocket(udp: datagram, gotData: gotData) -# -# -# proc createDtlsServer*(host: TransportAddress): Future[DtlsSocket] {.async.} = -# result = createDtlsSocket( -# localAddress = host, -# flags = {NoAutoRead, ReuseAddr} -# ) -# -# result.sslCtx = SSL_CTX_new(DTLS_server_method()) -# #TODO if we close the server with connections alive, -# #they have a ref to this ctx -# -# #TODO handle certificates -# echo SSL_CTX_use_certificate_file(result.sslCtx, "certs/server-cert.pem", SSL_FILETYPE_PEM) -# echo SSL_CTX_use_PrivateKey_file(result.sslCtx, "certs/server-key.pem", SSL_FILETYPE_PEM) -# SSL_CTX_set_cookie_generate_cb(result.sslCtx, generateSslCookie) -# SSL_CTX_set_cookie_verify_cb(result.sslCtx, verifySslCookie) -# -# proc accept*(sock: DtlsSocket): Future[DtlsSocket] {.async.} = -# let -# ctx = sock.sslCtx -# ssl = SSL_new(ctx) -# bio = BIO_new_dgram(SocketHandle(sock.udp.fd), BIO_NOCLOSE) -# -# sslSetBio(ssl, bio, bio) -# -# var clientSockAddr: Sockaddr_storage -# doAssert isNil(sock.ssl) -# sock.ssl = ssl -# wrapSslCall(sock, DTLSv1_listen(ssl, addr clientSockAddr)) -# sock.ssl = nil -# let clientAddr = fromSAddr(clientSockAddr) -# -# # create new socket -# result = createDtlsSocket( -# localAddress = sock.udp.localAddress, -# remoteAddress = clientAddr, -# flags = {NoAutoRead, ReuseAddr} -# ) -# -# let sockHandle = SocketHandle(result.udp.fd) -# doAssert BIO_ctrl(bio, BIO_C_SET_FD, 0, cast[cstring](addr sockHandle)) > 0 -# doAssert BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_CONNECTED, 0, cast[cstring](addr clientSockAddr)) > 0 -# -# result.sslCtx = ctx -# result.ssl = ssl -# result.ctxIsView = true -# wrapSslCall(result, SSL_accept(ssl)) -# -# proc connect*(address: TransportAddress): Future[DtlsSocket] {.async.} = -# result = createDtlsSocket( -# remoteAddress = address -# ) -# -# let -# ctx = SSL_CTX_new(DTLS_client_method()) -# ssl = SSL_new(ctx) -# bio = BIO_new_dgram(SocketHandle(result.udp.fd), BIO_NOCLOSE) -# -# #TODO handle certs -# echo SSL_CTX_use_certificate_file(ctx, "certs/client-cert.pem", SSL_FILETYPE_PEM) -# echo SSL_CTX_use_PrivateKey_file(ctx, "certs/client-key.pem", SSL_FILETYPE_PEM) -# echo SSL_CTX_check_private_key(ctx) -# -# result.sslCtx = ctx -# result.ssl = ssl -# var slen: SockLen -# var remoteSaddr: Sockaddr_storage -# toSAddr(address, remoteSaddr, slen) -# doAssert BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_CONNECTED, 0, cast[cstring](addr remoteSaddr)) > 0 -# sslSetBio(ssl, bio, bio) -# wrapSslCall(result, SSL_connect(ssl)) -# -# proc write*(sock: DtlsSocket, data: seq[byte]) {.async.} = -# wrapSslCall(sock, SSL_write(sock.ssl, cast[cstring](addr data[0]), data.len)) -# -# proc read*(sock: DtlsSocket): Future[seq[byte]] {.async.} = -# result = newSeq[byte](1000) -# let length = wrapSslCallRes(sock, SSL_read(sock.ssl, cast[cstring](addr result[0]), result.len)) -# result.setLen(length) -# -# proc close*(sock: DtlsSocket) {.async.} = -# if not isNil(sock.ssl): -# let shutdownRes = SSL_shutdown(sock.ssl) -# if shutdownRes == 0: -# wrapSslCall(sock, SSL_shutdown(sock.ssl)) -# SSL_free(sock.ssl) -# if not isNil(sock.sslCtx) and not sock.ctxIsView: -# SSL_CTX_free(sock.sslCtx) -# sock.udp.close() -# -# proc main {.async.} = -# let -# address = initTAddress("127.0.0.1:8090") -# server = await createDtlsServer(address) -# client = connect(address) -# -# let -# servConn = await server.accept() -# clientConn = await client -# await clientConn.write("Hello world!".toBytes()) -# echo string.fromBytes(await servConn.read()) -# -# await allFutures(servConn.close(), clientConn.close()) -# await server.close() -# -# waitFor(main()) +import mbedtls/ssl +import mbedtls/pk +import mbedtls/md +import mbedtls/entropy +import mbedtls/ctr_drbg +import mbedtls/rsa +import mbedtls/x509 +import mbedtls/x509_crt +import mbedtls/bignum +import mbedtls/error + +type + DtlsConn* = ref object of WebRTCConn + recvData: seq[seq[byte]] + recvEvent: AsyncEvent + handlesFut: Future[void] + + entropy: mbedtls_entropy_context + ctr_drbg: mbedtls_ctr_drbg_context + +proc mbedtls_pk_rsa(pk: mbedtls_pk_context): ptr mbedtls_rsa_context = + var key = pk + case mbedtls_pk_get_type(addr key): + of MBEDTLS_PK_RSA: + return cast[ptr mbedtls_rsa_context](pk.private_pk_ctx) + else: + return nil + +proc generateKey(self: DtlsConn): mbedtls_pk_context = + var res: mbedtls_pk_context + mbedtls_pk_init(addr res) + echo "=> ", mbedtls_pk_setup(addr res, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) + echo "=> ", mbedtls_rsa_gen_key(mbedtls_pk_rsa(res), + mbedtls_ctr_drbg_random, + cast[pointer](addr self.ctr_drbg), 4096, 65537) + return res + +proc generateCertificate(self: DtlsConn): mbedtls_x509_crt = + let + name = "C=FR,O=webrtc,CN=wbrtc" + time_format = initTimeFormat("YYYYMMddHHmmss") + time_from = times.now().format(time_format) + time_to = (times.now() + times.years(1)).format(time_format) + + + var issuer_key = self.generateKey() + var write_cert: mbedtls_x509write_cert + var serial_mpi: mbedtls_mpi + mbedtls_x509write_crt_init(addr write_cert) + mbedtls_x509write_crt_set_md_alg(addr write_cert, MBEDTLS_MD_SHA256); + mbedtls_x509write_crt_set_subject_key(addr write_cert, addr issuer_key) + mbedtls_x509write_crt_set_issuer_key(addr write_cert, addr issuer_key) + echo mbedtls_x509write_crt_set_subject_name(addr write_cert, name.cstring) + echo mbedtls_x509write_crt_set_issuer_name(addr write_cert, name.cstring) + echo mbedtls_x509write_crt_set_validity(addr write_cert, time_from.cstring, time_to.cstring) + echo mbedtls_x509write_crt_set_basic_constraints(addr write_cert, 0, -1) + echo mbedtls_x509write_crt_set_subject_key_identifier(addr write_cert) + echo mbedtls_x509write_crt_set_authority_key_identifier(addr write_cert); + mbedtls_mpi_init(addr serial_mpi); + var + serial_hex = newString(16) + buf = newString(4096) + echo mbedtls_mpi_read_string(addr serial_mpi, 16, serial_hex.cstring); + echo mbedtls_x509write_crt_set_serial(addr write_cert, addr serial_mpi) + echo mbedtls_x509write_crt_pem(addr write_cert, cast[ptr byte](buf.cstring), buf.len().uint, + mbedtls_ctr_drbg_random, addr self.ctr_drbg) + echo mbedtls_x509_crt_parse(addr result, cast[ptr byte](buf.cstring), buf.cstring.len().uint + 1) + +method init*(self: DtlsConn, conn: WebRTCConn, address: TransportAddress) {.async.} = + await procCall(WebRTCConn(self).init(conn, address)) + + mbedtls_ctr_drbg_init(cast[ptr mbedtls_ctr_drbg_context](addr self.ctr_drbg)) + mbedtls_entropy_init(cast[ptr mbedtls_entropy_context](addr self.entropy)) + if mbedtls_ctr_drbg_seed(cast[ptr mbedtls_ctr_drbg_context](addr self.ctr_drbg), + mbedtls_entropy_func, cast[pointer](addr self.entropy), + nil, 0) != 0: + echo "Something's not quite right" + return + +proc testtruc() = + var write_cert: mbedtls_x509write_cert + mbedtls_x509write_crt_init(cast[ptr mbedtls_x509write_cert](addr write_cert)) + echo mbedtls_x509write_crt_set_subject_name( + cast[ptr mbedtls_x509write_cert](addr write_cert), "aa".cstring) + + +method close*(self: WebRTCConn) {.async.} = + discard + +method write*(self: WebRTCConn, msg: seq[byte]) {.async.} = + discard + +method read*(self: WebRTCConn): Future[seq[byte]] {.async.} = + discard + +proc main {.async.} = + let laddr = initTAddress("127.0.0.1:" & "4242") + var dtls = DtlsConn() + await dtls.init(nil, laddr) + let cert = dtls.generateCertificate() + +waitFor(main()) From d875ba1ad88ed7d67fb47a21a2fc28fd5ee86ccd Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Mon, 3 Jul 2023 12:33:19 +0200 Subject: [PATCH 15/66] dtls with templates from mbedtls + read & write --- webrtc/dtls.nim | 113 ++++++++++++++++++++++------------- webrtc/stun_connection.nim | 4 +- webrtc/webrtc_connection.nim | 8 +-- 3 files changed, 76 insertions(+), 49 deletions(-) diff --git a/webrtc/dtls.nim b/webrtc/dtls.nim index 1d2a2f0..a904011 100644 --- a/webrtc/dtls.nim +++ b/webrtc/dtls.nim @@ -21,16 +21,20 @@ import mbedtls/x509 import mbedtls/x509_crt import mbedtls/bignum import mbedtls/error +import mbedtls/net_sockets type DtlsConn* = ref object of WebRTCConn recvData: seq[seq[byte]] recvEvent: AsyncEvent - handlesFut: Future[void] + sendEvent: AsyncEvent entropy: mbedtls_entropy_context ctr_drbg: mbedtls_ctr_drbg_context + config: mbedtls_ssl_config + ssl: mbedtls_ssl_context + proc mbedtls_pk_rsa(pk: mbedtls_pk_context): ptr mbedtls_rsa_context = var key = pk case mbedtls_pk_get_type(addr key): @@ -41,11 +45,9 @@ proc mbedtls_pk_rsa(pk: mbedtls_pk_context): ptr mbedtls_rsa_context = proc generateKey(self: DtlsConn): mbedtls_pk_context = var res: mbedtls_pk_context - mbedtls_pk_init(addr res) - echo "=> ", mbedtls_pk_setup(addr res, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) - echo "=> ", mbedtls_rsa_gen_key(mbedtls_pk_rsa(res), - mbedtls_ctr_drbg_random, - cast[pointer](addr self.ctr_drbg), 4096, 65537) + mb_pk_init(res) + discard mbedtls_pk_setup(addr res, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) + mb_rsa_gen_key(mb_pk_rsa(res), mbedtls_ctr_drbg_random, self.ctr_drbg, 4096, 65537) return res proc generateCertificate(self: DtlsConn): mbedtls_x509_crt = @@ -59,52 +61,77 @@ proc generateCertificate(self: DtlsConn): mbedtls_x509_crt = var issuer_key = self.generateKey() var write_cert: mbedtls_x509write_cert var serial_mpi: mbedtls_mpi - mbedtls_x509write_crt_init(addr write_cert) - mbedtls_x509write_crt_set_md_alg(addr write_cert, MBEDTLS_MD_SHA256); - mbedtls_x509write_crt_set_subject_key(addr write_cert, addr issuer_key) - mbedtls_x509write_crt_set_issuer_key(addr write_cert, addr issuer_key) - echo mbedtls_x509write_crt_set_subject_name(addr write_cert, name.cstring) - echo mbedtls_x509write_crt_set_issuer_name(addr write_cert, name.cstring) - echo mbedtls_x509write_crt_set_validity(addr write_cert, time_from.cstring, time_to.cstring) - echo mbedtls_x509write_crt_set_basic_constraints(addr write_cert, 0, -1) - echo mbedtls_x509write_crt_set_subject_key_identifier(addr write_cert) - echo mbedtls_x509write_crt_set_authority_key_identifier(addr write_cert); - mbedtls_mpi_init(addr serial_mpi); - var - serial_hex = newString(16) - buf = newString(4096) - echo mbedtls_mpi_read_string(addr serial_mpi, 16, serial_hex.cstring); - echo mbedtls_x509write_crt_set_serial(addr write_cert, addr serial_mpi) - echo mbedtls_x509write_crt_pem(addr write_cert, cast[ptr byte](buf.cstring), buf.len().uint, - mbedtls_ctr_drbg_random, addr self.ctr_drbg) - echo mbedtls_x509_crt_parse(addr result, cast[ptr byte](buf.cstring), buf.cstring.len().uint + 1) + mb_x509write_crt_init(write_cert) + mb_x509write_crt_set_md_alg(write_cert, MBEDTLS_MD_SHA256); + mb_x509write_crt_set_subject_key(write_cert, issuer_key) + mb_x509write_crt_set_issuer_key(write_cert, issuer_key) + mb_x509write_crt_set_subject_name(write_cert, name) + mb_x509write_crt_set_issuer_name(write_cert, name) + mb_x509write_crt_set_validity(write_cert, time_from, time_to) + mb_x509write_crt_set_basic_constraints(write_cert, 0, -1) + mb_x509write_crt_set_subject_key_identifier(write_cert) + mb_x509write_crt_set_authority_key_identifier(write_cert) + mb_mpi_init(serial_mpi) + let serial_hex = mb_mpi_read_string(serial_mpi, 16) + mb_x509write_crt_set_serial(write_cert, serial_mpi) + let buf = mb_x509write_crt_pem(write_cert, 4096, mbedtls_ctr_drbg_random, self.ctr_drbg) + mb_x509_crt_parse(result, buf) + +proc dtlsSend*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = + echo "dtlsSend: " + let self = cast[ptr DtlsConn](ctx) + self.sendEvent.fire() + +proc dtlsRecv*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = + echo "dtlsRecv: " + let self = cast[ptr DtlsConn](ctx)[] + self.recvEvent.fire() method init*(self: DtlsConn, conn: WebRTCConn, address: TransportAddress) {.async.} = await procCall(WebRTCConn(self).init(conn, address)) + self.recvEvent = AsyncEvent() + self.sendEvent = AsyncEvent() - mbedtls_ctr_drbg_init(cast[ptr mbedtls_ctr_drbg_context](addr self.ctr_drbg)) - mbedtls_entropy_init(cast[ptr mbedtls_entropy_context](addr self.entropy)) - if mbedtls_ctr_drbg_seed(cast[ptr mbedtls_ctr_drbg_context](addr self.ctr_drbg), - mbedtls_entropy_func, cast[pointer](addr self.entropy), - nil, 0) != 0: - echo "Something's not quite right" - return + mb_ctr_drbg_init(self.ctr_drbg) + mb_entropy_init(self.entropy) + mb_ctr_drbg_seed(self.ctr_drbg, mbedtls_entropy_func, + self.entropy, nil, 0) + var + srvcert = self.generateCertificate() + pkey = self.generateKey() + selfvar = self -proc testtruc() = - var write_cert: mbedtls_x509write_cert - mbedtls_x509write_crt_init(cast[ptr mbedtls_x509write_cert](addr write_cert)) - echo mbedtls_x509write_crt_set_subject_name( - cast[ptr mbedtls_x509write_cert](addr write_cert), "aa".cstring) + mb_ssl_init(self.ssl) + mb_ssl_config_init(self.config) + mb_ssl_config_defaults(self.config, MBEDTLS_SSL_IS_SERVER, + MBEDTLS_SSL_TRANSPORT_DATAGRAM, + MBEDTLS_SSL_PRESET_DEFAULT) + mb_ssl_conf_rng(self.config, mbedtls_ctr_drbg_random, self.ctr_drbg) + mb_ssl_conf_read_timeout(self.config, 10000) # in milliseconds + mb_ssl_conf_ca_chain(self.config, srvcert.next, nil) + mb_ssl_conf_own_cert(self.config, srvcert, pkey) + # cookies ? + mb_ssl_setup(self.ssl, self.config) + mb_ssl_session_reset(self.ssl) + mb_ssl_set_bio(self.ssl, cast[pointer](addr selfvar), + dtlsSend, dtlsRecv, nil) + while true: + mb_ssl_handshake(self.ssl) - -method close*(self: WebRTCConn) {.async.} = +method close*(self: DtlsConn) {.async.} = discard -method write*(self: WebRTCConn, msg: seq[byte]) {.async.} = - discard +method write*(self: DtlsConn, msg: seq[byte]) {.async.} = + var buf = msg + self.sendEvent.clear() + discard mbedtls_ssl_write(addr self.ssl, cast[ptr byte](buf.cstring), buf.len()) + await self.sendEvent.wait() -method read*(self: WebRTCConn): Future[seq[byte]] {.async.} = - discard +method read*(self: DtlsConn): Future[seq[byte]] {.async.} = + var res = newString(4096) + self.recvEvent.clear() + discard mbedtls_ssl_read(addr self.ssl, cast[ptr byte](res.cstring), 4096) + await self.recvEvent.wait() proc main {.async.} = let laddr = initTAddress("127.0.0.1:" & "4242") diff --git a/webrtc/stun_connection.nim b/webrtc/stun_connection.nim index 8199450..f8482c9 100644 --- a/webrtc/stun_connection.nim +++ b/webrtc/stun_connection.nim @@ -28,7 +28,7 @@ proc handles(self: StunConn) {.async.} = recvEvent.fire() method init(self: StunConn, conn: WebRTCConn, address: TransportAddress) {.async.} = - procCall(WebRTCConn(self).init(conn, address)) + await procCall(WebRTCConn(self).init(conn, address)) self.recvEvent = newAsyncEvent() self.handlesFut = handles() @@ -40,7 +40,7 @@ method close(self: StunConn) {.async.} = method write(self: StunConn, msg: seq[byte]) {.async.} = await self.conn.write(msg) -method read(self: StunConn): seq[byte] {.async.} = +method read(self: StunConn): Future[seq[byte]] {.async.} = while self.recvData.len() <= 0: self.recvEvent.clear() await self.recvEvent.wait() diff --git a/webrtc/webrtc_connection.nim b/webrtc/webrtc_connection.nim index 76b61ee..eae2b1b 100644 --- a/webrtc/webrtc_connection.nim +++ b/webrtc/webrtc_connection.nim @@ -16,15 +16,15 @@ type # isClosed: bool # isEof: bool -method init(self: WebRTCConn, conn: WebRTCConn, address: TransportAddress) {.async, base.} = +method init*(self: WebRTCConn, conn: WebRTCConn, address: TransportAddress) {.async, base.} = self.conn = conn self.address = address -method close(self: WebRTCConn) {.async, base.} = +method close*(self: WebRTCConn) {.async, base.} = doAssert(false, "not implemented!") -method write(self: WebRTCConn, msg: seq[byte]) {.async, base.} = +method write*(self: WebRTCConn, msg: seq[byte]) {.async, base.} = doAssert(false, "not implemented!") -method read(self: WebRTCConn): seq[byte] = +method read*(self: WebRTCConn): Future[seq[byte]] {.async, base.} = doAssert(false, "not implemented!") From 237d723374ac05b7ec67fd2ec2021c9d43d83a44 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 18 Aug 2023 11:47:20 +0200 Subject: [PATCH 16/66] Multiple fixes --- webrtc/dtls.nim | 34 +++++++++++-------- webrtc/sctp.nim | 21 ++++++++---- webrtc/{ => stun}/stun.nim | 2 +- .../stun_attributes.nim} | 2 +- webrtc/{ => stun}/stun_connection.nim | 6 ++-- webrtc/udp_connection.nim | 7 ++-- webrtc/webrtc.nim | 2 +- webrtc/webrtc_connection.nim | 4 +-- 8 files changed, 46 insertions(+), 32 deletions(-) rename webrtc/{ => stun}/stun.nim (99%) rename webrtc/{stunattributes.nim => stun/stun_attributes.nim} (99%) rename webrtc/{ => stun}/stun_connection.nim (93%) diff --git a/webrtc/dtls.nim b/webrtc/dtls.nim index a904011..0e38b89 100644 --- a/webrtc/dtls.nim +++ b/webrtc/dtls.nim @@ -8,7 +8,7 @@ # those terms. import std/times -import chronos +import chronos, chronicles import webrtc_connection import mbedtls/ssl @@ -22,6 +22,10 @@ import mbedtls/x509_crt import mbedtls/bignum import mbedtls/error import mbedtls/net_sockets +import mbedtls/timing + +logScope: + topics = "webrtc dtls" type DtlsConn* = ref object of WebRTCConn @@ -31,6 +35,7 @@ type entropy: mbedtls_entropy_context ctr_drbg: mbedtls_ctr_drbg_context + timer: mbedtls_timing_delay_context config: mbedtls_ssl_config ssl: mbedtls_ssl_context @@ -57,7 +62,6 @@ proc generateCertificate(self: DtlsConn): mbedtls_x509_crt = time_from = times.now().format(time_format) time_to = (times.now() + times.years(1)).format(time_format) - var issuer_key = self.generateKey() var write_cert: mbedtls_x509write_cert var serial_mpi: mbedtls_mpi @@ -78,14 +82,15 @@ proc generateCertificate(self: DtlsConn): mbedtls_x509_crt = mb_x509_crt_parse(result, buf) proc dtlsSend*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = - echo "dtlsSend: " + echo "Send: ", len let self = cast[ptr DtlsConn](ctx) self.sendEvent.fire() proc dtlsRecv*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = - echo "dtlsRecv: " + echo "Recv: ", len let self = cast[ptr DtlsConn](ctx)[] - self.recvEvent.fire() + + let x = self.read() method init*(self: DtlsConn, conn: WebRTCConn, address: TransportAddress) {.async.} = await procCall(WebRTCConn(self).init(conn, address)) @@ -110,7 +115,10 @@ method init*(self: DtlsConn, conn: WebRTCConn, address: TransportAddress) {.asyn mb_ssl_conf_read_timeout(self.config, 10000) # in milliseconds mb_ssl_conf_ca_chain(self.config, srvcert.next, nil) mb_ssl_conf_own_cert(self.config, srvcert, pkey) - # cookies ? + mbedtls_ssl_set_timer_cb(addr self.ssl, cast[pointer](addr self.timer), + mbedtls_timing_set_delay, + mbedtls_timing_get_delay) + # cookie ? mb_ssl_setup(self.ssl, self.config) mb_ssl_session_reset(self.ssl) mb_ssl_set_bio(self.ssl, cast[pointer](addr selfvar), @@ -118,25 +126,21 @@ method init*(self: DtlsConn, conn: WebRTCConn, address: TransportAddress) {.asyn while true: mb_ssl_handshake(self.ssl) -method close*(self: DtlsConn) {.async.} = - discard - method write*(self: DtlsConn, msg: seq[byte]) {.async.} = var buf = msg self.sendEvent.clear() - discard mbedtls_ssl_write(addr self.ssl, cast[ptr byte](buf.cstring), buf.len()) + discard mbedtls_ssl_write(addr self.ssl, cast[ptr byte](addr buf[0]), buf.len().uint) await self.sendEvent.wait() method read*(self: DtlsConn): Future[seq[byte]] {.async.} = - var res = newString(4096) - self.recvEvent.clear() - discard mbedtls_ssl_read(addr self.ssl, cast[ptr byte](res.cstring), 4096) - await self.recvEvent.wait() + return await self.conn.read() + +method close*(self: DtlsConn) {.async.} = + discard proc main {.async.} = let laddr = initTAddress("127.0.0.1:" & "4242") var dtls = DtlsConn() await dtls.init(nil, laddr) - let cert = dtls.generateCertificate() waitFor(main()) diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index d86833d..78e6004 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -8,7 +8,7 @@ # those terms. import tables, bitops, posix, strutils, sequtils -import chronos, chronicles, stew/ranges/ptr_arith +import chronos, chronicles, stew/[ranges/ptr_arith, byteutils] import usrsctp export chronicles @@ -101,10 +101,13 @@ proc write*(self: SctpConnection, buf: seq[byte]) {.async.} = self.sctp.sentConnection = self self.sctp.sentAddress = self.address let sendvErr = self.sctp.usrsctpAwait: - self.sctpSocket.usrsctp_sendv(addr buf[0], buf.len.uint, + self.sctpSocket.usrsctp_sendv(unsafeAddr buf[0], buf.len.uint, nil, 0, nil, 0, SCTP_SENDV_NOINFO, 0) +proc write*(self: SctpConnection, s: string) {.async.} = + await self.write(s.toBytes()) + proc close*(self: SctpConnection) {.async.} = self.sctp.usrsctpAwait: self.sctpSocket.usrsctp_close() @@ -143,7 +146,7 @@ proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = if bitand(flags, MSG_NOTIFICATION) != 0: trace "Notification received", length = n else: - conn.dataRecv = conn.dataRecv.concat(buffer[0..n]) + conn.dataRecv = conn.dataRecv.concat(buffer[0.. Date: Fri, 18 Aug 2023 13:37:08 +0200 Subject: [PATCH 17/66] Fix in case of double connections with sctp --- webrtc/sctp.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index 78e6004..7206c37 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -191,7 +191,7 @@ proc getOrCreateConnection(self: Sctp, self.sentAddress = address let connErr = self.usrsctpAwait: conn.sctpSocket.usrsctp_connect(cast[ptr SockAddr](addr sconn), SockLen(sizeof(sconn))) - doAssert 0 == connErr or errno == EINPROGRESS, ($errno) # TODO raise + doAssert 0 == connErr or errno == posix.EINPROGRESS, ($errno) # TODO raise self.connections[address] = conn return conn @@ -308,6 +308,8 @@ proc connect*(self: Sctp, sctpPort: uint16 = 5000): Future[SctpConnection] {.async.} = trace "Connect", address let conn = await self.getOrCreateConnection(self.udp, address, sctpPort) + if conn.state == Connected: + return conn try: await conn.connectEvent.wait() except CancelledError as exc: From 8a33c17c3842d8c23c899f691863503ed23cba0b Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 18 Aug 2023 14:45:25 +0200 Subject: [PATCH 18/66] Some fixes in dtls --- webrtc/{ => dtls}/dtls.nim | 43 +--------------------------- webrtc/dtls/utils.nim | 58 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 42 deletions(-) rename webrtc/{ => dtls}/dtls.nim (64%) create mode 100644 webrtc/dtls/utils.nim diff --git a/webrtc/dtls.nim b/webrtc/dtls/dtls.nim similarity index 64% rename from webrtc/dtls.nim rename to webrtc/dtls/dtls.nim index 0e38b89..01041df 100644 --- a/webrtc/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -9,7 +9,7 @@ import std/times import chronos, chronicles -import webrtc_connection +import ./utils, ../webrtc_connection import mbedtls/ssl import mbedtls/pk @@ -40,47 +40,6 @@ type config: mbedtls_ssl_config ssl: mbedtls_ssl_context -proc mbedtls_pk_rsa(pk: mbedtls_pk_context): ptr mbedtls_rsa_context = - var key = pk - case mbedtls_pk_get_type(addr key): - of MBEDTLS_PK_RSA: - return cast[ptr mbedtls_rsa_context](pk.private_pk_ctx) - else: - return nil - -proc generateKey(self: DtlsConn): mbedtls_pk_context = - var res: mbedtls_pk_context - mb_pk_init(res) - discard mbedtls_pk_setup(addr res, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) - mb_rsa_gen_key(mb_pk_rsa(res), mbedtls_ctr_drbg_random, self.ctr_drbg, 4096, 65537) - return res - -proc generateCertificate(self: DtlsConn): mbedtls_x509_crt = - let - name = "C=FR,O=webrtc,CN=wbrtc" - time_format = initTimeFormat("YYYYMMddHHmmss") - time_from = times.now().format(time_format) - time_to = (times.now() + times.years(1)).format(time_format) - - var issuer_key = self.generateKey() - var write_cert: mbedtls_x509write_cert - var serial_mpi: mbedtls_mpi - mb_x509write_crt_init(write_cert) - mb_x509write_crt_set_md_alg(write_cert, MBEDTLS_MD_SHA256); - mb_x509write_crt_set_subject_key(write_cert, issuer_key) - mb_x509write_crt_set_issuer_key(write_cert, issuer_key) - mb_x509write_crt_set_subject_name(write_cert, name) - mb_x509write_crt_set_issuer_name(write_cert, name) - mb_x509write_crt_set_validity(write_cert, time_from, time_to) - mb_x509write_crt_set_basic_constraints(write_cert, 0, -1) - mb_x509write_crt_set_subject_key_identifier(write_cert) - mb_x509write_crt_set_authority_key_identifier(write_cert) - mb_mpi_init(serial_mpi) - let serial_hex = mb_mpi_read_string(serial_mpi, 16) - mb_x509write_crt_set_serial(write_cert, serial_mpi) - let buf = mb_x509write_crt_pem(write_cert, 4096, mbedtls_ctr_drbg_random, self.ctr_drbg) - mb_x509_crt_parse(result, buf) - proc dtlsSend*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = echo "Send: ", len let self = cast[ptr DtlsConn](ctx) diff --git a/webrtc/dtls/utils.nim b/webrtc/dtls/utils.nim new file mode 100644 index 0000000..eb71d3f --- /dev/null +++ b/webrtc/dtls/utils.nim @@ -0,0 +1,58 @@ +# Nim-WebRTC +# Copyright (c) 2023 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +# * MIT license ([LICENSE-MIT](LICENSE-MIT)) +# at your option. +# This file may not be copied, modified, or distributed except according to +# those terms. + +import std/times + +import mbedtls/pk +import mbedtls/rsa +import mbedtls/ctr_drbg +import mbedtls/x509_crt +import mbedtls/bignum +import mbedtls/md + +proc mbedtls_pk_rsa*(pk: mbedtls_pk_context): ptr mbedtls_rsa_context = + var key = pk + case mbedtls_pk_get_type(addr key): + of MBEDTLS_PK_RSA: + return cast[ptr mbedtls_rsa_context](pk.private_pk_ctx) + else: + return nil + +proc generateKey*(random: mbedtls_ctr_drbg_context): mbedtls_pk_context = + var res: mbedtls_pk_context + mb_pk_init(res) + discard mbedtls_pk_setup(addr res, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) + mb_rsa_gen_key(mb_pk_rsa(res), mbedtls_ctr_drbg_random, random, 4096, 65537) + return res + +proc generateCertificate*(random: mbedtls_ctr_drbg_context): mbedtls_x509_crt = + let + name = "C=FR,O=webrtc,CN=webrtc" + time_format = initTimeFormat("YYYYMMddHHmmss") + time_from = times.now().format(time_format) + time_to = (times.now() + times.years(1)).format(time_format) + + var issuer_key = random.generateKey() + var write_cert: mbedtls_x509write_cert + var serial_mpi: mbedtls_mpi + mb_x509write_crt_init(write_cert) + mb_x509write_crt_set_md_alg(write_cert, MBEDTLS_MD_SHA256); + mb_x509write_crt_set_subject_key(write_cert, issuer_key) + mb_x509write_crt_set_issuer_key(write_cert, issuer_key) + mb_x509write_crt_set_subject_name(write_cert, name) + mb_x509write_crt_set_issuer_name(write_cert, name) + mb_x509write_crt_set_validity(write_cert, time_from, time_to) + mb_x509write_crt_set_basic_constraints(write_cert, 0, -1) + mb_x509write_crt_set_subject_key_identifier(write_cert) + mb_x509write_crt_set_authority_key_identifier(write_cert) + mb_mpi_init(serial_mpi) + let serial_hex = mb_mpi_read_string(serial_mpi, 16) + mb_x509write_crt_set_serial(write_cert, serial_mpi) + let buf = mb_x509write_crt_pem(write_cert, 4096, mbedtls_ctr_drbg_random, random) + mb_x509_crt_parse(result, buf) From c28ae5ca31430f3c94a49f29893964f34f1eee29 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 18 Aug 2023 17:13:34 +0200 Subject: [PATCH 19/66] dtls fixes 1 --- webrtc/dtls/dtls.nim | 100 +++++++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 33 deletions(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 01041df..c9debdf 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -33,8 +33,6 @@ type recvEvent: AsyncEvent sendEvent: AsyncEvent - entropy: mbedtls_entropy_context - ctr_drbg: mbedtls_ctr_drbg_context timer: mbedtls_timing_delay_context config: mbedtls_ssl_config @@ -53,37 +51,9 @@ proc dtlsRecv*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = method init*(self: DtlsConn, conn: WebRTCConn, address: TransportAddress) {.async.} = await procCall(WebRTCConn(self).init(conn, address)) - self.recvEvent = AsyncEvent() - self.sendEvent = AsyncEvent() - - mb_ctr_drbg_init(self.ctr_drbg) - mb_entropy_init(self.entropy) - mb_ctr_drbg_seed(self.ctr_drbg, mbedtls_entropy_func, - self.entropy, nil, 0) - var - srvcert = self.generateCertificate() - pkey = self.generateKey() - selfvar = self - - mb_ssl_init(self.ssl) - mb_ssl_config_init(self.config) - mb_ssl_config_defaults(self.config, MBEDTLS_SSL_IS_SERVER, - MBEDTLS_SSL_TRANSPORT_DATAGRAM, - MBEDTLS_SSL_PRESET_DEFAULT) - mb_ssl_conf_rng(self.config, mbedtls_ctr_drbg_random, self.ctr_drbg) - mb_ssl_conf_read_timeout(self.config, 10000) # in milliseconds - mb_ssl_conf_ca_chain(self.config, srvcert.next, nil) - mb_ssl_conf_own_cert(self.config, srvcert, pkey) - mbedtls_ssl_set_timer_cb(addr self.ssl, cast[pointer](addr self.timer), - mbedtls_timing_set_delay, - mbedtls_timing_get_delay) - # cookie ? - mb_ssl_setup(self.ssl, self.config) - mb_ssl_session_reset(self.ssl) - mb_ssl_set_bio(self.ssl, cast[pointer](addr selfvar), - dtlsSend, dtlsRecv, nil) - while true: - mb_ssl_handshake(self.ssl) +# self.recvEvent = AsyncEvent() +# self.sendEvent = AsyncEvent() +# method write*(self: DtlsConn, msg: seq[byte]) {.async.} = var buf = msg @@ -103,3 +73,67 @@ proc main {.async.} = await dtls.init(nil, laddr) waitFor(main()) + +type + Dtls* = ref object of RootObj + ctr_drbg: mbedtls_ctr_drbg_context + entropy: mbedtls_entropy_context + + address: TransportAddress + started: bool + +proc start*(self: Dtls, address: TransportAddress) = + if self.started: + warn "Already started" + return + + self.address = address + self.started = true + mb_ctr_drbg_init(self.ctr_drbg) + mb_entropy_init(self.entropy) + mb_ctr_drbg_seed(self.ctr_drbg, mbedtls_entropy_func, + self.entropy, nil, 0) + +proc stop*(self: Dtls) = + if not self.started: + warn "Already stopped" + return + + self.stopped = false + +proc handshake(self: DtlsConn) {.async.} = + while self.ssl.private_state != MBEDTLS_SSL_HANDSHAKE_OVER: + let res = mbedtls_ssl_handshake_step(addr self.ssl) + if res == MBEDTLS_ERR_SSL_WANT_READ or res == MBEDTLS_ERR_SSL_WANT_READ: + continue + +proc accept*(self: Dtls, conn: WebRTCConn): DtlsConn {.async.} = + var + srvcert = self.generateCertificate() + pkey = self.generateKey() + selfvar = self + + result = Dtls() + result.init(conn, self.address) + mb_ssl_init(result.ssl) + mb_ssl_config_init(result.config) + mb_ssl_config_defaults(result.config, + MBEDTLS_SSL_IS_SERVER, + MBEDTLS_SSL_TRANSPORT_DATAGRAM, + MBEDTLS_SSL_PRESET_DEFAULT) + mb_ssl_conf_rng(result.config, mbedtls_ctr_drbg_random, self.ctr_drbg) + mb_ssl_conf_read_timeout(result.config, 10000) # in milliseconds + mb_ssl_conf_ca_chain(result.config, srvcert.next, nil) + mb_ssl_conf_own_cert(result.config, srvcert, pkey) + mbedtls_ssl_set_timer_cb(addr result.ssl, cast[pointer](addr result.timer), + mbedtls_timing_set_delay, + mbedtls_timing_get_delay) + # Add the cookie management (it works without, but it's more secure) + mb_ssl_setup(result.ssl, result.config) + mb_ssl_session_reset(result.ssl) + mb_ssl_set_bio(result.ssl, cast[pointer](result), + dtlsSend, dtlsRecv, nil) + await result.handshake() + +proc dial*(self: Dtls, address: TransportAddress): DtlsConn = + discard From 8e826f7eb241f32218942404cc5e3e9bd07431c6 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 18 Aug 2023 17:14:03 +0200 Subject: [PATCH 20/66] add sctp examples --- examples/sctp_client.nim | 14 ++++++++++++++ examples/sctp_server.nim | 13 +++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 examples/sctp_client.nim create mode 100644 examples/sctp_server.nim diff --git a/examples/sctp_client.nim b/examples/sctp_client.nim new file mode 100644 index 0000000..b49b1d8 --- /dev/null +++ b/examples/sctp_client.nim @@ -0,0 +1,14 @@ +import chronos, stew/byteutils +import ../webrtc/sctp + +proc main() {.async.} = + let + sctp = Sctp.new(port = 4244) + address = TransportAddress(initTAddress("127.0.0.1:4242")) + conn = await sctp.connect(address, sctpPort = 13) + await conn.write("test".toBytes) + let msg = await conn.read() + echo "Client read() finished ; receive: ", string.fromBytes(msg) + await conn.close() + +waitFor(main()) diff --git a/examples/sctp_server.nim b/examples/sctp_server.nim new file mode 100644 index 0000000..429e247 --- /dev/null +++ b/examples/sctp_server.nim @@ -0,0 +1,13 @@ +import chronos, stew/byteutils +import ../webrtc/sctp + +proc main() {.async.} = + let sctp = Sctp.new(port = 4242) + sctp.startServer(13) + let conn = await sctp.listen() + let msg = await conn.read() + echo "Receive: ", string.fromBytes(msg) + await conn.close() + sctp.stopServer() + +waitFor(main()) From d6c2877fc2eb544d74fac392b2a5763610b6d4ab Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 18 Aug 2023 17:19:06 +0200 Subject: [PATCH 21/66] add example sctp_both.nim --- examples/sctp_both.nim | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 examples/sctp_both.nim diff --git a/examples/sctp_both.nim b/examples/sctp_both.nim new file mode 100644 index 0000000..d801f6b --- /dev/null +++ b/examples/sctp_both.nim @@ -0,0 +1,27 @@ +import chronos, stew/byteutils +import ../webrtc/sctp as sc + +let sctp = Sctp.new(port = 4242) +proc serv(fut: Future[void]) {.async.} = + #let sctp = Sctp.new(port = 4242) + sctp.startServer(13) + fut.complete() + let conn = await sctp.listen() + echo "await read()" + let msg = await conn.read() + echo "read() finished" + echo "Receive: ", string.fromBytes(msg) + await conn.close() + sctp.stopServer() + +proc main() {.async.} = + let fut = Future[void]() + asyncSpawn serv(fut) + await fut + #let sctp = Sctp.new(port = 4244) + let address = TransportAddress(initTAddress("127.0.0.1:4242")) + let conn = await sctp.connect(address, sctpPort = 13) + await conn.write("test".toBytes) + await conn.close() + +waitFor(main()) From a65d905fb8eeca74a120c191dee12d36488051cb Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 18 Aug 2023 17:20:18 +0200 Subject: [PATCH 22/66] remove useless comments --- examples/sctp_both.nim | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/sctp_both.nim b/examples/sctp_both.nim index d801f6b..bb861fa 100644 --- a/examples/sctp_both.nim +++ b/examples/sctp_both.nim @@ -3,7 +3,6 @@ import ../webrtc/sctp as sc let sctp = Sctp.new(port = 4242) proc serv(fut: Future[void]) {.async.} = - #let sctp = Sctp.new(port = 4242) sctp.startServer(13) fut.complete() let conn = await sctp.listen() @@ -18,7 +17,6 @@ proc main() {.async.} = let fut = Future[void]() asyncSpawn serv(fut) await fut - #let sctp = Sctp.new(port = 4244) let address = TransportAddress(initTAddress("127.0.0.1:4242")) let conn = await sctp.connect(address, sctpPort = 13) await conn.write("test".toBytes) From 11031a47060fd2905eab5d443d4ce2a04db42a7a Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Tue, 22 Aug 2023 17:03:14 +0200 Subject: [PATCH 23/66] few fixes on udp & try to fix dtls read and write --- webrtc/dtls/dtls.nim | 94 ++++++++++++++++++++++++++------------- webrtc/dtls/utils.nim | 10 +++-- webrtc/udp_connection.nim | 7 +-- 3 files changed, 72 insertions(+), 39 deletions(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index c9debdf..e5c2e57 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -7,7 +7,8 @@ # This file may not be copied, modified, or distributed except according to # those terms. -import std/times +import times, sequtils +import strutils # to remove import chronos, chronicles import ./utils, ../webrtc_connection @@ -40,14 +41,16 @@ type proc dtlsSend*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = echo "Send: ", len - let self = cast[ptr DtlsConn](ctx) + let self = cast[DtlsConn](ctx) self.sendEvent.fire() proc dtlsRecv*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = - echo "Recv: ", len - let self = cast[ptr DtlsConn](ctx)[] - - let x = self.read() + var self = cast[DtlsConn](ctx)[] + echo "Recv: ", self.recvData[0].len(), " ", len + echo ctx.repr + result = self.recvData[0].len().cint + copyMem(buf, addr self.recvData[0][0], self.recvData[0].len()) + self.recvData.delete(0..0) method init*(self: DtlsConn, conn: WebRTCConn, address: TransportAddress) {.async.} = await procCall(WebRTCConn(self).init(conn, address)) @@ -67,13 +70,6 @@ method read*(self: DtlsConn): Future[seq[byte]] {.async.} = method close*(self: DtlsConn) {.async.} = discard -proc main {.async.} = - let laddr = initTAddress("127.0.0.1:" & "4242") - var dtls = DtlsConn() - await dtls.init(nil, laddr) - -waitFor(main()) - type Dtls* = ref object of RootObj ctr_drbg: mbedtls_ctr_drbg_context @@ -99,41 +95,75 @@ proc stop*(self: Dtls) = warn "Already stopped" return - self.stopped = false + self.started = false proc handshake(self: DtlsConn) {.async.} = + var endpoint = + if self.ssl.private_conf.private_endpoint == MBEDTLS_SSL_IS_SERVER: + MBEDTLS_ERR_SSL_WANT_READ + else: + MBEDTLS_ERR_SSL_WANT_WRITE + while self.ssl.private_state != MBEDTLS_SSL_HANDSHAKE_OVER: + echo "State: ", toHex(self.ssl.private_state.int) + if endpoint == MBEDTLS_ERR_SSL_WANT_READ: + self.recvData.add(await self.conn.read()) + echo "=====> ", self.recvData.len() let res = mbedtls_ssl_handshake_step(addr self.ssl) - if res == MBEDTLS_ERR_SSL_WANT_READ or res == MBEDTLS_ERR_SSL_WANT_READ: + echo "Result handshake step: ", (-res).toHex, " ", + (-MBEDTLS_ERR_SSL_WANT_READ).toHex, " ", + (-MBEDTLS_ERR_SSL_WANT_WRITE).toHex + if res == MBEDTLS_ERR_SSL_WANT_READ or res == MBEDTLS_ERR_SSL_WANT_WRITE: + echo if res == MBEDTLS_ERR_SSL_WANT_READ: "WANT_READ" else: "WANT_WRITE" continue + elif res != 0: + break # raise whatever + endpoint = res -proc accept*(self: Dtls, conn: WebRTCConn): DtlsConn {.async.} = +proc accept*(self: Dtls, conn: WebRTCConn): Future[DtlsConn] {.async.} = + echo "1" var - srvcert = self.generateCertificate() - pkey = self.generateKey() + srvcert = self.ctr_drbg.generateCertificate() + pkey = self.ctr_drbg.generateKey() selfvar = self + res = DtlsConn() + let v = cast[pointer](res) + echo v.repr - result = Dtls() - result.init(conn, self.address) - mb_ssl_init(result.ssl) - mb_ssl_config_init(result.config) - mb_ssl_config_defaults(result.config, + await res.init(conn, self.address) + mb_ssl_init(res.ssl) + mb_ssl_config_init(res.config) + mb_ssl_config_defaults(res.config, MBEDTLS_SSL_IS_SERVER, MBEDTLS_SSL_TRANSPORT_DATAGRAM, MBEDTLS_SSL_PRESET_DEFAULT) - mb_ssl_conf_rng(result.config, mbedtls_ctr_drbg_random, self.ctr_drbg) - mb_ssl_conf_read_timeout(result.config, 10000) # in milliseconds - mb_ssl_conf_ca_chain(result.config, srvcert.next, nil) - mb_ssl_conf_own_cert(result.config, srvcert, pkey) - mbedtls_ssl_set_timer_cb(addr result.ssl, cast[pointer](addr result.timer), + mb_ssl_conf_rng(res.config, mbedtls_ctr_drbg_random, self.ctr_drbg) + mb_ssl_conf_read_timeout(res.config, 10000) # in milliseconds + mb_ssl_conf_ca_chain(res.config, srvcert.next, nil) + mb_ssl_conf_own_cert(res.config, srvcert, pkey) + mbedtls_ssl_set_timer_cb(addr res.ssl, cast[pointer](addr res.timer), mbedtls_timing_set_delay, mbedtls_timing_get_delay) # Add the cookie management (it works without, but it's more secure) - mb_ssl_setup(result.ssl, result.config) - mb_ssl_session_reset(result.ssl) - mb_ssl_set_bio(result.ssl, cast[pointer](result), + mb_ssl_setup(res.ssl, res.config) + mb_ssl_session_reset(res.ssl) + mb_ssl_set_bio(res.ssl, cast[pointer](res), dtlsSend, dtlsRecv, nil) - await result.handshake() + await res.handshake() + return res proc dial*(self: Dtls, address: TransportAddress): DtlsConn = discard + +import ../udp_connection +proc main() {.async.} = + let laddr = initTAddress("127.0.0.1:4433") + let udp = UdpConn() + await udp.init(nil, laddr) + let dtls = Dtls() + dtls.start(laddr) + echo "Before accept" + let x = await dtls.accept(udp) + echo "After accept" + +waitFor(main()) diff --git a/webrtc/dtls/utils.nim b/webrtc/dtls/utils.nim index eb71d3f..63ed41e 100644 --- a/webrtc/dtls/utils.nim +++ b/webrtc/dtls/utils.nim @@ -24,14 +24,14 @@ proc mbedtls_pk_rsa*(pk: mbedtls_pk_context): ptr mbedtls_rsa_context = else: return nil -proc generateKey*(random: mbedtls_ctr_drbg_context): mbedtls_pk_context = +template generateKey*(random: mbedtls_ctr_drbg_context): mbedtls_pk_context = var res: mbedtls_pk_context mb_pk_init(res) discard mbedtls_pk_setup(addr res, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) mb_rsa_gen_key(mb_pk_rsa(res), mbedtls_ctr_drbg_random, random, 4096, 65537) - return res + res -proc generateCertificate*(random: mbedtls_ctr_drbg_context): mbedtls_x509_crt = +template generateCertificate*(random: mbedtls_ctr_drbg_context): mbedtls_x509_crt = let name = "C=FR,O=webrtc,CN=webrtc" time_format = initTimeFormat("YYYYMMddHHmmss") @@ -55,4 +55,6 @@ proc generateCertificate*(random: mbedtls_ctr_drbg_context): mbedtls_x509_crt = let serial_hex = mb_mpi_read_string(serial_mpi, 16) mb_x509write_crt_set_serial(write_cert, serial_mpi) let buf = mb_x509write_crt_pem(write_cert, 4096, mbedtls_ctr_drbg_random, random) - mb_x509_crt_parse(result, buf) + var res: mbedtls_x509_crt + mb_x509_crt_parse(res, buf) + res diff --git a/webrtc/udp_connection.nim b/webrtc/udp_connection.nim index 49d20b6..20a7173 100644 --- a/webrtc/udp_connection.nim +++ b/webrtc/udp_connection.nim @@ -7,6 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. +import sequtils import chronos, chronicles import webrtc_connection @@ -20,7 +21,7 @@ type recvEvent: AsyncEvent method init(self: UdpConn, conn: WebRTCConn, address: TransportAddress) {.async.} = - procCall(WebRTCConn(self).init(conn, address)) + await procCall(WebRTCConn(self).init(conn, address)) proc onReceive(udp: DatagramTransport, address: TransportAddress) {.async, gcsafe.} = let msg = udp.getMessage() @@ -33,12 +34,12 @@ method init(self: UdpConn, conn: WebRTCConn, address: TransportAddress) {.async. method close(self: UdpConn) {.async.} = self.udp.close() if not self.conn.isNil(): - self.conn.close() + await self.conn.close() method write(self: UdpConn, msg: seq[byte]) {.async.} = await self.udp.sendTo(self.address, msg) -method read(self: UdpConn): seq[byte] {.async.} = +method read(self: UdpConn): Future[seq[byte]] {.async.} = while self.recvData.len() <= 0: self.recvEvent.clear() await self.recvEvent.wait() From 12debd98a9bd511301a3c593071be1f67aa8cf2a Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Tue, 29 Aug 2023 17:27:44 +0200 Subject: [PATCH 24/66] Fix a lot of bugs in mbedtls, udp_connection and dtls --- webrtc/dtls/dtls.nim | 89 ++++++++++++++++++++++----------- webrtc/dtls/utils.nim | 45 +++++++++++++++-- webrtc/stun/stun_connection.nim | 3 ++ webrtc/udp_connection.nim | 16 ++++-- webrtc/webrtc_connection.nim | 3 ++ 5 files changed, 119 insertions(+), 37 deletions(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index e5c2e57..b9441db 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -13,6 +13,8 @@ import chronos, chronicles import ./utils, ../webrtc_connection import mbedtls/ssl +import mbedtls/ssl_cookie +import mbedtls/ssl_cache import mbedtls/pk import mbedtls/md import mbedtls/entropy @@ -32,22 +34,30 @@ type DtlsConn* = ref object of WebRTCConn recvData: seq[seq[byte]] recvEvent: AsyncEvent - sendEvent: AsyncEvent + sendFuture: Future[void] timer: mbedtls_timing_delay_context - config: mbedtls_ssl_config ssl: mbedtls_ssl_context + config: mbedtls_ssl_config + cookie: mbedtls_ssl_cookie_ctx + cache: mbedtls_ssl_cache_context + + ctr_drbg: mbedtls_ctr_drbg_context + entropy: mbedtls_entropy_context proc dtlsSend*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = - echo "Send: ", len - let self = cast[DtlsConn](ctx) - self.sendEvent.fire() + echo "\e[36m\e[0;1m Send\e[0m: ", len + var self = cast[DtlsConn](ctx) + var toWrite = newSeq[byte](len) + if len > 0: + copyMem(addr toWrite[0], buf, len) + self.sendFuture = self.conn.write(toWrite) + result = len.cint proc dtlsRecv*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = - var self = cast[DtlsConn](ctx)[] - echo "Recv: ", self.recvData[0].len(), " ", len - echo ctx.repr + var self = cast[DtlsConn](ctx) + echo "\e[36m\e[0;1m Recv\e[0m: ", self.recvData[0].len() result = self.recvData[0].len().cint copyMem(buf, addr self.recvData[0][0], self.recvData[0].len()) self.recvData.delete(0..0) @@ -60,9 +70,7 @@ method init*(self: DtlsConn, conn: WebRTCConn, address: TransportAddress) {.asyn method write*(self: DtlsConn, msg: seq[byte]) {.async.} = var buf = msg - self.sendEvent.clear() discard mbedtls_ssl_write(addr self.ssl, cast[ptr byte](addr buf[0]), buf.len().uint) - await self.sendEvent.wait() method read*(self: DtlsConn): Future[seq[byte]] {.async.} = return await self.conn.read() @@ -70,11 +78,11 @@ method read*(self: DtlsConn): Future[seq[byte]] {.async.} = method close*(self: DtlsConn) {.async.} = discard +method getRemoteAddress*(self: DtlsConn): TransportAddress = + self.conn.getRemoteAddress() + type Dtls* = ref object of RootObj - ctr_drbg: mbedtls_ctr_drbg_context - entropy: mbedtls_entropy_context - address: TransportAddress started: bool @@ -85,10 +93,6 @@ proc start*(self: Dtls, address: TransportAddress) = self.address = address self.started = true - mb_ctr_drbg_init(self.ctr_drbg) - mb_entropy_init(self.entropy) - mb_ctr_drbg_seed(self.ctr_drbg, mbedtls_entropy_func, - self.entropy, nil, 0) proc stop*(self: Dtls) = if not self.started: @@ -105,42 +109,72 @@ proc handshake(self: DtlsConn) {.async.} = MBEDTLS_ERR_SSL_WANT_WRITE while self.ssl.private_state != MBEDTLS_SSL_HANDSHAKE_OVER: - echo "State: ", toHex(self.ssl.private_state.int) + echo "State: ", mb_ssl_states[self.ssl.private_state.int], "(", self.ssl.private_state, ")" if endpoint == MBEDTLS_ERR_SSL_WANT_READ: self.recvData.add(await self.conn.read()) echo "=====> ", self.recvData.len() - let res = mbedtls_ssl_handshake_step(addr self.ssl) - echo "Result handshake step: ", (-res).toHex, " ", - (-MBEDTLS_ERR_SSL_WANT_READ).toHex, " ", - (-MBEDTLS_ERR_SSL_WANT_WRITE).toHex + # TODO: Change set_client_transport_id in mbedtls.nim directly + var ta = self.getRemoteAddress() + case ta.family + of AddressFamily.IPv4: + discard mbedtls_ssl_set_client_transport_id(addr self.ssl, + addr ta.address_v4[0], + ta.address_v4.len().uint) + of AddressFamily.IPv6: + discard mbedtls_ssl_set_client_transport_id(addr self.ssl, + addr ta.address_v6[0], + ta.address_v6.len().uint) + else: discard # TODO: raise ? + + self.sendFuture = nil + let res = mbedtls_ssl_handshake_step(addr self.ssl) # TODO: Change in mbedtls.nim + echo "\e[34m\e[0m: ", res + if not self.sendFuture.isNil(): await self.sendFuture + echo "Result handshake step: ", res.mbedtls_high_level_strerr(), "(", res, ")" if res == MBEDTLS_ERR_SSL_WANT_READ or res == MBEDTLS_ERR_SSL_WANT_WRITE: echo if res == MBEDTLS_ERR_SSL_WANT_READ: "WANT_READ" else: "WANT_WRITE" continue + elif res == MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED: + echo "hello verification requested" + mb_ssl_session_reset(self.ssl) + endpoint = MBEDTLS_ERR_SSL_WANT_READ + continue elif res != 0: + echo "\e[31mRaise Whatever\e[0m" break # raise whatever endpoint = res proc accept*(self: Dtls, conn: WebRTCConn): Future[DtlsConn] {.async.} = - echo "1" var - srvcert = self.ctr_drbg.generateCertificate() - pkey = self.ctr_drbg.generateKey() selfvar = self res = DtlsConn() let v = cast[pointer](res) - echo v.repr await res.init(conn, self.address) mb_ssl_init(res.ssl) mb_ssl_config_init(res.config) + mbedtls_ssl_cookie_init(addr res.cookie) # TODO: Change in mbedtls.nim + mbedtls_ssl_cache_init(addr res.cache) # TODO: Change in mbedtls.nim + + mb_ctr_drbg_init(res.ctr_drbg) + mb_entropy_init(res.entropy) + mb_ctr_drbg_seed(res.ctr_drbg, mbedtls_entropy_func, res.entropy, nil, 0) + + var srvcert = res.ctr_drbg.generateCertificate() + echo "========> ", srvcert.version, " ", srvcert.raw.len + var pkey = res.ctr_drbg.generateKey() + mb_ssl_config_defaults(res.config, MBEDTLS_SSL_IS_SERVER, MBEDTLS_SSL_TRANSPORT_DATAGRAM, MBEDTLS_SSL_PRESET_DEFAULT) - mb_ssl_conf_rng(res.config, mbedtls_ctr_drbg_random, self.ctr_drbg) + mb_ssl_conf_rng(res.config, mbedtls_ctr_drbg_random, res.ctr_drbg) mb_ssl_conf_read_timeout(res.config, 10000) # in milliseconds mb_ssl_conf_ca_chain(res.config, srvcert.next, nil) mb_ssl_conf_own_cert(res.config, srvcert, pkey) + discard mbedtls_ssl_cookie_setup(addr res.cookie, mbedtls_ctr_drbg_random, addr res.ctr_drbg) # TODO: Change in mbedtls.nim + mbedtls_ssl_conf_dtls_cookies(addr res.config, mbedtls_ssl_cookie_write, + mbedtls_ssl_cookie_check, addr res.cookie) # TODO: Change in mbedtls.nim mbedtls_ssl_set_timer_cb(addr res.ssl, cast[pointer](addr res.timer), mbedtls_timing_set_delay, mbedtls_timing_get_delay) @@ -162,7 +196,6 @@ proc main() {.async.} = await udp.init(nil, laddr) let dtls = Dtls() dtls.start(laddr) - echo "Before accept" let x = await dtls.accept(udp) echo "After accept" diff --git a/webrtc/dtls/utils.nim b/webrtc/dtls/utils.nim index 63ed41e..78c4c92 100644 --- a/webrtc/dtls/utils.nim +++ b/webrtc/dtls/utils.nim @@ -18,11 +18,11 @@ import mbedtls/md proc mbedtls_pk_rsa*(pk: mbedtls_pk_context): ptr mbedtls_rsa_context = var key = pk - case mbedtls_pk_get_type(addr key): - of MBEDTLS_PK_RSA: - return cast[ptr mbedtls_rsa_context](pk.private_pk_ctx) - else: - return nil + case mbedtls_pk_get_type(addr key) + of MBEDTLS_PK_RSA: + return cast[ptr mbedtls_rsa_context](pk.private_pk_ctx) + else: + return nil template generateKey*(random: mbedtls_ctr_drbg_context): mbedtls_pk_context = var res: mbedtls_pk_context @@ -58,3 +58,38 @@ template generateCertificate*(random: mbedtls_ctr_drbg_context): mbedtls_x509_cr var res: mbedtls_x509_crt mb_x509_crt_parse(res, buf) res + + + +const mb_ssl_states* = @[ + "MBEDTLS_SSL_HELLO_REQUEST", + "MBEDTLS_SSL_CLIENT_HELLO", + "MBEDTLS_SSL_SERVER_HELLO", + "MBEDTLS_SSL_SERVER_CERTIFICATE", + "MBEDTLS_SSL_SERVER_KEY_EXCHANGE", + "MBEDTLS_SSL_CERTIFICATE_REQUEST", + "MBEDTLS_SSL_SERVER_HELLO_DONE", + "MBEDTLS_SSL_CLIENT_CERTIFICATE", + "MBEDTLS_SSL_CLIENT_KEY_EXCHANGE", + "MBEDTLS_SSL_CERTIFICATE_VERIFY", + "MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC", + "MBEDTLS_SSL_CLIENT_FINISHED", + "MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC", + "MBEDTLS_SSL_SERVER_FINISHED", + "MBEDTLS_SSL_FLUSH_BUFFERS", + "MBEDTLS_SSL_HANDSHAKE_WRAPUP", + "MBEDTLS_SSL_NEW_SESSION_TICKET", + "MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT", + "MBEDTLS_SSL_HELLO_RETRY_REQUEST", + "MBEDTLS_SSL_ENCRYPTED_EXTENSIONS", + "MBEDTLS_SSL_END_OF_EARLY_DATA", + "MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY", + "MBEDTLS_SSL_CLIENT_CCS_AFTER_SERVER_FINISHED", + "MBEDTLS_SSL_CLIENT_CCS_BEFORE_2ND_CLIENT_HELLO", + "MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO", + "MBEDTLS_SSL_CLIENT_CCS_AFTER_CLIENT_HELLO", + "MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST", + "MBEDTLS_SSL_HANDSHAKE_OVER", + "MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET", + "MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH" +] diff --git a/webrtc/stun/stun_connection.nim b/webrtc/stun/stun_connection.nim index e0d3a04..5edd9d4 100644 --- a/webrtc/stun/stun_connection.nim +++ b/webrtc/stun/stun_connection.nim @@ -46,3 +46,6 @@ method read(self: StunConn): Future[seq[byte]] {.async.} = await self.recvEvent.wait() result = self.recvData[0] self.recvData.delete(0..0) + +method getRemoteAddress*(self: StunConn): TransportAddress = + self.conn.getRemoteAddress() diff --git a/webrtc/udp_connection.nim b/webrtc/udp_connection.nim index 20a7173..6bd4952 100644 --- a/webrtc/udp_connection.nim +++ b/webrtc/udp_connection.nim @@ -17,19 +17,22 @@ logScope: type UdpConn* = ref object of WebRTCConn udp: DatagramTransport + remote: TransportAddress recvData: seq[seq[byte]] recvEvent: AsyncEvent -method init(self: UdpConn, conn: WebRTCConn, address: TransportAddress) {.async.} = - await procCall(WebRTCConn(self).init(conn, address)) +method init(self: UdpConn, conn: WebRTCConn, addrss: TransportAddress) {.async.} = + await procCall(WebRTCConn(self).init(conn, addrss)) proc onReceive(udp: DatagramTransport, address: TransportAddress) {.async, gcsafe.} = let msg = udp.getMessage() + echo "\e[33m\e[0;1m onReceive\e[0m: ", udp.getMessage().len() + self.remote = address self.recvData.add(msg) self.recvEvent.fire() self.recvEvent = newAsyncEvent() - self.udp = newDatagramTransport(onReceive, local = address) + self.udp = newDatagramTransport(onReceive, local = addrss) method close(self: UdpConn) {.async.} = self.udp.close() @@ -37,11 +40,16 @@ method close(self: UdpConn) {.async.} = await self.conn.close() method write(self: UdpConn, msg: seq[byte]) {.async.} = - await self.udp.sendTo(self.address, msg) + echo "\e[33m\e[0;1m write\e[0m" + await self.udp.sendTo(self.remote, msg) method read(self: UdpConn): Future[seq[byte]] {.async.} = + echo "\e[33m\e[0;1m read\e[0m" while self.recvData.len() <= 0: self.recvEvent.clear() await self.recvEvent.wait() result = self.recvData[0] self.recvData.delete(0..0) + +method getRemoteAddress*(self: UdpConn): TransportAddress = + self.remote diff --git a/webrtc/webrtc_connection.nim b/webrtc/webrtc_connection.nim index 5cdf63c..103d48c 100644 --- a/webrtc/webrtc_connection.nim +++ b/webrtc/webrtc_connection.nim @@ -28,3 +28,6 @@ method write*(self: WebRTCConn, msg: seq[byte]) {.async, base.} = method read*(self: WebRTCConn): Future[seq[byte]] {.async, base.} = doAssert(false, "not implemented!") + +method getRemoteAddress*(self: WebRTCConn): TransportAddress {.base.} = + doAssert(false, "not implemented") From bf8ea1bbaa8169eb2f1e7f80c1ac84ddb6d125d4 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Tue, 3 Oct 2023 16:36:38 +0200 Subject: [PATCH 25/66] Clear DTLS Server --- webrtc/dtls/dtls.nim | 47 +++++++-------------- webrtc/dtls/utils.nim | 97 +++++++++++++++++++++++-------------------- 2 files changed, 66 insertions(+), 78 deletions(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index b9441db..39a10d4 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -47,7 +47,6 @@ type entropy: mbedtls_entropy_context proc dtlsSend*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = - echo "\e[36m\e[0;1m Send\e[0m: ", len var self = cast[DtlsConn](ctx) var toWrite = newSeq[byte](len) if len > 0: @@ -57,16 +56,12 @@ proc dtlsSend*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = proc dtlsRecv*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = var self = cast[DtlsConn](ctx) - echo "\e[36m\e[0;1m Recv\e[0m: ", self.recvData[0].len() result = self.recvData[0].len().cint copyMem(buf, addr self.recvData[0][0], self.recvData[0].len()) self.recvData.delete(0..0) method init*(self: DtlsConn, conn: WebRTCConn, address: TransportAddress) {.async.} = await procCall(WebRTCConn(self).init(conn, address)) -# self.recvEvent = AsyncEvent() -# self.sendEvent = AsyncEvent() -# method write*(self: DtlsConn, msg: seq[byte]) {.async.} = var buf = msg @@ -109,38 +104,28 @@ proc handshake(self: DtlsConn) {.async.} = MBEDTLS_ERR_SSL_WANT_WRITE while self.ssl.private_state != MBEDTLS_SSL_HANDSHAKE_OVER: - echo "State: ", mb_ssl_states[self.ssl.private_state.int], "(", self.ssl.private_state, ")" - if endpoint == MBEDTLS_ERR_SSL_WANT_READ: + if endpoint == MBEDTLS_ERR_SSL_WANT_READ or + self.ssl.private_state == MBEDTLS_SSL_CLIENT_KEY_EXCHANGE: self.recvData.add(await self.conn.read()) - echo "=====> ", self.recvData.len() - # TODO: Change set_client_transport_id in mbedtls.nim directly var ta = self.getRemoteAddress() case ta.family of AddressFamily.IPv4: - discard mbedtls_ssl_set_client_transport_id(addr self.ssl, - addr ta.address_v4[0], - ta.address_v4.len().uint) - of AddressFamily.IPv6: - discard mbedtls_ssl_set_client_transport_id(addr self.ssl, - addr ta.address_v6[0], - ta.address_v6.len().uint) - else: discard # TODO: raise ? + mb_ssl_set_client_transport_id(self.ssl, ta.address_v4) + of AddressFamily.IPv6: + mb_ssl_set_client_transport_id(self.ssl, ta.address_v6) + else: + discard # TODO: raise ? self.sendFuture = nil - let res = mbedtls_ssl_handshake_step(addr self.ssl) # TODO: Change in mbedtls.nim - echo "\e[34m\e[0m: ", res + let res = mb_ssl_handshake_step(self.ssl) if not self.sendFuture.isNil(): await self.sendFuture - echo "Result handshake step: ", res.mbedtls_high_level_strerr(), "(", res, ")" if res == MBEDTLS_ERR_SSL_WANT_READ or res == MBEDTLS_ERR_SSL_WANT_WRITE: - echo if res == MBEDTLS_ERR_SSL_WANT_READ: "WANT_READ" else: "WANT_WRITE" continue elif res == MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED: - echo "hello verification requested" mb_ssl_session_reset(self.ssl) endpoint = MBEDTLS_ERR_SSL_WANT_READ continue elif res != 0: - echo "\e[31mRaise Whatever\e[0m" break # raise whatever endpoint = res @@ -153,16 +138,15 @@ proc accept*(self: Dtls, conn: WebRTCConn): Future[DtlsConn] {.async.} = await res.init(conn, self.address) mb_ssl_init(res.ssl) mb_ssl_config_init(res.config) - mbedtls_ssl_cookie_init(addr res.cookie) # TODO: Change in mbedtls.nim - mbedtls_ssl_cache_init(addr res.cache) # TODO: Change in mbedtls.nim + mb_ssl_cookie_init(res.cookie) + mb_ssl_cache_init(res.cache) mb_ctr_drbg_init(res.ctr_drbg) mb_entropy_init(res.entropy) mb_ctr_drbg_seed(res.ctr_drbg, mbedtls_entropy_func, res.entropy, nil, 0) - var srvcert = res.ctr_drbg.generateCertificate() - echo "========> ", srvcert.version, " ", srvcert.raw.len var pkey = res.ctr_drbg.generateKey() + var srvcert = res.ctr_drbg.generateCertificate(pkey) mb_ssl_config_defaults(res.config, MBEDTLS_SSL_IS_SERVER, @@ -172,12 +156,9 @@ proc accept*(self: Dtls, conn: WebRTCConn): Future[DtlsConn] {.async.} = mb_ssl_conf_read_timeout(res.config, 10000) # in milliseconds mb_ssl_conf_ca_chain(res.config, srvcert.next, nil) mb_ssl_conf_own_cert(res.config, srvcert, pkey) - discard mbedtls_ssl_cookie_setup(addr res.cookie, mbedtls_ctr_drbg_random, addr res.ctr_drbg) # TODO: Change in mbedtls.nim - mbedtls_ssl_conf_dtls_cookies(addr res.config, mbedtls_ssl_cookie_write, - mbedtls_ssl_cookie_check, addr res.cookie) # TODO: Change in mbedtls.nim - mbedtls_ssl_set_timer_cb(addr res.ssl, cast[pointer](addr res.timer), - mbedtls_timing_set_delay, - mbedtls_timing_get_delay) + mb_ssl_cookie_setup(res.cookie, mbedtls_ctr_drbg_random, res.ctr_drbg) + mb_ssl_conf_dtls_cookies(res.config, res.cookie) + mb_ssl_set_timer_cb(res.ssl, res.timer) # Add the cookie management (it works without, but it's more secure) mb_ssl_setup(res.ssl, res.config) mb_ssl_session_reset(res.ssl) diff --git a/webrtc/dtls/utils.nim b/webrtc/dtls/utils.nim index 78c4c92..6f9ad5b 100644 --- a/webrtc/dtls/utils.nim +++ b/webrtc/dtls/utils.nim @@ -9,6 +9,8 @@ import std/times +import stew/byteutils + import mbedtls/pk import mbedtls/rsa import mbedtls/ctr_drbg @@ -16,52 +18,9 @@ import mbedtls/x509_crt import mbedtls/bignum import mbedtls/md -proc mbedtls_pk_rsa*(pk: mbedtls_pk_context): ptr mbedtls_rsa_context = - var key = pk - case mbedtls_pk_get_type(addr key) - of MBEDTLS_PK_RSA: - return cast[ptr mbedtls_rsa_context](pk.private_pk_ctx) - else: - return nil +import chronicles -template generateKey*(random: mbedtls_ctr_drbg_context): mbedtls_pk_context = - var res: mbedtls_pk_context - mb_pk_init(res) - discard mbedtls_pk_setup(addr res, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) - mb_rsa_gen_key(mb_pk_rsa(res), mbedtls_ctr_drbg_random, random, 4096, 65537) - res - -template generateCertificate*(random: mbedtls_ctr_drbg_context): mbedtls_x509_crt = - let - name = "C=FR,O=webrtc,CN=webrtc" - time_format = initTimeFormat("YYYYMMddHHmmss") - time_from = times.now().format(time_format) - time_to = (times.now() + times.years(1)).format(time_format) - - var issuer_key = random.generateKey() - var write_cert: mbedtls_x509write_cert - var serial_mpi: mbedtls_mpi - mb_x509write_crt_init(write_cert) - mb_x509write_crt_set_md_alg(write_cert, MBEDTLS_MD_SHA256); - mb_x509write_crt_set_subject_key(write_cert, issuer_key) - mb_x509write_crt_set_issuer_key(write_cert, issuer_key) - mb_x509write_crt_set_subject_name(write_cert, name) - mb_x509write_crt_set_issuer_name(write_cert, name) - mb_x509write_crt_set_validity(write_cert, time_from, time_to) - mb_x509write_crt_set_basic_constraints(write_cert, 0, -1) - mb_x509write_crt_set_subject_key_identifier(write_cert) - mb_x509write_crt_set_authority_key_identifier(write_cert) - mb_mpi_init(serial_mpi) - let serial_hex = mb_mpi_read_string(serial_mpi, 16) - mb_x509write_crt_set_serial(write_cert, serial_mpi) - let buf = mb_x509write_crt_pem(write_cert, 4096, mbedtls_ctr_drbg_random, random) - var res: mbedtls_x509_crt - mb_x509_crt_parse(res, buf) - res - - - -const mb_ssl_states* = @[ +const mb_ssl_states* = @[ "MBEDTLS_SSL_HELLO_REQUEST", "MBEDTLS_SSL_CLIENT_HELLO", "MBEDTLS_SSL_SERVER_HELLO", @@ -93,3 +52,51 @@ const mb_ssl_states* = @[ "MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET", "MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH" ] + +proc mbedtls_pk_rsa*(pk: mbedtls_pk_context): ptr mbedtls_rsa_context = + var key = pk + case mbedtls_pk_get_type(addr key) + of MBEDTLS_PK_RSA: + return cast[ptr mbedtls_rsa_context](pk.private_pk_ctx) + else: + return nil + +template generateKey*(random: mbedtls_ctr_drbg_context): mbedtls_pk_context = + var res: mbedtls_pk_context + mb_pk_init(res) + discard mbedtls_pk_setup(addr res, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) + mb_rsa_gen_key(mb_pk_rsa(res), mbedtls_ctr_drbg_random, random, 2048, 65537) + let x = mb_pk_rsa(res) + res + +template generateCertificate*(random: mbedtls_ctr_drbg_context, + issuer_key: mbedtls_pk_context): mbedtls_x509_crt = + let + name = "C=FR,O=Status,CN=webrtc" + time_format = initTimeFormat("YYYYMMddHHmmss") + time_from = times.now().format(time_format) + time_to = (times.now() + times.years(1)).format(time_format) + + var write_cert: mbedtls_x509write_cert + var serial_mpi: mbedtls_mpi + mb_x509write_crt_init(write_cert) + mb_x509write_crt_set_md_alg(write_cert, MBEDTLS_MD_SHA256); + mb_x509write_crt_set_subject_key(write_cert, issuer_key) + mb_x509write_crt_set_issuer_key(write_cert, issuer_key) + mb_x509write_crt_set_subject_name(write_cert, name) + mb_x509write_crt_set_issuer_name(write_cert, name) + mb_x509write_crt_set_validity(write_cert, time_from, time_to) + mb_x509write_crt_set_basic_constraints(write_cert, 0, -1) + mb_x509write_crt_set_subject_key_identifier(write_cert) + mb_x509write_crt_set_authority_key_identifier(write_cert) + mb_mpi_init(serial_mpi) + let serial_hex = mb_mpi_read_string(serial_mpi, 16) + mb_x509write_crt_set_serial(write_cert, serial_mpi) + let buf = + try: + mb_x509write_crt_pem(write_cert, 2048, mbedtls_ctr_drbg_random, random) + except MbedTLSError as e: + raise e + var res: mbedtls_x509_crt + mb_x509_crt_parse(res, buf) + res From ca2b411f97023260f0a3f03e0fd38262e89283b4 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Thu, 5 Oct 2023 13:14:42 +0200 Subject: [PATCH 26/66] Finalize dtls server --- webrtc/dtls/dtls.nim | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 39a10d4..e78b75b 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -8,7 +8,6 @@ # those terms. import times, sequtils -import strutils # to remove import chronos, chronicles import ./utils, ../webrtc_connection @@ -31,6 +30,7 @@ logScope: topics = "webrtc dtls" type + DtlsError* = object of CatchableError DtlsConn* = ref object of WebRTCConn recvData: seq[seq[byte]] recvEvent: AsyncEvent @@ -96,16 +96,11 @@ proc stop*(self: Dtls) = self.started = false -proc handshake(self: DtlsConn) {.async.} = - var endpoint = - if self.ssl.private_conf.private_endpoint == MBEDTLS_SSL_IS_SERVER: - MBEDTLS_ERR_SSL_WANT_READ - else: - MBEDTLS_ERR_SSL_WANT_WRITE +proc serverHandshake(self: DtlsConn) {.async.} = + var shouldRead = true while self.ssl.private_state != MBEDTLS_SSL_HANDSHAKE_OVER: - if endpoint == MBEDTLS_ERR_SSL_WANT_READ or - self.ssl.private_state == MBEDTLS_SSL_CLIENT_KEY_EXCHANGE: + if shouldRead: self.recvData.add(await self.conn.read()) var ta = self.getRemoteAddress() case ta.family @@ -114,20 +109,24 @@ proc handshake(self: DtlsConn) {.async.} = of AddressFamily.IPv6: mb_ssl_set_client_transport_id(self.ssl, ta.address_v6) else: - discard # TODO: raise ? + raise newException(DtlsError, "Remote address isn't an IP address") self.sendFuture = nil let res = mb_ssl_handshake_step(self.ssl) + shouldRead = false if not self.sendFuture.isNil(): await self.sendFuture - if res == MBEDTLS_ERR_SSL_WANT_READ or res == MBEDTLS_ERR_SSL_WANT_WRITE: + if res == MBEDTLS_ERR_SSL_WANT_WRITE: + continue + elif res == MBEDTLS_ERR_SSL_WANT_READ or + self.ssl.private_state == MBEDTLS_SSL_CLIENT_KEY_EXCHANGE: + shouldRead = true continue elif res == MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED: mb_ssl_session_reset(self.ssl) - endpoint = MBEDTLS_ERR_SSL_WANT_READ + shouldRead = true continue elif res != 0: - break # raise whatever - endpoint = res + raise newException(DtlsError, $(res.mbedtls_high_level_strerr())) proc accept*(self: Dtls, conn: WebRTCConn): Future[DtlsConn] {.async.} = var @@ -159,12 +158,11 @@ proc accept*(self: Dtls, conn: WebRTCConn): Future[DtlsConn] {.async.} = mb_ssl_cookie_setup(res.cookie, mbedtls_ctr_drbg_random, res.ctr_drbg) mb_ssl_conf_dtls_cookies(res.config, res.cookie) mb_ssl_set_timer_cb(res.ssl, res.timer) - # Add the cookie management (it works without, but it's more secure) mb_ssl_setup(res.ssl, res.config) mb_ssl_session_reset(res.ssl) mb_ssl_set_bio(res.ssl, cast[pointer](res), dtlsSend, dtlsRecv, nil) - await res.handshake() + await res.serverHandshake() return res proc dial*(self: Dtls, address: TransportAddress): DtlsConn = From a1aeafc3a379608af2fccb1e156706ee0f08e995 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Thu, 5 Oct 2023 13:44:10 +0200 Subject: [PATCH 27/66] DataChannel: decoding / encoding --- tests/testdatachannel.nim | 25 +++++++++++++++++++++ webrtc/datachannel.nim | 46 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 tests/testdatachannel.nim create mode 100644 webrtc/datachannel.nim diff --git a/tests/testdatachannel.nim b/tests/testdatachannel.nim new file mode 100644 index 0000000..cf1a6a0 --- /dev/null +++ b/tests/testdatachannel.nim @@ -0,0 +1,25 @@ +import ../webrtc/datachannel +import chronos/unittest2/asynctests +import binary_serialization + +suite "DataChannel encoding": + test "DataChannelOpenMessage": + let msg = @[ + 0x03'u8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x03, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72] + check msg == Binary.encode(Binary.decode(msg, DataChannelMessage)) + check Binary.decode(msg, DataChannelMessage).openMessage == + DataChannelOpenMessage( + channelType: Reliable, + priority: 0, + reliabilityParameter: 0, + labelLength: 3, + protocolLength: 3, + label: @[102, 111, 111], + protocol: @[98, 97, 114] + ) + + test "DataChannelAck": + let msg = @[0x02'u8] + check msg == Binary.encode(Binary.decode(msg, DataChannelMessage)) + check Binary.decode(msg, DataChannelMessage).messageType == Ack diff --git a/webrtc/datachannel.nim b/webrtc/datachannel.nim new file mode 100644 index 0000000..4445831 --- /dev/null +++ b/webrtc/datachannel.nim @@ -0,0 +1,46 @@ +# Nim-WebRTC +# Copyright (c) 2023 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +# * MIT license ([LICENSE-MIT](LICENSE-MIT)) +# at your option. +# This file may not be copied, modified, or distributed except according to +# those terms. + +import chronos, + chronicles, + binary_serialization + +export binary_serialization + +logScope: + topics = "webrtc datachannel" + +type + DataChannelMessageType* {.size: 1.} = enum + Reserved = 0x00 + Ack = 0x02 + Open = 0x03 + + DataChannelMessage* = object + case messageType*: DataChannelMessageType + of Open: openMessage*: DataChannelOpenMessage + else: discard + + DataChannelType {.size: 1.} = enum + Reliable = 0x00 + PartialReliableRexmit = 0x01 + PartialReliableTimed = 0x02 + ReliableUnordered = 0x80 + PartialReliableRexmitUnordered = 0x81 + PartialReliableTimedUnorderd = 0x82 + + + DataChannelOpenMessage* = object + channelType*: DataChannelType + priority*: uint16 + reliabilityParameter*: uint32 + labelLength* {.bin_value: it.label.len.}: uint16 + protocolLength* {.bin_value: it.protocol.len.}: uint16 + label* {.bin_len: it.labelLength.}: seq[byte] + protocol* {.bin_len: it.protocolLength.}: seq[byte] From 9394c065acc6305dcdc16000e98a6789c4a6b8fc Mon Sep 17 00:00:00 2001 From: Tanguy Date: Fri, 6 Oct 2023 10:09:21 +0200 Subject: [PATCH 28/66] Start of SCTP integration --- webrtc/datachannel.nim | 155 ++++++++++++++++++++++++++++++++++++++++- webrtc/sctp.nim | 82 ++++++++++++++++------ 2 files changed, 214 insertions(+), 23 deletions(-) diff --git a/webrtc/datachannel.nim b/webrtc/datachannel.nim index 4445831..66bc9d3 100644 --- a/webrtc/datachannel.nim +++ b/webrtc/datachannel.nim @@ -7,16 +7,27 @@ # This file may not be copied, modified, or distributed except according to # those terms. +import tables + import chronos, chronicles, binary_serialization +import sctp + export binary_serialization logScope: topics = "webrtc datachannel" type + DataChannelProtocolIds* {.size: 4.} = enum + WebRtcDcep = 50 + WebRtcString = 51 + WebRtcBinary = 53 + WebRtcStringEmpty = 56 + WebRtcBinaryEmpty = 57 + DataChannelMessageType* {.size: 1.} = enum Reserved = 0x00 Ack = 0x02 @@ -35,7 +46,6 @@ type PartialReliableRexmitUnordered = 0x81 PartialReliableTimedUnorderd = 0x82 - DataChannelOpenMessage* = object channelType*: DataChannelType priority*: uint16 @@ -44,3 +54,146 @@ type protocolLength* {.bin_value: it.protocol.len.}: uint16 label* {.bin_len: it.labelLength.}: seq[byte] protocol* {.bin_len: it.protocolLength.}: seq[byte] + +proc ordered(t: DataChannelType): bool = + t in [Reliable, PartialReliableRexmit, PartialReliableTimed] + +type + #TODO handle closing + DataChannelStream* = ref object + id: uint16 + conn: SctpConnection + reliability: DataChannelType + reliabilityParameter: uint32 + receivedData: AsyncQueue[seq[byte]] + acked: bool + + #TODO handle closing + DataChannelConnection* = ref object + readLoopFut: Future[void] + streams: Table[uint16, DataChannelStream] + conn: SctpConnection + incomingStreams: AsyncQueue[DataChannelStream] + +proc read*(stream: DataChannelStream): Future[seq[byte]] {.async.} = + return await stream.receivedData.popLast() + +proc write*(stream: DataChannelStream, buf: seq[byte]) {.async.} = + var + sendInfo = SctpMessageParameters( + streamId: stream.id, + endOfRecord: true, + protocolId: uint32(WebRtcBinary) + ) + + if stream.acked: + sendInfo.unordered = not stream.reliability.ordered + #TODO add reliability params + + if buf.len == 0: + sendInfo.protocolId = uint32(WebRtcBinaryEmpty) + await stream.conn.write(@[0'u8], sendInfo) + else: + await stream.conn.write(buf, sendInfo) + +proc sendControlMessage(stream: DataChannelStream, msg: DataChannelMessage) {.async.} = + let + encoded = Binary.encode(msg) + sendInfo = SctpMessageParameters( + streamId: stream.id, + endOfRecord: true, + protocolId: uint32(WebRtcDcep) + ) + + await stream.conn.write(encoded, sendInfo) + +proc openStream*( + conn: DataChannelConnection, + streamId: uint16, + reliability = Reliable, reliabilityParameter: uint32 = 0): Future[DataChannelStream] {.async.} = + + if reliability in [Reliable, ReliableUnordered] and reliabilityParameter != 0: + raise newException(ValueError, "reliabilityParameter should be 0") + + if streamId in conn.streams: + raise newException(ValueError, "streamId already used") + + #TODO: we should request more streams when required + # https://github.com/sctplab/usrsctp/blob/a0cbf4681474fab1e89d9e9e2d5c3694fce50359/programs/rtcweb.c#L304C16-L304C16 + + var stream = DataChannelStream( + id: streamId, conn: conn.conn, + reliability: reliability, + reliabilityParameter: reliabilityParameter, + receivedData: newAsyncQueue[seq[byte]]() + ) + + conn.streams[streamId] = stream + + let + msg = DataChannelMessage( + messageType: Open, + openMessage: DataChannelOpenMessage( + channelType: reliability, + reliabilityParameter: reliabilityParameter + ) + ) + await stream.sendControlMessage(msg) + return stream + +proc handleData(conn: DataChannelConnection, msg: SctpMessage) = + let streamId = msg.params.streamId + + if streamId notin conn.streams: + raise newException(ValueError, "got data for unknown streamid") + + let stream = conn.streams[streamId] + + #TODO handle string vs binary + if msg.params.protocolId in [uint32(WebRtcStringEmpty), uint32(WebRtcBinaryEmpty)]: + # PPID indicate empty message + stream.receivedData.addLastNoWait(@[]) + else: + stream.receivedData.addLastNoWait(msg.data) + +proc handleControl(conn: DataChannelConnection, msg: SctpMessage) {.async.} = + let + decoded = Binary.decode(msg.data, DataChannelMessage) + streamId = msg.params.streamId + + if decoded.messageType == Ack: + if streamId notin conn.streams: + raise newException(ValueError, "got ack for unknown streamid") + conn.streams[streamId].acked = true + elif decoded.messageType == Open: + if streamId in conn.streams: + raise newException(ValueError, "got open for already existing streamid") + + let stream = DataChannelStream( + id: streamId, conn: conn.conn, + reliability: decoded.openMessage.channelType, + reliabilityParameter: decoded.openMessage.reliabilityParameter, + receivedData: newAsyncQueue[seq[byte]]() + ) + + conn.streams[streamId] = stream + + await stream.sendControlMessage(DataChannelMessage(messageType: Ack)) + +proc readLoop(conn: DataChannelConnection) {.async.} = + try: + while true: + let message = await conn.conn.read() + if message.params.protocolId == uint32(WebRtcDcep): + #TODO should we really await? + await conn.handleControl(message) + else: + conn.handleData(message) + + except CatchableError as exc: + discard + +proc accept*(conn: DataChannelConnection): Future[DataChannelStream] {.async.} = + if isNil(conn.readLoopFut): + conn.readLoopFut = conn.readLoop() + return await conn.incomingStreams.popFirst() diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index 7206c37..4d3f376 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -24,6 +24,17 @@ type Connected Closed + SctpMessageParameters* = object + protocolId*: uint32 + streamId*: uint16 + endOfRecord*: bool + unordered*: bool + + SctpMessage* = ref object + data*: seq[byte] + info: sctp_rcvinfo + params*: SctpMessageParameters + SctpConnection* = ref object state: SctpState connectEvent: AsyncEvent @@ -31,8 +42,7 @@ type udp: DatagramTransport address: TransportAddress sctpSocket: ptr socket - recvEvent: AsyncEvent - dataRecv: seq[byte] + dataRecv: AsyncQueue[SctpMessage] Sctp* = ref object udp: DatagramTransport @@ -85,25 +95,43 @@ proc new(T: typedesc[SctpConnection], address: address, sctpSocket: sctpSocket, connectEvent: AsyncEvent(), - recvEvent: AsyncEvent()) + #TODO add some limit for backpressure? + dataRecv: newAsyncQueue[SctpMessage]() + ) -proc read*(self: SctpConnection): Future[seq[byte]] {.async.} = - trace "Read" - if self.dataRecv.len == 0: - self.recvEvent.clear() - await self.recvEvent.wait() - let res = self.dataRecv - self.dataRecv = @[] - return res +proc read*(self: SctpConnection): Future[SctpMessage] {.async.} = + return await self.dataRecv.popFirst() -proc write*(self: SctpConnection, buf: seq[byte]) {.async.} = +proc toFlags(params: SctpMessageParameters): uint16 = + if params.endOfRecord: + result = result or SCTP_EOR + if params.unordered: + result = result or SCTP_UNORDERED + +proc write*( + self: SctpConnection, + buf: seq[byte], + sendParams = default(SctpMessageParameters), + ) {.async.} = trace "Write", buf self.sctp.sentConnection = self self.sctp.sentAddress = self.address - let sendvErr = self.sctp.usrsctpAwait: - self.sctpSocket.usrsctp_sendv(unsafeAddr buf[0], buf.len.uint, - nil, 0, nil, 0, - SCTP_SENDV_NOINFO, 0) + + let + (sendInfo, infoType) = + if sendParams != default(SctpMessageParameters): + (sctp_sndinfo( + snd_sid: sendParams.streamId, + #TODO endianness? + snd_ppid: sendParams.protocolId, + snd_flags: sendParams.toFlags + ), cuint(SCTP_SENDV_SNDINFO)) + else: + (default(sctp_sndinfo), cuint(SCTP_SENDV_NOINFO)) + sendvErr = self.sctp.usrsctpAwait: + self.sctpSocket.usrsctp_sendv(unsafeAddr buf[0], buf.len.uint, + nil, 0, unsafeAddr sendInfo, sizeof(sendInfo).SockLen, + infoType, 0) proc write*(self: SctpConnection, s: string) {.async.} = await self.write(s.toBytes()) @@ -125,17 +153,19 @@ proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = conn.connectEvent.fire() elif bitand(events, SCTP_EVENT_READ) != 0: var - buffer = newSeq[byte](4096) + message = SctpMessage( + data: newSeq[byte](4096) + ) address: Sockaddr_storage rn: sctp_recvv_rn addressLen = sizeof(Sockaddr_storage).SockLen - rnLen = sizeof(sctp_recvv_rn).SockLen + rnLen = sizeof(message.info).SockLen infotype: uint flags: int - let n = sock.usrsctp_recvv(cast[pointer](addr buffer[0]), buffer.len.uint, + let n = sock.usrsctp_recvv(cast[pointer](addr message.data[0]), message.data.len.uint, cast[ptr SockAddr](addr address), cast[ptr SockLen](addr addressLen), - cast[pointer](addr rn), + cast[pointer](addr message.info), cast[ptr SockLen](addr rnLen), cast[ptr cuint](addr infotype), cast[ptr cint](addr flags)) @@ -143,11 +173,19 @@ proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = perror("usrsctp_recvv") return elif n > 0: + if infotype == SCTP_RECVV_RCVINFO: + message.params = SctpMessageParameters( + #TODO endianness? + protocolId: message.info.rcv_ppid, + streamId: message.info.rcv_sid + ) if bitand(flags, MSG_NOTIFICATION) != 0: trace "Notification received", length = n else: - conn.dataRecv = conn.dataRecv.concat(buffer[0.. Date: Fri, 6 Oct 2023 17:33:41 +0200 Subject: [PATCH 29/66] rework udp and stun connection after removing webrtc connection --- webrtc/stun/stun_connection.nim | 25 +++++++++++++------------ webrtc/udp_connection.nim | 26 +++++++++++--------------- webrtc/webrtc_connection.nim | 33 --------------------------------- 3 files changed, 24 insertions(+), 60 deletions(-) delete mode 100644 webrtc/webrtc_connection.nim diff --git a/webrtc/stun/stun_connection.nim b/webrtc/stun/stun_connection.nim index 5edd9d4..823d410 100644 --- a/webrtc/stun/stun_connection.nim +++ b/webrtc/stun/stun_connection.nim @@ -8,27 +8,30 @@ # those terms. import chronos -import ../webrtc_connection, stun +import ../udp_connection, stun type - StunConn* = ref object of WebRTCConn - recvData: seq[seq[byte]] + StunConn* = ref object + conn: UdpConn + address: TransportAddress + recvData: seq[(seq[byte], TransportAddress)] recvEvent: AsyncEvent handlesFut: Future[void] proc handles(self: StunConn) {.async.} = while true: # TODO: while not self.conn.atEof() - let msg = await self.conn.read() + let (msg, address) = await self.conn.read() if Stun.isMessage(msg): let res = Stun.getResponse(msg, self.address) if res.isSome(): await self.conn.write(res.get()) else: - self.recvData.add(msg) + self.recvData.add((msg, address)) self.recvEvent.fire() -method init(self: StunConn, conn: WebRTCConn, address: TransportAddress) {.async.} = - await procCall(WebRTCConn(self).init(conn, address)) +method init(self: StunConn, conn: UdpConn, address: TransportAddress) {.async.} = + self.conn = conn + self.address = address self.recvEvent = newAsyncEvent() self.handlesFut = handles() @@ -40,12 +43,10 @@ method close(self: StunConn) {.async.} = method write(self: StunConn, msg: seq[byte]) {.async.} = await self.conn.write(msg) -method read(self: StunConn): Future[seq[byte]] {.async.} = +method read(self: StunConn): Future[(seq[byte], TransportAddress)] {.async.} = while self.recvData.len() <= 0: self.recvEvent.clear() await self.recvEvent.wait() - result = self.recvData[0] + let res = self.recvData[0] self.recvData.delete(0..0) - -method getRemoteAddress*(self: StunConn): TransportAddress = - self.conn.getRemoteAddress() + return res diff --git a/webrtc/udp_connection.nim b/webrtc/udp_connection.nim index 6bd4952..53146dd 100644 --- a/webrtc/udp_connection.nim +++ b/webrtc/udp_connection.nim @@ -15,41 +15,37 @@ logScope: topics = "webrtc udp" type - UdpConn* = ref object of WebRTCConn + UdpConn* = ref object + localAddress: TransportAddress udp: DatagramTransport - remote: TransportAddress - recvData: seq[seq[byte]] + recvData: seq[(seq[byte], TransportAddress)] recvEvent: AsyncEvent -method init(self: UdpConn, conn: WebRTCConn, addrss: TransportAddress) {.async.} = - await procCall(WebRTCConn(self).init(conn, addrss)) +proc init(self: UdpConn, laddr: TransportAddress) {.async.} = + self.localAddress = laddr proc onReceive(udp: DatagramTransport, address: TransportAddress) {.async, gcsafe.} = let msg = udp.getMessage() - echo "\e[33m\e[0;1m onReceive\e[0m: ", udp.getMessage().len() - self.remote = address - self.recvData.add(msg) + echo "\e[33m\e[0;1m onReceive\e[0m: ", msg.len() + self.recvData.add((msg, address)) self.recvEvent.fire() self.recvEvent = newAsyncEvent() - self.udp = newDatagramTransport(onReceive, local = addrss) + self.udp = newDatagramTransport(onReceive, local = laddr) -method close(self: UdpConn) {.async.} = +proc close(self: UdpConn) {.async.} = self.udp.close() if not self.conn.isNil(): await self.conn.close() -method write(self: UdpConn, msg: seq[byte]) {.async.} = +proc write(self: UdpConn, msg: seq[byte]) {.async.} = echo "\e[33m\e[0;1m write\e[0m" await self.udp.sendTo(self.remote, msg) -method read(self: UdpConn): Future[seq[byte]] {.async.} = +proc read(self: UdpConn): Future[(seq[byte], TransportAddress)] {.async.} = echo "\e[33m\e[0;1m read\e[0m" while self.recvData.len() <= 0: self.recvEvent.clear() await self.recvEvent.wait() result = self.recvData[0] self.recvData.delete(0..0) - -method getRemoteAddress*(self: UdpConn): TransportAddress = - self.remote diff --git a/webrtc/webrtc_connection.nim b/webrtc/webrtc_connection.nim deleted file mode 100644 index 103d48c..0000000 --- a/webrtc/webrtc_connection.nim +++ /dev/null @@ -1,33 +0,0 @@ -# Nim-WebRTC -# Copyright (c) 2023 Status Research & Development GmbH -# Licensed under either of -# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) -# * MIT license ([LICENSE-MIT](LICENSE-MIT)) -# at your option. -# This file may not be copied, modified, or distributed except according to -# those terms. - -import chronos - -type - WebRTCConn* = ref object of RootObj - conn*: WebRTCConn - address*: TransportAddress - # isClosed: bool - # isEof: bool - -method init*(self: WebRTCConn, conn: WebRTCConn, address: TransportAddress) {.async, base.} = - self.conn = conn - self.address = address - -method close*(self: WebRTCConn) {.async, base.} = - doAssert(false, "not implemented!") - -method write*(self: WebRTCConn, msg: seq[byte]) {.async, base.} = - doAssert(false, "not implemented!") - -method read*(self: WebRTCConn): Future[seq[byte]] {.async, base.} = - doAssert(false, "not implemented!") - -method getRemoteAddress*(self: WebRTCConn): TransportAddress {.base.} = - doAssert(false, "not implemented") From 397c84238aa66e5adec689a481bc4990f1d7e2aa Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 6 Oct 2023 17:56:15 +0200 Subject: [PATCH 30/66] add asyncqueue & minor fixes --- webrtc/stun/stun_connection.nim | 29 +++++++++++------------------ webrtc/udp_connection.nim | 18 ++++++------------ 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/webrtc/stun/stun_connection.nim b/webrtc/stun/stun_connection.nim index 823d410..a00f48b 100644 --- a/webrtc/stun/stun_connection.nim +++ b/webrtc/stun/stun_connection.nim @@ -13,40 +13,33 @@ import ../udp_connection, stun type StunConn* = ref object conn: UdpConn - address: TransportAddress - recvData: seq[(seq[byte], TransportAddress)] - recvEvent: AsyncEvent + laddr: TransportAddress + dataRecv: AsyncQueue[(seq[byte], TransportAddress)] handlesFut: Future[void] proc handles(self: StunConn) {.async.} = while true: # TODO: while not self.conn.atEof() let (msg, address) = await self.conn.read() if Stun.isMessage(msg): - let res = Stun.getResponse(msg, self.address) + let res = Stun.getResponse(msg, self.laddr) if res.isSome(): await self.conn.write(res.get()) else: - self.recvData.add((msg, address)) - self.recvEvent.fire() + self.dataRecv.addLastNoWait((msg, address)) -method init(self: StunConn, conn: UdpConn, address: TransportAddress) {.async.} = +proc init(self: StunConn, conn: UdpConn, laddr: TransportAddress) {.async.} = self.conn = conn - self.address = address + self.laddr = laddr - self.recvEvent = newAsyncEvent() + self.dataRecv = newAsyncQueue() self.handlesFut = handles() -method close(self: StunConn) {.async.} = +proc close(self: StunConn) {.async.} = self.handlesFut.cancel() # check before? self.conn.close() -method write(self: StunConn, msg: seq[byte]) {.async.} = +proc write(self: StunConn, msg: seq[byte]) {.async.} = await self.conn.write(msg) -method read(self: StunConn): Future[(seq[byte], TransportAddress)] {.async.} = - while self.recvData.len() <= 0: - self.recvEvent.clear() - await self.recvEvent.wait() - let res = self.recvData[0] - self.recvData.delete(0..0) - return res +proc read(self: StunConn): Future[(seq[byte], TransportAddress)] {.async.} = + return await self.dataRecv.popFirst() diff --git a/webrtc/udp_connection.nim b/webrtc/udp_connection.nim index 53146dd..d612c10 100644 --- a/webrtc/udp_connection.nim +++ b/webrtc/udp_connection.nim @@ -16,21 +16,19 @@ logScope: type UdpConn* = ref object - localAddress: TransportAddress + laddr: TransportAddress udp: DatagramTransport - recvData: seq[(seq[byte], TransportAddress)] - recvEvent: AsyncEvent + dataRecv: AsyncQueue[(seq[byte], TransportAddress)] proc init(self: UdpConn, laddr: TransportAddress) {.async.} = - self.localAddress = laddr + self.laddr = laddr proc onReceive(udp: DatagramTransport, address: TransportAddress) {.async, gcsafe.} = let msg = udp.getMessage() echo "\e[33m\e[0;1m onReceive\e[0m: ", msg.len() - self.recvData.add((msg, address)) - self.recvEvent.fire() + self.dataRecv.addLastNoWait((msg, address)) - self.recvEvent = newAsyncEvent() + self.dataRecv = newAsyncQueue() self.udp = newDatagramTransport(onReceive, local = laddr) proc close(self: UdpConn) {.async.} = @@ -44,8 +42,4 @@ proc write(self: UdpConn, msg: seq[byte]) {.async.} = proc read(self: UdpConn): Future[(seq[byte], TransportAddress)] {.async.} = echo "\e[33m\e[0;1m read\e[0m" - while self.recvData.len() <= 0: - self.recvEvent.clear() - await self.recvEvent.wait() - result = self.recvData[0] - self.recvData.delete(0..0) + return await self.dataRecv.popFirst() From 2a9b8298eb4aa9de5b5bc414b0e588fa3296754f Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Tue, 10 Oct 2023 17:38:31 +0200 Subject: [PATCH 31/66] Multiple fixes on stun / udp / dtls --- webrtc/dtls/dtls.nim | 131 ++++++++++++++++++++++---------- webrtc/sctp.nim | 5 +- webrtc/stun/stun_connection.nim | 22 +++--- webrtc/udp_connection.nim | 15 ++-- 4 files changed, 111 insertions(+), 62 deletions(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index e78b75b..19608a2 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -7,9 +7,9 @@ # This file may not be copied, modified, or distributed except according to # those terms. -import times, sequtils +import times, deques, tables import chronos, chronicles -import ./utils, ../webrtc_connection +import ./utils, ../stun/stun_connection import mbedtls/ssl import mbedtls/ssl_cookie @@ -29,11 +29,19 @@ import mbedtls/timing logScope: topics = "webrtc dtls" +# TODO: Check the viability of the add/pop first/last of the asyncqueue with the limit. +# There might be some errors (or crashes) in weird cases with the no wait option + +const + PendingHandshakeLimit = 1024 + type DtlsError* = object of CatchableError - DtlsConn* = ref object of WebRTCConn - recvData: seq[seq[byte]] - recvEvent: AsyncEvent + DtlsConn* = ref object + conn: StunConn + laddr: TransportAddress + raddr: TransportAddress + dataRecv: AsyncQueue[seq[byte]] sendFuture: Future[void] timer: mbedtls_timing_delay_context @@ -51,70 +59,99 @@ proc dtlsSend*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = var toWrite = newSeq[byte](len) if len > 0: copyMem(addr toWrite[0], buf, len) - self.sendFuture = self.conn.write(toWrite) + self.sendFuture = self.conn.write(self.raddr, toWrite) result = len.cint proc dtlsRecv*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = - var self = cast[DtlsConn](ctx) - result = self.recvData[0].len().cint - copyMem(buf, addr self.recvData[0][0], self.recvData[0].len()) - self.recvData.delete(0..0) + var + self = cast[DtlsConn](ctx) + dataRecv = self.dataRecv.popFirstNoWait() + copyMem(buf, addr dataRecv[0], dataRecv.len()) + result = dataRecv.len().cint -method init*(self: DtlsConn, conn: WebRTCConn, address: TransportAddress) {.async.} = - await procCall(WebRTCConn(self).init(conn, address)) +proc init*(self: DtlsConn, conn: StunConn, laddr: TransportAddress) {.async.} = + self.conn = conn + self.laddr = laddr + self.dataRecv = newAsyncQueue[seq[byte]]() -method write*(self: DtlsConn, msg: seq[byte]) {.async.} = +proc write*(self: DtlsConn, msg: seq[byte]) {.async.} = var buf = msg discard mbedtls_ssl_write(addr self.ssl, cast[ptr byte](addr buf[0]), buf.len().uint) -method read*(self: DtlsConn): Future[seq[byte]] {.async.} = - return await self.conn.read() +proc read*(self: DtlsConn): Future[seq[byte]] {.async.} = + var res = newSeq[byte](8192) + let tmp = await self.dataRecv.popFirst() + self.dataRecv.addFirstNoWait(tmp) + let length = mbedtls_ssl_read(addr self.ssl, cast[ptr byte](addr res[0]), res.len().uint) + res.setLen(length) + return res -method close*(self: DtlsConn) {.async.} = +proc close*(self: DtlsConn) {.async.} = discard -method getRemoteAddress*(self: DtlsConn): TransportAddress = - self.conn.getRemoteAddress() - type Dtls* = ref object of RootObj - address: TransportAddress + connections: Table[TransportAddress, DtlsConn] + pendingHandshakes: AsyncQueue[(TransportAddress, seq[byte])] + conn: StunConn + laddr: TransportAddress started: bool + readLoop: Future[void] -proc start*(self: Dtls, address: TransportAddress) = +proc updateOrAdd(aq: AsyncQueue[(TransportAddress, seq[byte])], + raddr: TransportAddress, buf: seq[byte]) = + for (k, v) in aq.mitems(): + if k == raddr: + v = buf + return + aq.addLastNoWait((raddr, buf)) + +proc start*(self: Dtls, conn: StunConn, laddr: TransportAddress) = if self.started: warn "Already started" return - self.address = address + proc readLoop() {.async.} = + while true: + let (buf, raddr) = await self.conn.read() + if self.connections.hasKey(raddr): + self.connections[raddr].dataRecv.addLastNoWait(buf) + else: + self.pendingHandshakes.updateOrAdd(raddr, buf) + + self.connections = initTable[TransportAddress, DtlsConn]() + self.pendingHandshakes = newAsyncQueue[(TransportAddress, seq[byte])](PendingHandshakeLimit) + self.conn = conn + self.laddr = laddr self.started = true + self.readLoop = readLoop() proc stop*(self: Dtls) = if not self.started: warn "Already stopped" return + self.readLoop.cancel() self.started = false proc serverHandshake(self: DtlsConn) {.async.} = - var shouldRead = true + case self.raddr.family + of AddressFamily.IPv4: + mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v4) + of AddressFamily.IPv6: + mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v6) + else: + raise newException(DtlsError, "Remote address isn't an IP address") + var shouldRead = true while self.ssl.private_state != MBEDTLS_SSL_HANDSHAKE_OVER: if shouldRead: - self.recvData.add(await self.conn.read()) - var ta = self.getRemoteAddress() - case ta.family - of AddressFamily.IPv4: - mb_ssl_set_client_transport_id(self.ssl, ta.address_v4) - of AddressFamily.IPv6: - mb_ssl_set_client_transport_id(self.ssl, ta.address_v6) - else: - raise newException(DtlsError, "Remote address isn't an IP address") - + let tmp = await self.dataRecv.popFirst() + self.dataRecv.addFirstNoWait(tmp) self.sendFuture = nil let res = mb_ssl_handshake_step(self.ssl) - shouldRead = false if not self.sendFuture.isNil(): await self.sendFuture + shouldRead = false if res == MBEDTLS_ERR_SSL_WANT_WRITE: continue elif res == MBEDTLS_ERR_SSL_WANT_READ or @@ -128,13 +165,13 @@ proc serverHandshake(self: DtlsConn) {.async.} = elif res != 0: raise newException(DtlsError, $(res.mbedtls_high_level_strerr())) -proc accept*(self: Dtls, conn: WebRTCConn): Future[DtlsConn] {.async.} = +proc accept*(self: Dtls): Future[DtlsConn] {.async.} = var selfvar = self res = DtlsConn() let v = cast[pointer](res) - await res.init(conn, self.address) + await res.init(self.conn, self.laddr) mb_ssl_init(res.ssl) mb_ssl_config_init(res.config) mb_ssl_cookie_init(res.cookie) @@ -162,20 +199,32 @@ proc accept*(self: Dtls, conn: WebRTCConn): Future[DtlsConn] {.async.} = mb_ssl_session_reset(res.ssl) mb_ssl_set_bio(res.ssl, cast[pointer](res), dtlsSend, dtlsRecv, nil) - await res.serverHandshake() + while true: + let (raddr, buf) = await self.pendingHandshakes.popFirst() + try: + res.raddr = raddr + res.dataRecv.addLastNoWait(buf) + self.connections[raddr] = res + await res.serverHandshake() + except CatchableError as exc: + trace "Handshake fail", remoteAddress = raddr, error = exc.msg + self.connections.del(raddr) + continue return res -proc dial*(self: Dtls, address: TransportAddress): DtlsConn = +proc dial*(self: Dtls, raddr: TransportAddress): DtlsConn = discard import ../udp_connection proc main() {.async.} = let laddr = initTAddress("127.0.0.1:4433") let udp = UdpConn() - await udp.init(nil, laddr) + await udp.init(laddr) + let stun = StunConn() + await stun.init(udp, laddr) let dtls = Dtls() - dtls.start(laddr) - let x = await dtls.accept(udp) + dtls.start(stun, laddr) + let x = await dtls.accept() echo "After accept" waitFor(main()) diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index 4d3f376..3b14509 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -10,6 +10,7 @@ import tables, bitops, posix, strutils, sequtils import chronos, chronicles, stew/[ranges/ptr_arith, byteutils] import usrsctp +import dtls/dtls export chronicles @@ -36,6 +37,7 @@ type params*: SctpMessageParameters SctpConnection* = ref object + conn: DtlsConn state: SctpState connectEvent: AsyncEvent sctp: Sctp @@ -45,8 +47,9 @@ type dataRecv: AsyncQueue[SctpMessage] Sctp* = ref object + dtls: Dtls udp: DatagramTransport - connections: Table[TransportAddress, SctpConnection] + #connections: Table[TransportAddress, SctpConnection] gotConnection: AsyncEvent timersHandler: Future[void] isServer: bool diff --git a/webrtc/stun/stun_connection.nim b/webrtc/stun/stun_connection.nim index a00f48b..aea422a 100644 --- a/webrtc/stun/stun_connection.nim +++ b/webrtc/stun/stun_connection.nim @@ -19,27 +19,27 @@ type proc handles(self: StunConn) {.async.} = while true: # TODO: while not self.conn.atEof() - let (msg, address) = await self.conn.read() + let (msg, raddr) = await self.conn.read() if Stun.isMessage(msg): let res = Stun.getResponse(msg, self.laddr) if res.isSome(): - await self.conn.write(res.get()) + await self.conn.write(raddr, res.get()) else: - self.dataRecv.addLastNoWait((msg, address)) + self.dataRecv.addLastNoWait((msg, raddr)) -proc init(self: StunConn, conn: UdpConn, laddr: TransportAddress) {.async.} = +proc init*(self: StunConn, conn: UdpConn, laddr: TransportAddress) {.async.} = self.conn = conn self.laddr = laddr - self.dataRecv = newAsyncQueue() - self.handlesFut = handles() + self.dataRecv = newAsyncQueue[(seq[byte], TransportAddress)]() + self.handlesFut = self.handles() -proc close(self: StunConn) {.async.} = +proc close*(self: StunConn) {.async.} = self.handlesFut.cancel() # check before? - self.conn.close() + await self.conn.close() -proc write(self: StunConn, msg: seq[byte]) {.async.} = - await self.conn.write(msg) +proc write*(self: StunConn, raddr: TransportAddress, msg: seq[byte]) {.async.} = + await self.conn.write(raddr, msg) -proc read(self: StunConn): Future[(seq[byte], TransportAddress)] {.async.} = +proc read*(self: StunConn): Future[(seq[byte], TransportAddress)] {.async.} = return await self.dataRecv.popFirst() diff --git a/webrtc/udp_connection.nim b/webrtc/udp_connection.nim index d612c10..3c28aef 100644 --- a/webrtc/udp_connection.nim +++ b/webrtc/udp_connection.nim @@ -9,7 +9,6 @@ import sequtils import chronos, chronicles -import webrtc_connection logScope: topics = "webrtc udp" @@ -20,7 +19,7 @@ type udp: DatagramTransport dataRecv: AsyncQueue[(seq[byte], TransportAddress)] -proc init(self: UdpConn, laddr: TransportAddress) {.async.} = +proc init*(self: UdpConn, laddr: TransportAddress) {.async.} = self.laddr = laddr proc onReceive(udp: DatagramTransport, address: TransportAddress) {.async, gcsafe.} = @@ -28,18 +27,16 @@ proc init(self: UdpConn, laddr: TransportAddress) {.async.} = echo "\e[33m\e[0;1m onReceive\e[0m: ", msg.len() self.dataRecv.addLastNoWait((msg, address)) - self.dataRecv = newAsyncQueue() + self.dataRecv = newAsyncQueue[(seq[byte], TransportAddress)]() self.udp = newDatagramTransport(onReceive, local = laddr) -proc close(self: UdpConn) {.async.} = +proc close*(self: UdpConn) {.async.} = self.udp.close() - if not self.conn.isNil(): - await self.conn.close() -proc write(self: UdpConn, msg: seq[byte]) {.async.} = +proc write*(self: UdpConn, raddr: TransportAddress, msg: seq[byte]) {.async.} = echo "\e[33m\e[0;1m write\e[0m" - await self.udp.sendTo(self.remote, msg) + await self.udp.sendTo(raddr, msg) -proc read(self: UdpConn): Future[(seq[byte], TransportAddress)] {.async.} = +proc read*(self: UdpConn): Future[(seq[byte], TransportAddress)] {.async.} = echo "\e[33m\e[0;1m read\e[0m" return await self.dataRecv.popFirst() From 4e576e0bb9308482f376d548aa3d7406f5f33336 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Wed, 11 Oct 2023 13:17:53 +0200 Subject: [PATCH 32/66] Last dtls fixes --- webrtc/dtls/dtls.nim | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 19608a2..12208a3 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -100,9 +100,9 @@ type proc updateOrAdd(aq: AsyncQueue[(TransportAddress, seq[byte])], raddr: TransportAddress, buf: seq[byte]) = - for (k, v) in aq.mitems(): - if k == raddr: - v = buf + for kv in aq.mitems(): + if kv[0] == raddr: + kv[1] = buf return aq.addLastNoWait((raddr, buf)) @@ -135,17 +135,16 @@ proc stop*(self: Dtls) = self.started = false proc serverHandshake(self: DtlsConn) {.async.} = - case self.raddr.family - of AddressFamily.IPv4: - mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v4) - of AddressFamily.IPv6: - mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v6) - else: - raise newException(DtlsError, "Remote address isn't an IP address") - var shouldRead = true while self.ssl.private_state != MBEDTLS_SSL_HANDSHAKE_OVER: if shouldRead: + case self.raddr.family + of AddressFamily.IPv4: + mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v4) + of AddressFamily.IPv6: + mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v6) + else: + raise newException(DtlsError, "Remote address isn't an IP address") let tmp = await self.dataRecv.popFirst() self.dataRecv.addFirstNoWait(tmp) self.sendFuture = nil @@ -206,6 +205,7 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} = res.dataRecv.addLastNoWait(buf) self.connections[raddr] = res await res.serverHandshake() + break except CatchableError as exc: trace "Handshake fail", remoteAddress = raddr, error = exc.msg self.connections.del(raddr) @@ -216,6 +216,7 @@ proc dial*(self: Dtls, raddr: TransportAddress): DtlsConn = discard import ../udp_connection +import stew/byteutils proc main() {.async.} = let laddr = initTAddress("127.0.0.1:4433") let udp = UdpConn() @@ -225,6 +226,6 @@ proc main() {.async.} = let dtls = Dtls() dtls.start(stun, laddr) let x = await dtls.accept() - echo "After accept" + echo "Recv: <", string.fromBytes(await x.read()), ">" waitFor(main()) From 95c4805ab6c21ac2af3bb60cf755fa5c175fc9c3 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 13 Oct 2023 13:58:30 +0200 Subject: [PATCH 33/66] Multiple fixes on sctp --- examples/pong.nim | 29 ++++++++ webrtc/dtls/dtls.nim | 30 ++++---- webrtc/sctp.nim | 168 ++++++++++++++++++++++++++----------------- 3 files changed, 148 insertions(+), 79 deletions(-) create mode 100644 examples/pong.nim diff --git a/examples/pong.nim b/examples/pong.nim new file mode 100644 index 0000000..d7cb0bb --- /dev/null +++ b/examples/pong.nim @@ -0,0 +1,29 @@ +import chronos, stew/byteutils +import ../webrtc/udp_connection +import ../webrtc/stun/stun_connection +import ../webrtc/dtls/dtls +import ../webrtc/sctp + +proc sendPong(conn: SctpConn) {.async.} = + var i = 0 + while true: + let msg = await conn.read() + echo "Received: ", string.fromBytes(msg.data) + await conn.write(("pong " & $i).toBytes) + i.inc() + +proc main() {.async.} = + let laddr = initTAddress("127.0.0.1:4242") + let udp = UdpConn() + await udp.init(laddr) + let stun = StunConn() + await stun.init(udp, laddr) + let dtls = Dtls() + dtls.start(stun, laddr) + let sctp = Sctp.new(dtls, laddr) + await sctp.listen(13) + while true: + let conn = await sctp.accept() + asyncSpawn conn.sendPong() + +waitFor(main()) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 12208a3..78d74b7 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -212,20 +212,20 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} = continue return res -proc dial*(self: Dtls, raddr: TransportAddress): DtlsConn = +proc dial*(self: Dtls, raddr: TransportAddress): Future[DtlsConn] {.async.} = discard -import ../udp_connection -import stew/byteutils -proc main() {.async.} = - let laddr = initTAddress("127.0.0.1:4433") - let udp = UdpConn() - await udp.init(laddr) - let stun = StunConn() - await stun.init(udp, laddr) - let dtls = Dtls() - dtls.start(stun, laddr) - let x = await dtls.accept() - echo "Recv: <", string.fromBytes(await x.read()), ">" - -waitFor(main()) +#import ../udp_connection +#import stew/byteutils +#proc main() {.async.} = +# let laddr = initTAddress("127.0.0.1:4433") +# let udp = UdpConn() +# await udp.init(laddr) +# let stun = StunConn() +# await stun.init(udp, laddr) +# let dtls = Dtls() +# dtls.start(stun, laddr) +# let x = await dtls.accept() +# echo "Recv: <", string.fromBytes(await x.read()), ">" +# +#waitFor(main()) diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index 3b14509..6e6d567 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -17,6 +17,10 @@ export chronicles logScope: topics = "webrtc sctp" +# TODO: +# - Replace doAssert by a proper exception management +# - Find a clean way to manage SCTP ports + type SctpError* = object of CatchableError @@ -36,10 +40,11 @@ type info: sctp_rcvinfo params*: SctpMessageParameters - SctpConnection* = ref object + SctpConn* = ref object conn: DtlsConn state: SctpState connectEvent: AsyncEvent + acceptEvent: AsyncEvent sctp: Sctp udp: DatagramTransport address: TransportAddress @@ -49,14 +54,15 @@ type Sctp* = ref object dtls: Dtls udp: DatagramTransport - #connections: Table[TransportAddress, SctpConnection] + connections: Table[TransportAddress, SctpConn] gotConnection: AsyncEvent timersHandler: Future[void] isServer: bool sockServer: ptr socket - pendingConnections: seq[SctpConnection] + pendingConnections: seq[SctpConn] + pendingConnections2: Table[SockAddr, SctpConn] sentFuture: Future[void] - sentConnection: SctpConnection + sentConnection: SctpConn sentAddress: TransportAddress const @@ -87,7 +93,7 @@ proc packetPretty(packet: cstring): string = else: result = result & ctn -proc new(T: typedesc[SctpConnection], +proc new(T: typedesc[SctpConn], sctp: Sctp, udp: DatagramTransport, address: TransportAddress, @@ -102,7 +108,15 @@ proc new(T: typedesc[SctpConnection], dataRecv: newAsyncQueue[SctpMessage]() ) -proc read*(self: SctpConnection): Future[SctpMessage] {.async.} = +proc new(T: typedesc[SctpConn], conn: DtlsConn): T = + T(conn: conn, + state: Connecting, + connectEvent: AsyncEvent(), + acceptEvent: AsyncEvent(), + dataRecv: newAsyncQueue[SctpMessage]() #TODO add some limit for backpressure? + ) + +proc read*(self: SctpConn): Future[SctpMessage] {.async.} = return await self.dataRecv.popFirst() proc toFlags(params: SctpMessageParameters): uint16 = @@ -112,7 +126,7 @@ proc toFlags(params: SctpMessageParameters): uint16 = result = result or SCTP_UNORDERED proc write*( - self: SctpConnection, + self: SctpConn, buf: seq[byte], sendParams = default(SctpMessageParameters), ) {.async.} = @@ -136,16 +150,16 @@ proc write*( nil, 0, unsafeAddr sendInfo, sizeof(sendInfo).SockLen, infoType, 0) -proc write*(self: SctpConnection, s: string) {.async.} = +proc write*(self: SctpConn, s: string) {.async.} = await self.write(s.toBytes()) -proc close*(self: SctpConnection) {.async.} = +proc close*(self: SctpConn) {.async.} = self.sctp.usrsctpAwait: self.sctpSocket.usrsctp_close() proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = let events = usrsctp_get_events(sock) - conn = cast[SctpConnection](data) + conn = cast[SctpConn](data) trace "Handle Upcall", events if conn.state == Connecting: if bitand(events, SCTP_EVENT_ERROR) != 0: @@ -194,29 +208,30 @@ proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = proc handleAccept(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = trace "Handle Accept" + var + sconn: Sockaddr_conn + slen: Socklen = sizeof(Sockaddr_conn).uint32 let sctp = cast[Sctp](data) - sctpSocket = usrsctp_accept(sctp.sockServer, nil, nil) + sctpSocket = usrsctp_accept(sctp.sockServer, cast[ptr SockAddr](addr sconn), addr slen) + # echo cast[uint64](sconn.sconn_addr) doAssert 0 == sctpSocket.usrsctp_set_non_blocking(1) - let conn = SctpConnection.new(sctp, sctp.udp, sctp.sentAddress, sctpSocket) - sctp.connections[sctp.sentAddress] = conn - sctp.pendingConnections.add(conn) + let conn = cast[SctpConn](sconn.sconn_addr) conn.state = Connected - doAssert 0 == sctpSocket.usrsctp_set_upcall(handleUpcall, cast[pointer](conn)) - sctp.gotConnection.fire() + conn.acceptEvent.fire() proc getOrCreateConnection(self: Sctp, udp: DatagramTransport, address: TransportAddress, - sctpPort: uint16 = 5000): Future[SctpConnection] {.async.} = + sctpPort: uint16 = 5000): Future[SctpConn] {.async.} = #TODO remove the = 5000 if self.connections.hasKey(address): return self.connections[address] trace "Create Connection", address let sctpSocket = usrsctp_socket(AF_CONN, posix.SOCK_STREAM, IPPROTO_SCTP, nil, nil, 0, nil) - conn = SctpConnection.new(self, udp, address, sctpSocket) + conn = SctpConn.new(self, udp, address, sctpSocket) var on: int = 1 doAssert 0 == conn.sctpSocket.usrsctp_setsockopt(IPPROTO_SCTP, SCTP_RECVRCVINFO, @@ -232,7 +247,7 @@ proc getOrCreateConnection(self: Sctp, self.sentAddress = address let connErr = self.usrsctpAwait: conn.sctpSocket.usrsctp_connect(cast[ptr SockAddr](addr sconn), SockLen(sizeof(sconn))) - doAssert 0 == connErr or errno == posix.EINPROGRESS, ($errno) # TODO raise + doAssert 0 == connErr or errno == posix.EINPROGRESS, ($errno) self.connections[address] = conn return conn @@ -262,25 +277,6 @@ proc timersHandler() {.async.} = await sleepAsync(500.milliseconds) usrsctp_handle_timers(500) -proc startServer*(self: Sctp, sctpPort: uint16 = 5000) = - if self.isServer: - trace "Try to start the server twice" - return - self.isServer = true - doAssert 0 == usrsctp_sysctl_set_sctp_blackhole(2) - doAssert 0 == usrsctp_sysctl_set_sctp_no_csum_on_loopback(0) - let sock = usrsctp_socket(AF_CONN, posix.SOCK_STREAM, IPPROTO_SCTP, nil, nil, 0, nil) - var on: int = 1 - doAssert 0 == usrsctp_set_non_blocking(sock, 1) - var sin: Sockaddr_in - sin.sin_family = posix.AF_INET.uint16 - sin.sin_port = htons(sctpPort) - sin.sin_addr.s_addr = htonl(INADDR_ANY) - doAssert 0 == usrsctp_bind(sock, cast[ptr SockAddr](addr sin), SockLen(sizeof(Sockaddr_in))) - doAssert 0 >= usrsctp_listen(sock, 1) - doAssert 0 == sock.usrsctp_set_upcall(handleAccept, cast[pointer](self)) - self.sockServer = sock - proc stopServer*(self: Sctp) = if not self.isServer: trace "Try to close a client" @@ -292,27 +288,38 @@ proc stopServer*(self: Sctp) = pc.sctpSocket.usrsctp_close() self.sockServer.usrsctp_close() +proc new*(T: typedesc[Sctp], dtls: Dtls, laddr: TransportAddress): T = + let sctp = T(gotConnection: newAsyncEvent(), + timersHandler: timersHandler(), + dtls: dtls) + + usrsctp_init_nothreads(laddr.port.uint16, sendCallback, printf) + discard usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_NONE) + discard usrsctp_sysctl_set_sctp_ecn_enable(1) + usrsctp_register_address(cast[pointer](sctp)) + return sctp + proc new*(T: typedesc[Sctp], port: uint16 = 9899): T = logScope: topics = "webrtc sctp" let sctp = T(gotConnection: newAsyncEvent()) - proc onReceive(udp: DatagramTransport, address: TransportAddress) {.async, gcsafe.} = + proc onReceive(udp: DatagramTransport, raddr: TransportAddress) {.async, gcsafe.} = let msg = udp.getMessage() data = usrsctp_dumppacket(unsafeAddr msg[0], uint(msg.len), SCTP_DUMP_INBOUND) if data != nil: if sctp.isServer: - trace "onReceive (server)", data = data.packetPretty(), length = msg.len(), address + trace "onReceive (server)", data = data.packetPretty(), length = msg.len(), raddr else: - trace "onReceive (client)", data = data.packetPretty(), length = msg.len(), address + trace "onReceive (client)", data = data.packetPretty(), length = msg.len(), raddr usrsctp_freedumpbuffer(data) if sctp.isServer: - sctp.sentAddress = address + sctp.sentAddress = raddr usrsctp_conninput(cast[pointer](sctp), unsafeAddr msg[0], uint(msg.len), 0) else: - let conn = await sctp.getOrCreateConnection(udp, address) + let conn = await sctp.getOrCreateConnection(udp, raddr) sctp.sentConnection = conn - sctp.sentAddress = address + sctp.sentAddress = raddr usrsctp_conninput(cast[pointer](sctp), unsafeAddr msg[0], uint(msg.len), 0) let localAddr = TransportAddress(family: AddressFamily.IPv4, port: Port(port)) @@ -333,29 +340,62 @@ proc stop*(self: Sctp) {.async.} = discard self.usrsctpAwait usrsctp_finish() self.udp.close() -proc listen*(self: Sctp): Future[SctpConnection] {.async.} = +proc accept*(self: Sctp): Future[SctpConn] {.async.} = if not self.isServer: raise newSctpError("Not a server") - trace "Listening" - if self.pendingConnections.len == 0: - self.gotConnection.clear() - await self.gotConnection.wait() - let res = self.pendingConnections[0] - self.pendingConnections.delete(0) + let conn = await self.dtls.accept() + var res = SctpConn.new(conn) + res.conn = await self.dtls.accept() + let + msg = await res.conn.read() + data = usrsctp_dumppacket(unsafeAddr msg[0], uint(msg.len), SCTP_DUMP_INBOUND) + if data != nil: + trace "Receive connection", remoteAddress = res.conn.raddr, data = data.packetPretty() + usrsctp_freedumpbuffer(data) + # sctp.sentAddress = raddr + usrsctp_register_address(cast[pointer](res)) + usrsctp_conninput(cast[pointer](res), unsafeAddr msg[0], uint(msg.len), 0) + res.acceptEvent.clear() + await res.acceptEvent.wait() return res +proc listen*(self: Sctp, sctpPort: uint16 = 5000) {.async.} = + if self.isServer: + trace "Try to start the server twice" + return + self.isServer = true + trace "Listening", sctpPort + doAssert 0 == usrsctp_sysctl_set_sctp_blackhole(2) + doAssert 0 == usrsctp_sysctl_set_sctp_no_csum_on_loopback(0) + let sock = usrsctp_socket(AF_CONN, posix.SOCK_STREAM, IPPROTO_SCTP, nil, nil, 0, nil) + var on: int = 1 + doAssert 0 == usrsctp_set_non_blocking(sock, 1) + var sin: Sockaddr_in + sin.sin_family = posix.AF_INET.uint16 + sin.sin_port = htons(sctpPort) + sin.sin_addr.s_addr = htonl(INADDR_ANY) + doAssert 0 == usrsctp_bind(sock, cast[ptr SockAddr](addr sin), SockLen(sizeof(Sockaddr_in))) + doAssert 0 >= usrsctp_listen(sock, 1) + doAssert 0 == sock.usrsctp_set_upcall(handleAccept, cast[pointer](self)) + self.sockServer = sock + proc connect*(self: Sctp, address: TransportAddress, - sctpPort: uint16 = 5000): Future[SctpConnection] {.async.} = - trace "Connect", address - let conn = await self.getOrCreateConnection(self.udp, address, sctpPort) - if conn.state == Connected: - return conn - try: - await conn.connectEvent.wait() - except CancelledError as exc: - conn.sctpSocket.usrsctp_close() - return nil - if conn.state != Connected: - raise newSctpError("Cannot connect to " & $address) - return conn + sctpPort: uint16 = 5000): Future[SctpConn] {.async.} = + discard + +# proc connect*(self: Sctp, +# address: TransportAddress, +# sctpPort: uint16 = 5000): Future[SctpConn] {.async.} = +# trace "Connect", address, sctpPort +# let conn = await self.getOrCreateConnection(self.udp, address, sctpPort) +# if conn.state == Connected: +# return conn +# try: +# await conn.connectEvent.wait() # TODO: clear? +# except CancelledError as exc: +# conn.sctpSocket.usrsctp_close() +# return nil +# if conn.state != Connected: +# raise newSctpError("Cannot connect to " & $address) +# return conn From d3b52cdac3b912a899eb24bd787aec868a088b1b Mon Sep 17 00:00:00 2001 From: Tanguy Date: Fri, 13 Oct 2023 15:04:02 +0200 Subject: [PATCH 34/66] webrtc --- examples/pong.nim | 6 ++-- webrtc/datachannel.nim | 10 +++++-- webrtc/dtls/dtls.nim | 2 ++ webrtc/sctp.nim | 2 +- webrtc/stun/stun_connection.nim | 2 +- webrtc/webrtc.nim | 53 ++++++++++++++------------------- 6 files changed, 38 insertions(+), 37 deletions(-) diff --git a/examples/pong.nim b/examples/pong.nim index d7cb0bb..69abf57 100644 --- a/examples/pong.nim +++ b/examples/pong.nim @@ -15,13 +15,13 @@ proc sendPong(conn: SctpConn) {.async.} = proc main() {.async.} = let laddr = initTAddress("127.0.0.1:4242") let udp = UdpConn() - await udp.init(laddr) + udp.init(laddr) let stun = StunConn() - await stun.init(udp, laddr) + stun.init(udp, laddr) let dtls = Dtls() dtls.start(stun, laddr) let sctp = Sctp.new(dtls, laddr) - await sctp.listen(13) + sctp.listen(13) while true: let conn = await sctp.accept() asyncSpawn conn.sendPong() diff --git a/webrtc/datachannel.nim b/webrtc/datachannel.nim index 66bc9d3..4d6675b 100644 --- a/webrtc/datachannel.nim +++ b/webrtc/datachannel.nim @@ -62,7 +62,7 @@ type #TODO handle closing DataChannelStream* = ref object id: uint16 - conn: SctpConnection + conn: SctpConn reliability: DataChannelType reliabilityParameter: uint32 receivedData: AsyncQueue[seq[byte]] @@ -72,7 +72,7 @@ type DataChannelConnection* = ref object readLoopFut: Future[void] streams: Table[uint16, DataChannelStream] - conn: SctpConnection + conn: SctpConn incomingStreams: AsyncQueue[DataChannelStream] proc read*(stream: DataChannelStream): Future[seq[byte]] {.async.} = @@ -197,3 +197,9 @@ proc accept*(conn: DataChannelConnection): Future[DataChannelStream] {.async.} = if isNil(conn.readLoopFut): conn.readLoopFut = conn.readLoop() return await conn.incomingStreams.popFirst() + +proc new*(_: type DataChannelConnection, conn: SctpConn): DataChannelConnection = + DataChannelConnection( + conn: conn, + incomingStreams: newAsyncQueue[DataChannelStream]() + ) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 78d74b7..35ac163 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -164,6 +164,8 @@ proc serverHandshake(self: DtlsConn) {.async.} = elif res != 0: raise newException(DtlsError, $(res.mbedtls_high_level_strerr())) +proc remoteAddress*(conn: DtlsConn): TransportAddress = conn.raddr + proc accept*(self: Dtls): Future[DtlsConn] {.async.} = var selfvar = self diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index 6e6d567..d3b31aa 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -359,7 +359,7 @@ proc accept*(self: Sctp): Future[SctpConn] {.async.} = await res.acceptEvent.wait() return res -proc listen*(self: Sctp, sctpPort: uint16 = 5000) {.async.} = +proc listen*(self: Sctp, sctpPort: uint16 = 5000) = if self.isServer: trace "Try to start the server twice" return diff --git a/webrtc/stun/stun_connection.nim b/webrtc/stun/stun_connection.nim index aea422a..26913bb 100644 --- a/webrtc/stun/stun_connection.nim +++ b/webrtc/stun/stun_connection.nim @@ -27,7 +27,7 @@ proc handles(self: StunConn) {.async.} = else: self.dataRecv.addLastNoWait((msg, raddr)) -proc init*(self: StunConn, conn: UdpConn, laddr: TransportAddress) {.async.} = +proc init*(self: StunConn, conn: UdpConn, laddr: TransportAddress) = self.conn = conn self.laddr = laddr diff --git a/webrtc/webrtc.nim b/webrtc/webrtc.nim index f8cdc36..88e9e74 100644 --- a/webrtc/webrtc.nim +++ b/webrtc/webrtc.nim @@ -8,41 +8,34 @@ # those terms. import chronos, chronicles -import stun/stun + +import udp_connection +import stun/stun_connection +import dtls/dtls +import sctp, datachannel logScope: topics = "webrtc" -let fut = newFuture[void]() type - WebRTC* = object - udp: DatagramTransport + WebRTC* = ref object + udp*: UdpConn + stun*: StunConn + dtls*: Dtls + sctp*: Sctp + port: int -proc new*(T: typedesc[WebRTC], port: uint16 = 42657): T = - logScope: topics = "webrtc" +proc new*(T: typedesc[WebRTC], address: TransportAddress): T = var webrtc = T() - proc onReceive(udp: DatagramTransport, address: TransportAddress) {.async, gcsafe.} = - let - msg = udp.getMessage() - if Stun.isMessage(msg): - let res = Stun.getResponse(msg, address) - if res.isSome(): - await udp.sendTo(address, res.get()) - - trace "onReceive", isStun = Stun.isMessage(msg) - if not fut.completed(): fut.complete() - - let - laddr = initTAddress("127.0.0.1:" & $port) - udp = newDatagramTransport(onReceive, local = laddr) - trace "local address", laddr - webrtc.udp = udp + webrtc.udp.init(address) + webrtc.stun.init(webrtc.udp, address) + webrtc.dtls.start(webrtc.stun, address) + webrtc.sctp = Sctp.new(webrtc.dtls, address) return webrtc -# -#proc main {.async.} = -# echo "/ip4/127.0.0.1/udp/42657/webrtc/certhash/uEiDKBGpmOW3zQhiCHagHZ8igwfKNIp8rQCJWd5E5mIhGHw/p2p/12D3KooWFjMiMZLaCKEZRvMqKp5qUGduS6iBZ9RWQgYZXYtAAaPC" -# discard WebRTC.new() -# await fut -# await sleepAsync(10.seconds) -# -#waitFor(main()) + +proc listen*(w: WebRTC) = + w.sctp.listen() + +proc accept*(w: WebRTC): Future[DataChannelConnection] {.async.} = + let sctpConn = await w.sctp.accept() + result = DataChannelConnection.new(sctpConn) From 64d374d837f2b862a241adfc6634627217417d7d Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 13 Oct 2023 15:06:06 +0200 Subject: [PATCH 35/66] Add read loop for sctp connexion --- webrtc/sctp.nim | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index 6e6d567..b94c8cb 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -45,6 +45,7 @@ type state: SctpState connectEvent: AsyncEvent acceptEvent: AsyncEvent + readLoop: Future[void] sctp: Sctp udp: DatagramTransport address: TransportAddress @@ -340,6 +341,16 @@ proc stop*(self: Sctp) {.async.} = discard self.usrsctpAwait usrsctp_finish() self.udp.close() +proc readLoopProc(res: SctpConn) {.async.} = + while true: + let + msg = await res.conn.read() + data = usrsctp_dumppacket(unsafeAddr msg[0], uint(msg.len), SCTP_DUMP_INBOUND) + if data != nil: + trace "Receive connection", remoteAddress = result.conn.raddr, data = data.packetPretty() + usrsctp_freedumpbuffer(data) + usrsctp_conninput(cast[pointer](res), unsafeAddr msg[0], uint(msg.len), 0) + proc accept*(self: Sctp): Future[SctpConn] {.async.} = if not self.isServer: raise newSctpError("Not a server") @@ -354,7 +365,7 @@ proc accept*(self: Sctp): Future[SctpConn] {.async.} = usrsctp_freedumpbuffer(data) # sctp.sentAddress = raddr usrsctp_register_address(cast[pointer](res)) - usrsctp_conninput(cast[pointer](res), unsafeAddr msg[0], uint(msg.len), 0) + res.readLoop = res.readLoopProc() res.acceptEvent.clear() await res.acceptEvent.wait() return res From 0c96e8db2daa829d012e142f516e31f5b188e0b8 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Fri, 13 Oct 2023 15:12:18 +0200 Subject: [PATCH 36/66] fix --- webrtc/sctp.nim | 7 ------- 1 file changed, 7 deletions(-) diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index 4e8b0f5..daa5482 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -357,13 +357,6 @@ proc accept*(self: Sctp): Future[SctpConn] {.async.} = let conn = await self.dtls.accept() var res = SctpConn.new(conn) res.conn = await self.dtls.accept() - let - msg = await res.conn.read() - data = usrsctp_dumppacket(unsafeAddr msg[0], uint(msg.len), SCTP_DUMP_INBOUND) - if data != nil: - trace "Receive connection", remoteAddress = res.conn.raddr, data = data.packetPretty() - usrsctp_freedumpbuffer(data) - # sctp.sentAddress = raddr usrsctp_register_address(cast[pointer](res)) res.readLoop = res.readLoopProc() res.acceptEvent.clear() From a3f68f1745b4fb0d2d3d759e6a023be335ed34b7 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 13 Oct 2023 15:34:30 +0200 Subject: [PATCH 37/66] Add getter for local and remote dtls certificate --- webrtc/dtls/dtls.nim | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 35ac163..8ccb39f 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -54,6 +54,9 @@ type ctr_drbg: mbedtls_ctr_drbg_context entropy: mbedtls_entropy_context + localCert: seq[byte] + remoteCert: seq[byte] + proc dtlsSend*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = var self = cast[DtlsConn](ctx) var toWrite = newSeq[byte](len) @@ -163,8 +166,15 @@ proc serverHandshake(self: DtlsConn) {.async.} = continue elif res != 0: raise newException(DtlsError, $(res.mbedtls_high_level_strerr())) + let remoteCert = self.ssl.mbedtls_ssl_get_peer_cert()[] + res.remoteCert = newSeq[byte](srvcert.raw.len) + copyMem(addr res.remoteCert[0], srvcert.raw.p, srvcert.raw.len) -proc remoteAddress*(conn: DtlsConn): TransportAddress = conn.raddr +proc localCertificate*(conn: DtlsConn): seq[byte] = + conn.localCert + +proc remoteCertificate*(conn: DtlsConn): seq[byte] = + conn.remoteCert proc accept*(self: Dtls): Future[DtlsConn] {.async.} = var @@ -184,6 +194,8 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} = var pkey = res.ctr_drbg.generateKey() var srvcert = res.ctr_drbg.generateCertificate(pkey) + res.localCert = newSeq[byte](srvcert.raw.len) + copyMem(addr res.localCert[0], srvcert.raw.p, srvcert.raw.len) mb_ssl_config_defaults(res.config, MBEDTLS_SSL_IS_SERVER, From b26e0c17d68e6dfbad9b3dbda3912eeeeba14a82 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Fri, 13 Oct 2023 16:45:56 +0200 Subject: [PATCH 38/66] fix compile stmt --- webrtc/usrsctp.nim | 49 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/webrtc/usrsctp.nim b/webrtc/usrsctp.nim index 25acb33..c3e9d69 100644 --- a/webrtc/usrsctp.nim +++ b/webrtc/usrsctp.nim @@ -4,7 +4,7 @@ import strformat, os import nativesockets # C include directory -const root = currentSourcePath.parentDir +const root = currentSourcePath.parentDir.parentDir const usrsctpInclude = root/"usrsctp"/"usrsctplib" {.passc: fmt"-I{usrsctpInclude}".} @@ -47,30 +47,29 @@ const usrsctpInclude = root/"usrsctp"/"usrsctplib" {.passc: "-DHAVE_NETINET_IP_ICMP_H=1".} {.passc: "-DHAVE_NET_ROUTE_H=1".} {.passc: "-D_GNU_SOURCE".} -{.passc: "-I./usrsctp/usrsctplib".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_input.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_asconf.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_pcb.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_usrreq.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_cc_functions.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_auth.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_userspace.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_output.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_callout.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_crc32.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_sysctl.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_sha1.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_timer.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctputil.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_bsd_addr.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_peeloff.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_indata.c".} -{.compile: "./usrsctp/usrsctplib/netinet/sctp_ss_functions.c".} -{.compile: "./usrsctp/usrsctplib/user_socket.c".} -{.compile: "./usrsctp/usrsctplib/netinet6/sctp6_usrreq.c".} -{.compile: "./usrsctp/usrsctplib/user_mbuf.c".} -{.compile: "./usrsctp/usrsctplib/user_environment.c".} -{.compile: "./usrsctp/usrsctplib/user_recv_thread.c".} +{.compile: usrsctpInclude / "netinet/sctp_input.c".} +{.compile: usrsctpInclude / "netinet/sctp_asconf.c".} +{.compile: usrsctpInclude / "netinet/sctp_pcb.c".} +{.compile: usrsctpInclude / "netinet/sctp_usrreq.c".} +{.compile: usrsctpInclude / "netinet/sctp_cc_functions.c".} +{.compile: usrsctpInclude / "netinet/sctp_auth.c".} +{.compile: usrsctpInclude / "netinet/sctp_userspace.c".} +{.compile: usrsctpInclude / "netinet/sctp_output.c".} +{.compile: usrsctpInclude / "netinet/sctp_callout.c".} +{.compile: usrsctpInclude / "netinet/sctp_crc32.c".} +{.compile: usrsctpInclude / "netinet/sctp_sysctl.c".} +{.compile: usrsctpInclude / "netinet/sctp_sha1.c".} +{.compile: usrsctpInclude / "netinet/sctp_timer.c".} +{.compile: usrsctpInclude / "netinet/sctputil.c".} +{.compile: usrsctpInclude / "netinet/sctp_bsd_addr.c".} +{.compile: usrsctpInclude / "netinet/sctp_peeloff.c".} +{.compile: usrsctpInclude / "netinet/sctp_indata.c".} +{.compile: usrsctpInclude / "netinet/sctp_ss_functions.c".} +{.compile: usrsctpInclude / "user_socket.c".} +{.compile: usrsctpInclude / "netinet6/sctp6_usrreq.c".} +{.compile: usrsctpInclude / "user_mbuf.c".} +{.compile: usrsctpInclude / "user_environment.c".} +{.compile: usrsctpInclude / "user_recv_thread.c".} const MSG_NOTIFICATION* = 0x00002000 AF_CONN* = 123 From 713b1c99962212830051ca2f64bed5b9c5c08093 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 13 Oct 2023 17:17:15 +0200 Subject: [PATCH 39/66] Fix remoteCert --- webrtc/dtls/dtls.nim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 8ccb39f..d7ed5d9 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -166,9 +166,10 @@ proc serverHandshake(self: DtlsConn) {.async.} = continue elif res != 0: raise newException(DtlsError, $(res.mbedtls_high_level_strerr())) - let remoteCert = self.ssl.mbedtls_ssl_get_peer_cert()[] - res.remoteCert = newSeq[byte](srvcert.raw.len) - copyMem(addr res.remoteCert[0], srvcert.raw.p, srvcert.raw.len) + var remoteCertPtr = mbedtls_ssl_get_peer_cert(addr self.ssl) + let remoteCert = remoteCertPtr[] + self.remoteCert = newSeq[byte](remoteCert.raw.len) + copyMem(addr self.remoteCert[0], remoteCert.raw.p, remoteCert.raw.len) proc localCertificate*(conn: DtlsConn): seq[byte] = conn.localCert From 65693727c76faa703e59f0a92cb6307587c1b78a Mon Sep 17 00:00:00 2001 From: Tanguy Date: Fri, 13 Oct 2023 17:26:57 +0200 Subject: [PATCH 40/66] set installDirs --- webrtc.nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webrtc.nimble b/webrtc.nimble index 4d0acf6..0031ecd 100644 --- a/webrtc.nimble +++ b/webrtc.nimble @@ -3,7 +3,7 @@ version = "0.0.1" author = "Status Research & Development GmbH" description = "Webrtc stack" license = "MIT" -#installDirs = @["usrsctp"] +installDirs = @["usrsctp", "webrtc"] requires "nim >= 1.2.0", "chronicles >= 0.10.2", From 3ec464dfe318dce10f79949950a595ca7cbd32c4 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Fri, 13 Oct 2023 18:08:21 +0200 Subject: [PATCH 41/66] fixes --- webrtc/udp_connection.nim | 2 +- webrtc/webrtc.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/webrtc/udp_connection.nim b/webrtc/udp_connection.nim index 3c28aef..6f66da7 100644 --- a/webrtc/udp_connection.nim +++ b/webrtc/udp_connection.nim @@ -19,7 +19,7 @@ type udp: DatagramTransport dataRecv: AsyncQueue[(seq[byte], TransportAddress)] -proc init*(self: UdpConn, laddr: TransportAddress) {.async.} = +proc init*(self: UdpConn, laddr: TransportAddress) = self.laddr = laddr proc onReceive(udp: DatagramTransport, address: TransportAddress) {.async, gcsafe.} = diff --git a/webrtc/webrtc.nim b/webrtc/webrtc.nim index 88e9e74..1c39eb8 100644 --- a/webrtc/webrtc.nim +++ b/webrtc/webrtc.nim @@ -26,7 +26,7 @@ type port: int proc new*(T: typedesc[WebRTC], address: TransportAddress): T = - var webrtc = T() + var webrtc = T(udp: UdpConn(), stun: StunConn(), dtls: Dtls()) webrtc.udp.init(address) webrtc.stun.init(webrtc.udp, address) webrtc.dtls.start(webrtc.stun, address) From 2309d9718ee11826d643bf59844e4ca20a28e86f Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Wed, 18 Oct 2023 13:33:54 +0200 Subject: [PATCH 42/66] move the creation of the certificate from the connection to the transport --- webrtc/dtls/dtls.nim | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index d7ed5d9..c984e67 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -100,6 +100,12 @@ type laddr: TransportAddress started: bool readLoop: Future[void] + ctr_drbg: mbedtls_ctr_drbg_context + entropy: mbedtls_entropy_context + + serverPrivKey: mbedtls_pk_context + serverCert: mbedtls_x509_crt + localCert: seq[byte] proc updateOrAdd(aq: AsyncQueue[(TransportAddress, seq[byte])], raddr: TransportAddress, buf: seq[byte]) = @@ -129,6 +135,14 @@ proc start*(self: Dtls, conn: StunConn, laddr: TransportAddress) = self.started = true self.readLoop = readLoop() + mb_ctr_drbg_init(self.ctr_drbg) + mb_entropy_init(self.entropy) + mb_ctr_drbg_seed(self.ctr_drbg, mbedtls_entropy_func, self.entropy, nil, 0) + + var pkey = self.ctr_drbg.generateKey() + var srvcert = self.ctr_drbg.generateCertificate(pkey) + self.localCert = newSeq[byte](srvcert.raw.len) + proc stop*(self: Dtls) = if not self.started: warn "Already stopped" @@ -171,17 +185,16 @@ proc serverHandshake(self: DtlsConn) {.async.} = self.remoteCert = newSeq[byte](remoteCert.raw.len) copyMem(addr self.remoteCert[0], remoteCert.raw.p, remoteCert.raw.len) -proc localCertificate*(conn: DtlsConn): seq[byte] = - conn.localCert - proc remoteCertificate*(conn: DtlsConn): seq[byte] = conn.remoteCert +proc localCertificate*(self: Dtls): seq[byte] = + self.localCert + proc accept*(self: Dtls): Future[DtlsConn] {.async.} = var selfvar = self res = DtlsConn() - let v = cast[pointer](res) await res.init(self.conn, self.laddr) mb_ssl_init(res.ssl) @@ -189,9 +202,8 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} = mb_ssl_cookie_init(res.cookie) mb_ssl_cache_init(res.cache) - mb_ctr_drbg_init(res.ctr_drbg) - mb_entropy_init(res.entropy) - mb_ctr_drbg_seed(res.ctr_drbg, mbedtls_entropy_func, res.entropy, nil, 0) + res.ctr_drbg = self.ctr_drbg + res.entropy = self.entropy var pkey = res.ctr_drbg.generateKey() var srvcert = res.ctr_drbg.generateCertificate(pkey) From 0504d863407c1d14bf39478ba2335d299caac6ef Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Wed, 18 Oct 2023 14:05:50 +0200 Subject: [PATCH 43/66] add dtlsLocalCertificate --- webrtc/webrtc.nim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/webrtc/webrtc.nim b/webrtc/webrtc.nim index 1c39eb8..1ce299a 100644 --- a/webrtc/webrtc.nim +++ b/webrtc/webrtc.nim @@ -25,6 +25,9 @@ type sctp*: Sctp port: int +proc dtlsLocalCertificate(w: WebRTC): seq[byte] = + w.dtls.localCertificate() + proc new*(T: typedesc[WebRTC], address: TransportAddress): T = var webrtc = T(udp: UdpConn(), stun: StunConn(), dtls: Dtls()) webrtc.udp.init(address) From afce5cad171c19e5bdeaf3b28bf9561a4dc9fbaa Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Thu, 19 Oct 2023 14:20:48 +0200 Subject: [PATCH 44/66] expose local address --- webrtc/dtls/dtls.nim | 12 ++++++------ webrtc/udp_connection.nim | 2 +- webrtc/webrtc.nim | 3 --- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index c984e67..9b467ae 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -139,9 +139,9 @@ proc start*(self: Dtls, conn: StunConn, laddr: TransportAddress) = mb_entropy_init(self.entropy) mb_ctr_drbg_seed(self.ctr_drbg, mbedtls_entropy_func, self.entropy, nil, 0) - var pkey = self.ctr_drbg.generateKey() - var srvcert = self.ctr_drbg.generateCertificate(pkey) - self.localCert = newSeq[byte](srvcert.raw.len) + self.serverPrivKey = self.ctr_drbg.generateKey() + self.serverCert = self.ctr_drbg.generateCertificate(self.serverPrivKey) + self.localCert = newSeq[byte](self.serverCert.raw.len) proc stop*(self: Dtls) = if not self.started: @@ -205,10 +205,10 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} = res.ctr_drbg = self.ctr_drbg res.entropy = self.entropy - var pkey = res.ctr_drbg.generateKey() - var srvcert = res.ctr_drbg.generateCertificate(pkey) + var pkey = self.serverPrivKey + var srvcert = self.serverCert res.localCert = newSeq[byte](srvcert.raw.len) - copyMem(addr res.localCert[0], srvcert.raw.p, srvcert.raw.len) + res.localCert = self.localCert mb_ssl_config_defaults(res.config, MBEDTLS_SSL_IS_SERVER, diff --git a/webrtc/udp_connection.nim b/webrtc/udp_connection.nim index 6f66da7..adf2463 100644 --- a/webrtc/udp_connection.nim +++ b/webrtc/udp_connection.nim @@ -15,7 +15,7 @@ logScope: type UdpConn* = ref object - laddr: TransportAddress + laddr*: TransportAddress udp: DatagramTransport dataRecv: AsyncQueue[(seq[byte], TransportAddress)] diff --git a/webrtc/webrtc.nim b/webrtc/webrtc.nim index 1ce299a..1c39eb8 100644 --- a/webrtc/webrtc.nim +++ b/webrtc/webrtc.nim @@ -25,9 +25,6 @@ type sctp*: Sctp port: int -proc dtlsLocalCertificate(w: WebRTC): seq[byte] = - w.dtls.localCertificate() - proc new*(T: typedesc[WebRTC], address: TransportAddress): T = var webrtc = T(udp: UdpConn(), stun: StunConn(), dtls: Dtls()) webrtc.udp.init(address) From a36708a5a0103f7dbbca85f7021eab864cc6cca0 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 20 Oct 2023 11:15:00 +0200 Subject: [PATCH 45/66] Fix chronicles --- webrtc/dtls/dtls.nim | 2 +- webrtc/sctp.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 9b467ae..ca26f45 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -40,7 +40,7 @@ type DtlsConn* = ref object conn: StunConn laddr: TransportAddress - raddr: TransportAddress + raddr*: TransportAddress dataRecv: AsyncQueue[seq[byte]] sendFuture: Future[void] diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index daa5482..c1a66cb 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -347,7 +347,7 @@ proc readLoopProc(res: SctpConn) {.async.} = msg = await res.conn.read() data = usrsctp_dumppacket(unsafeAddr msg[0], uint(msg.len), SCTP_DUMP_INBOUND) if data != nil: - trace "Receive connection", remoteAddress = result.conn.raddr, data = data.packetPretty() + trace "Receive connection", remoteAddress = res.conn.raddr, data = data.packetPretty() usrsctp_freedumpbuffer(data) usrsctp_conninput(cast[pointer](res), unsafeAddr msg[0], uint(msg.len), 0) From dee08191cf209898011e68732e3ec8c4ca23beaf Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Tue, 7 Nov 2023 16:33:29 +0100 Subject: [PATCH 46/66] Fix remote certificate --- webrtc/dtls/dtls.nim | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index ca26f45..b2d3ed1 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -142,6 +142,7 @@ proc start*(self: Dtls, conn: StunConn, laddr: TransportAddress) = self.serverPrivKey = self.ctr_drbg.generateKey() self.serverCert = self.ctr_drbg.generateCertificate(self.serverPrivKey) self.localCert = newSeq[byte](self.serverCert.raw.len) + copyMem(addr self.localCert[0], self.serverCert.raw.p, self.serverCert.raw.len) proc stop*(self: Dtls) = if not self.started: @@ -180,10 +181,10 @@ proc serverHandshake(self: DtlsConn) {.async.} = continue elif res != 0: raise newException(DtlsError, $(res.mbedtls_high_level_strerr())) - var remoteCertPtr = mbedtls_ssl_get_peer_cert(addr self.ssl) - let remoteCert = remoteCertPtr[] - self.remoteCert = newSeq[byte](remoteCert.raw.len) - copyMem(addr self.remoteCert[0], remoteCert.raw.p, remoteCert.raw.len) + # var remoteCertPtr = mbedtls_ssl_get_peer_cert(addr self.ssl) + # let remoteCert = remoteCertPtr[] + # self.remoteCert = newSeq[byte](remoteCert.raw.len) + # copyMem(addr self.remoteCert[0], remoteCert.raw.p, remoteCert.raw.len) proc remoteCertificate*(conn: DtlsConn): seq[byte] = conn.remoteCert @@ -191,6 +192,15 @@ proc remoteCertificate*(conn: DtlsConn): seq[byte] = proc localCertificate*(self: Dtls): seq[byte] = self.localCert +proc verify(ctx: pointer, pcert: ptr mbedtls_x509_crt, + state: cint, pflags: ptr uint32): cint {.cdecl.} = + var self = cast[DtlsConn](ctx) + let cert = pcert[] + + self.remoteCert = newSeq[byte](cert.raw.len) + copyMem(addr self.remoteCert[0], cert.raw.p, cert.raw.len) + return 0 + proc accept*(self: Dtls): Future[DtlsConn] {.async.} = var selfvar = self @@ -223,6 +233,7 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} = mb_ssl_set_timer_cb(res.ssl, res.timer) mb_ssl_setup(res.ssl, res.config) mb_ssl_session_reset(res.ssl) + mbedtls_ssl_set_verify(addr res.ssl, verify, cast[pointer](res)) mb_ssl_set_bio(res.ssl, cast[pointer](res), dtlsSend, dtlsRecv, nil) while true: From 6391a3f2e58c269bbcad8ad53770efac64ede9a0 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Thu, 9 Nov 2023 15:54:45 +0100 Subject: [PATCH 47/66] fix small errors on sctp --- webrtc/dtls/dtls.nim | 2 + webrtc/sctp.nim | 170 +++++++++++++++++++++---------------------- 2 files changed, 87 insertions(+), 85 deletions(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index b2d3ed1..703c78d 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -58,6 +58,7 @@ type remoteCert: seq[byte] proc dtlsSend*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = + trace "dtls send", len var self = cast[DtlsConn](ctx) var toWrite = newSeq[byte](len) if len > 0: @@ -66,6 +67,7 @@ proc dtlsSend*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = result = len.cint proc dtlsRecv*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = + trace "dtls receive", len var self = cast[DtlsConn](ctx) dataRecv = self.dataRecv.popFirstNoWait() diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index c1a66cb..8eafc09 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -51,6 +51,7 @@ type address: TransportAddress sctpSocket: ptr socket dataRecv: AsyncQueue[SctpMessage] + sentFuture: Future[void] Sctp* = ref object dtls: Dtls @@ -62,9 +63,9 @@ type sockServer: ptr socket pendingConnections: seq[SctpConn] pendingConnections2: Table[SockAddr, SctpConn] - sentFuture: Future[void] sentConnection: SctpConn sentAddress: TransportAddress + sentFuture: Future[void] const IPPROTO_SCTP = 132 @@ -72,14 +73,14 @@ const proc newSctpError(msg: string): ref SctpError = result = newException(SctpError, msg) -template usrsctpAwait(sctp: Sctp, body: untyped): untyped = - sctp.sentFuture = nil +template usrsctpAwait(self: SctpConn|Sctp, body: untyped): untyped = + self.sentFuture = nil when type(body) is void: body - if sctp.sentFuture != nil: await sctp.sentFuture + if self.sentFuture != nil: await self.sentFuture else: let res = body - if sctp.sentFuture != nil: await sctp.sentFuture + if self.sentFuture != nil: await self.sentFuture res proc perror(error: cstring) {.importc, cdecl, header: "".} @@ -109,8 +110,9 @@ proc new(T: typedesc[SctpConn], dataRecv: newAsyncQueue[SctpMessage]() ) -proc new(T: typedesc[SctpConn], conn: DtlsConn): T = +proc new(T: typedesc[SctpConn], conn: DtlsConn, sctp: Sctp): T = T(conn: conn, + sctp: sctp, state: Connecting, connectEvent: AsyncEvent(), acceptEvent: AsyncEvent(), @@ -146,7 +148,7 @@ proc write*( ), cuint(SCTP_SENDV_SNDINFO)) else: (default(sctp_sndinfo), cuint(SCTP_SENDV_NOINFO)) - sendvErr = self.sctp.usrsctpAwait: + sendvErr = self.usrsctpAwait: self.sctpSocket.usrsctp_sendv(unsafeAddr buf[0], buf.len.uint, nil, 0, unsafeAddr sendInfo, sizeof(sendInfo).SockLen, infoType, 0) @@ -155,7 +157,7 @@ proc write*(self: SctpConn, s: string) {.async.} = await self.write(s.toBytes()) proc close*(self: SctpConn) {.async.} = - self.sctp.usrsctpAwait: self.sctpSocket.usrsctp_close() + self.usrsctpAwait: self.sctpSocket.usrsctp_close() proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = let @@ -216,43 +218,42 @@ proc handleAccept(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = sctp = cast[Sctp](data) sctpSocket = usrsctp_accept(sctp.sockServer, cast[ptr SockAddr](addr sconn), addr slen) - # echo cast[uint64](sconn.sconn_addr) doAssert 0 == sctpSocket.usrsctp_set_non_blocking(1) let conn = cast[SctpConn](sconn.sconn_addr) conn.state = Connected conn.acceptEvent.fire() -proc getOrCreateConnection(self: Sctp, - udp: DatagramTransport, - address: TransportAddress, - sctpPort: uint16 = 5000): Future[SctpConn] {.async.} = - #TODO remove the = 5000 - if self.connections.hasKey(address): - return self.connections[address] - trace "Create Connection", address - let - sctpSocket = usrsctp_socket(AF_CONN, posix.SOCK_STREAM, IPPROTO_SCTP, nil, nil, 0, nil) - conn = SctpConn.new(self, udp, address, sctpSocket) - var on: int = 1 - doAssert 0 == conn.sctpSocket.usrsctp_setsockopt(IPPROTO_SCTP, - SCTP_RECVRCVINFO, - addr on, - sizeof(on).SockLen) - doAssert 0 == usrsctp_set_non_blocking(conn.sctpSocket, 1) - doAssert 0 == usrsctp_set_upcall(conn.sctpSocket, handleUpcall, cast[pointer](conn)) - var sconn: Sockaddr_conn - sconn.sconn_family = AF_CONN - sconn.sconn_port = htons(sctpPort) - sconn.sconn_addr = cast[pointer](self) - self.sentConnection = conn - self.sentAddress = address - let connErr = self.usrsctpAwait: - conn.sctpSocket.usrsctp_connect(cast[ptr SockAddr](addr sconn), SockLen(sizeof(sconn))) - doAssert 0 == connErr or errno == posix.EINPROGRESS, ($errno) - self.connections[address] = conn - return conn +# proc getOrCreateConnection(self: Sctp, +# udp: DatagramTransport, +# address: TransportAddress, +# sctpPort: uint16 = 5000): Future[SctpConn] {.async.} = +# #TODO remove the = 5000 +# if self.connections.hasKey(address): +# return self.connections[address] +# trace "Create Connection", address +# let +# sctpSocket = usrsctp_socket(AF_CONN, posix.SOCK_STREAM, IPPROTO_SCTP, nil, nil, 0, nil) +# conn = SctpConn.new(self, udp, address, sctpSocket) +# var on: int = 1 +# doAssert 0 == conn.sctpSocket.usrsctp_setsockopt(IPPROTO_SCTP, +# SCTP_RECVRCVINFO, +# addr on, +# sizeof(on).SockLen) +# doAssert 0 == usrsctp_set_non_blocking(conn.sctpSocket, 1) +# doAssert 0 == usrsctp_set_upcall(conn.sctpSocket, handleUpcall, cast[pointer](conn)) +# var sconn: Sockaddr_conn +# sconn.sconn_family = AF_CONN +# sconn.sconn_port = htons(sctpPort) +# sconn.sconn_addr = cast[pointer](self) +# self.sentConnection = conn +# self.sentAddress = address +# let connErr = self.usrsctpAwait: +# conn.sctpSocket.usrsctp_connect(cast[ptr SockAddr](addr sconn), SockLen(sizeof(sconn))) +# doAssert 0 == connErr or errno == posix.EINPROGRESS, ($errno) +# self.connections[address] = conn +# return conn -proc sendCallback(address: pointer, +proc sendCallback(ctx: pointer, buffer: pointer, length: uint, tos: uint8, @@ -261,17 +262,15 @@ proc sendCallback(address: pointer, if data != nil: trace "sendCallback", data = data.packetPretty(), length usrsctp_freedumpbuffer(data) - let sctp = cast[Sctp](address) + let sctpConn = cast[SctpConn](ctx) proc testSend() {.async.} = try: - let - buf = @(buffer.makeOpenArray(byte, int(length))) - address = sctp.sentAddress - trace "Send To", address - await sendTo(sctp.udp, address, buf, int(length)) + let buf = @(buffer.makeOpenArray(byte, int(length))) + trace "Send To", address = sctpConn.address + await sctpConn.conn.write(buf) except CatchableError as exc: trace "Send Failed", message = exc.msg - sctp.sentFuture = testSend() + sctpConn.sentFuture = testSend() proc timersHandler() {.async.} = while true: @@ -300,42 +299,42 @@ proc new*(T: typedesc[Sctp], dtls: Dtls, laddr: TransportAddress): T = usrsctp_register_address(cast[pointer](sctp)) return sctp -proc new*(T: typedesc[Sctp], port: uint16 = 9899): T = - logScope: topics = "webrtc sctp" - let sctp = T(gotConnection: newAsyncEvent()) - proc onReceive(udp: DatagramTransport, raddr: TransportAddress) {.async, gcsafe.} = - let - msg = udp.getMessage() - data = usrsctp_dumppacket(unsafeAddr msg[0], uint(msg.len), SCTP_DUMP_INBOUND) - if data != nil: - if sctp.isServer: - trace "onReceive (server)", data = data.packetPretty(), length = msg.len(), raddr - else: - trace "onReceive (client)", data = data.packetPretty(), length = msg.len(), raddr - usrsctp_freedumpbuffer(data) - - if sctp.isServer: - sctp.sentAddress = raddr - usrsctp_conninput(cast[pointer](sctp), unsafeAddr msg[0], uint(msg.len), 0) - else: - let conn = await sctp.getOrCreateConnection(udp, raddr) - sctp.sentConnection = conn - sctp.sentAddress = raddr - usrsctp_conninput(cast[pointer](sctp), unsafeAddr msg[0], uint(msg.len), 0) - let - localAddr = TransportAddress(family: AddressFamily.IPv4, port: Port(port)) - laddr = initTAddress("127.0.0.1:" & $port) - udp = newDatagramTransport(onReceive, local = laddr) - trace "local address", localAddr, laddr - sctp.udp = udp - sctp.timersHandler = timersHandler() - - usrsctp_init_nothreads(port, sendCallback, printf) - discard usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_NONE) - discard usrsctp_sysctl_set_sctp_ecn_enable(1) - usrsctp_register_address(cast[pointer](sctp)) - - return sctp +#proc new*(T: typedesc[Sctp], port: uint16 = 9899): T = +# logScope: topics = "webrtc sctp" +# let sctp = T(gotConnection: newAsyncEvent()) +# proc onReceive(udp: DatagramTransport, raddr: TransportAddress) {.async, gcsafe.} = +# let +# msg = udp.getMessage() +# data = usrsctp_dumppacket(unsafeAddr msg[0], uint(msg.len), SCTP_DUMP_INBOUND) +# if data != nil: +# if sctp.isServer: +# trace "onReceive (server)", data = data.packetPretty(), length = msg.len(), raddr +# else: +# trace "onReceive (client)", data = data.packetPretty(), length = msg.len(), raddr +# usrsctp_freedumpbuffer(data) +# +# if sctp.isServer: +# sctp.sentAddress = raddr +# usrsctp_conninput(cast[pointer](sctp), unsafeAddr msg[0], uint(msg.len), 0) +# else: +# let conn = await sctp.getOrCreateConnection(udp, raddr) +# sctp.sentConnection = conn +# sctp.sentAddress = raddr +# usrsctp_conninput(cast[pointer](sctp), unsafeAddr msg[0], uint(msg.len), 0) +# let +# localAddr = TransportAddress(family: AddressFamily.IPv4, port: Port(port)) +# laddr = initTAddress("127.0.0.1:" & $port) +# udp = newDatagramTransport(onReceive, local = laddr) +# trace "local address", localAddr, laddr +# sctp.udp = udp +# sctp.timersHandler = timersHandler() +# +# usrsctp_init_nothreads(port, sendCallback, printf) +# discard usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_NONE) +# discard usrsctp_sysctl_set_sctp_ecn_enable(1) +# usrsctp_register_address(cast[pointer](sctp)) +# +# return sctp proc stop*(self: Sctp) {.async.} = discard self.usrsctpAwait usrsctp_finish() @@ -343,20 +342,21 @@ proc stop*(self: Sctp) {.async.} = proc readLoopProc(res: SctpConn) {.async.} = while true: + trace "Read Loop Proc Before" let msg = await res.conn.read() data = usrsctp_dumppacket(unsafeAddr msg[0], uint(msg.len), SCTP_DUMP_INBOUND) + trace "Read Loop Proc Before", isnil=data.isNil() if data != nil: trace "Receive connection", remoteAddress = res.conn.raddr, data = data.packetPretty() usrsctp_freedumpbuffer(data) + res.sctp.sentConnection = res usrsctp_conninput(cast[pointer](res), unsafeAddr msg[0], uint(msg.len), 0) proc accept*(self: Sctp): Future[SctpConn] {.async.} = if not self.isServer: raise newSctpError("Not a server") - let conn = await self.dtls.accept() - var res = SctpConn.new(conn) - res.conn = await self.dtls.accept() + var res = SctpConn.new(await self.dtls.accept, self) usrsctp_register_address(cast[pointer](res)) res.readLoop = res.readLoopProc() res.acceptEvent.clear() From 1132a5e42dc2f64be370c851c571acdb8ebb5111 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Tue, 14 Nov 2023 16:02:44 +0100 Subject: [PATCH 48/66] Fix dtlsRecv / read & add certificate request --- webrtc/datachannel.nim | 2 +- webrtc/dtls/dtls.nim | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/webrtc/datachannel.nim b/webrtc/datachannel.nim index 4d6675b..2fcb575 100644 --- a/webrtc/datachannel.nim +++ b/webrtc/datachannel.nim @@ -72,7 +72,7 @@ type DataChannelConnection* = ref object readLoopFut: Future[void] streams: Table[uint16, DataChannelStream] - conn: SctpConn + conn*: SctpConn incomingStreams: AsyncQueue[DataChannelStream] proc read*(stream: DataChannelStream): Future[seq[byte]] {.async.} = diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 703c78d..60e540f 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -67,12 +67,14 @@ proc dtlsSend*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = result = len.cint proc dtlsRecv*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = - trace "dtls receive", len - var - self = cast[DtlsConn](ctx) - dataRecv = self.dataRecv.popFirstNoWait() + let self = cast[DtlsConn](ctx) + if self.dataRecv.len() == 0: + return MBEDTLS_ERR_SSL_WANT_READ + + var dataRecv = self.dataRecv.popFirstNoWait() copyMem(buf, addr dataRecv[0], dataRecv.len()) result = dataRecv.len().cint + trace "dtls receive", len, result proc init*(self: DtlsConn, conn: StunConn, laddr: TransportAddress) {.async.} = self.conn = conn @@ -85,11 +87,14 @@ proc write*(self: DtlsConn, msg: seq[byte]) {.async.} = proc read*(self: DtlsConn): Future[seq[byte]] {.async.} = var res = newSeq[byte](8192) - let tmp = await self.dataRecv.popFirst() - self.dataRecv.addFirstNoWait(tmp) - let length = mbedtls_ssl_read(addr self.ssl, cast[ptr byte](addr res[0]), res.len().uint) - res.setLen(length) - return res + while true: + let tmp = await self.dataRecv.popFirst() + self.dataRecv.addFirstNoWait(tmp) + let length = mbedtls_ssl_read(addr self.ssl, cast[ptr byte](addr res[0]), res.len().uint) + if length == MBEDTLS_ERR_SSL_WANT_READ: + continue + res.setLen(length) + return res proc close*(self: DtlsConn) {.async.} = discard @@ -236,6 +241,7 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} = mb_ssl_setup(res.ssl, res.config) mb_ssl_session_reset(res.ssl) mbedtls_ssl_set_verify(addr res.ssl, verify, cast[pointer](res)) + mbedtls_ssl_conf_authmode(addr res.ssl, MBEDTLS_SSL_VERIFY_REQUIRED) # TODO: create template mb_ssl_set_bio(res.ssl, cast[pointer](res), dtlsSend, dtlsRecv, nil) while true: From 070aa1185433bfb449f3f07c188da82597e4f531 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Tue, 14 Nov 2023 16:32:08 +0100 Subject: [PATCH 49/66] fix --- webrtc/dtls/dtls.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 60e540f..33e2739 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -241,7 +241,7 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} = mb_ssl_setup(res.ssl, res.config) mb_ssl_session_reset(res.ssl) mbedtls_ssl_set_verify(addr res.ssl, verify, cast[pointer](res)) - mbedtls_ssl_conf_authmode(addr res.ssl, MBEDTLS_SSL_VERIFY_REQUIRED) # TODO: create template + mbedtls_ssl_conf_authmode(addr res.config, MBEDTLS_SSL_VERIFY_REQUIRED) # TODO: create template mb_ssl_set_bio(res.ssl, cast[pointer](res), dtlsSend, dtlsRecv, nil) while true: From 7d14cdcb48e24f6e1736d0b335e4e98bbd9221fb Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Wed, 22 Nov 2023 14:54:48 +0100 Subject: [PATCH 50/66] expose dtls connection --- webrtc/sctp.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index 8eafc09..d427336 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -41,7 +41,7 @@ type params*: SctpMessageParameters SctpConn* = ref object - conn: DtlsConn + conn*: DtlsConn state: SctpState connectEvent: AsyncEvent acceptEvent: AsyncEvent From de12f43ef9fc2bf7ed6db8e33d24ed6a73f5190e Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Tue, 28 Nov 2023 16:06:26 +0100 Subject: [PATCH 51/66] Dtls set local certificate --- webrtc/dtls/dtls.nim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 33e2739..15a8a50 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -196,7 +196,7 @@ proc serverHandshake(self: DtlsConn) {.async.} = proc remoteCertificate*(conn: DtlsConn): seq[byte] = conn.remoteCert -proc localCertificate*(self: Dtls): seq[byte] = +proc localCertificate*(self: DtlsConn): seq[byte] = self.localCert proc verify(ctx: pointer, pcert: ptr mbedtls_x509_crt, @@ -224,7 +224,6 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} = var pkey = self.serverPrivKey var srvcert = self.serverCert - res.localCert = newSeq[byte](srvcert.raw.len) res.localCert = self.localCert mb_ssl_config_defaults(res.config, From ec51a19880f533d2f0afc9e79fa9894f81f25c40 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Tue, 28 Nov 2023 16:20:43 +0100 Subject: [PATCH 52/66] add localcert for Dtls --- webrtc/dtls/dtls.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 15a8a50..b6e1d60 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -196,7 +196,10 @@ proc serverHandshake(self: DtlsConn) {.async.} = proc remoteCertificate*(conn: DtlsConn): seq[byte] = conn.remoteCert -proc localCertificate*(self: DtlsConn): seq[byte] = +proc localCertificate*(conn: DtlsConn): seq[byte] = + conn.localCert + +proc localCertificate*(self: Dtls): seq[byte] = self.localCert proc verify(ctx: pointer, pcert: ptr mbedtls_x509_crt, From 525fb37882397dead197152e0e49af38796940b5 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Wed, 29 Nov 2023 16:19:31 +0100 Subject: [PATCH 53/66] Make authmode optional --- webrtc/dtls/dtls.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index b6e1d60..cd61c17 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -243,7 +243,7 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} = mb_ssl_setup(res.ssl, res.config) mb_ssl_session_reset(res.ssl) mbedtls_ssl_set_verify(addr res.ssl, verify, cast[pointer](res)) - mbedtls_ssl_conf_authmode(addr res.config, MBEDTLS_SSL_VERIFY_REQUIRED) # TODO: create template + mbedtls_ssl_conf_authmode(addr res.config, MBEDTLS_SSL_VERIFY_OPTIONAL) # TODO: create template mb_ssl_set_bio(res.ssl, cast[pointer](res), dtlsSend, dtlsRecv, nil) while true: From 9a6657922ace51a93feb57520b12d9ab5a550a13 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 15 Dec 2023 09:53:20 +0100 Subject: [PATCH 54/66] add logs & fix some bugs in sctp --- webrtc/datachannel.nim | 1 + webrtc/dtls/dtls.nim | 5 ++++- webrtc/sctp.nim | 23 ++++++++++++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/webrtc/datachannel.nim b/webrtc/datachannel.nim index 2fcb575..1fac163 100644 --- a/webrtc/datachannel.nim +++ b/webrtc/datachannel.nim @@ -91,6 +91,7 @@ proc write*(stream: DataChannelStream, buf: seq[byte]) {.async.} = #TODO add reliability params if buf.len == 0: + trace "Datachannel write empty" sendInfo.protocolId = uint32(WebRtcBinaryEmpty) await stream.conn.write(@[0'u8], sendInfo) else: diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index cd61c17..22398e9 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -58,11 +58,11 @@ type remoteCert: seq[byte] proc dtlsSend*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = - trace "dtls send", len var self = cast[DtlsConn](ctx) var toWrite = newSeq[byte](len) if len > 0: copyMem(addr toWrite[0], buf, len) + trace "dtls send", len self.sendFuture = self.conn.write(self.raddr, toWrite) result = len.cint @@ -82,6 +82,7 @@ proc init*(self: DtlsConn, conn: StunConn, laddr: TransportAddress) {.async.} = self.dataRecv = newAsyncQueue[seq[byte]]() proc write*(self: DtlsConn, msg: seq[byte]) {.async.} = + trace "Dtls write", length = msg.len() var buf = msg discard mbedtls_ssl_write(addr self.ssl, cast[ptr byte](addr buf[0]), buf.len().uint) @@ -93,6 +94,8 @@ proc read*(self: DtlsConn): Future[seq[byte]] {.async.} = let length = mbedtls_ssl_read(addr self.ssl, cast[ptr byte](addr res[0]), res.len().uint) if length == MBEDTLS_ERR_SSL_WANT_READ: continue + if length < 0: + trace "dtls read", error = $(length.mbedtls_high_level_strerr()) res.setLen(length) return res diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index d427336..099d22e 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -133,7 +133,7 @@ proc write*( buf: seq[byte], sendParams = default(SctpMessageParameters), ) {.async.} = - trace "Write", buf + trace "Write", buf, sctp = cast[uint64](self), sock = cast[uint64](self.sctpSocket) self.sctp.sentConnection = self self.sctp.sentAddress = self.address @@ -142,7 +142,6 @@ proc write*( if sendParams != default(SctpMessageParameters): (sctp_sndinfo( snd_sid: sendParams.streamId, - #TODO endianness? snd_ppid: sendParams.protocolId, snd_flags: sendParams.toFlags ), cuint(SCTP_SENDV_SNDINFO)) @@ -152,6 +151,9 @@ proc write*( self.sctpSocket.usrsctp_sendv(unsafeAddr buf[0], buf.len.uint, nil, 0, unsafeAddr sendInfo, sizeof(sendInfo).SockLen, infoType, 0) + if sendvErr < 0: + perror("usrsctp_sendv") + trace "write sendv error?", sendvErr, sendParams proc write*(self: SctpConn, s: string) {.async.} = await self.write(s.toBytes()) @@ -161,8 +163,9 @@ proc close*(self: SctpConn) {.async.} = proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = let - events = usrsctp_get_events(sock) conn = cast[SctpConn](data) + events = usrsctp_get_events(sock) + trace "Handle Upcall", events if conn.state == Connecting: if bitand(events, SCTP_EVENT_ERROR) != 0: @@ -182,6 +185,7 @@ proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = rnLen = sizeof(message.info).SockLen infotype: uint flags: int + trace "recv from", sockuint64=cast[uint64](sock) let n = sock.usrsctp_recvv(cast[pointer](addr message.data[0]), message.data.len.uint, cast[ptr SockAddr](addr address), cast[ptr SockLen](addr addressLen), @@ -206,6 +210,8 @@ proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = conn.dataRecv.addLastNoWait(message) except AsyncQueueFullError: trace "Queue full, dropping packet" + elif bitand(events, SCTP_EVENT_WRITE) != 0: + trace "sctp event write in the upcall" else: warn "Handle Upcall unexpected event", events @@ -220,7 +226,14 @@ proc handleAccept(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = doAssert 0 == sctpSocket.usrsctp_set_non_blocking(1) let conn = cast[SctpConn](sconn.sconn_addr) + conn.sctpSocket = sctpSocket conn.state = Connected + var nodelay: uint32 = 1 + doAssert 0 == conn.sctpSocket.usrsctp_set_upcall(handleUpcall, cast[pointer](conn)) + doAssert 0 == conn.sctpSocket.usrsctp_setsockopt(IPPROTO_SCTP, + SCTP_NODELAY, + addr nodelay, + sizeof(nodelay).SockLen) conn.acceptEvent.fire() # proc getOrCreateConnection(self: Sctp, @@ -347,8 +360,8 @@ proc readLoopProc(res: SctpConn) {.async.} = msg = await res.conn.read() data = usrsctp_dumppacket(unsafeAddr msg[0], uint(msg.len), SCTP_DUMP_INBOUND) trace "Read Loop Proc Before", isnil=data.isNil() - if data != nil: - trace "Receive connection", remoteAddress = res.conn.raddr, data = data.packetPretty() + if not data.isNil(): + trace "Receive data", remoteAddress = res.conn.raddr, data = data.packetPretty() usrsctp_freedumpbuffer(data) res.sctp.sentConnection = res usrsctp_conninput(cast[pointer](res), unsafeAddr msg[0], uint(msg.len), 0) From 2591a158baf33784e2d46aee2cee17924c48b501 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 23 Feb 2024 11:06:59 +0100 Subject: [PATCH 55/66] A lot of fixes --- webrtc/datachannel.nim | 29 +++++++++++--- webrtc/sctp.nim | 70 +++++++++++++++++++++++---------- webrtc/stun/stun_connection.nim | 1 + webrtc/udp_connection.nim | 2 +- 4 files changed, 75 insertions(+), 27 deletions(-) diff --git a/webrtc/datachannel.nim b/webrtc/datachannel.nim index 1fac163..56fba3a 100644 --- a/webrtc/datachannel.nim +++ b/webrtc/datachannel.nim @@ -72,13 +72,17 @@ type DataChannelConnection* = ref object readLoopFut: Future[void] streams: Table[uint16, DataChannelStream] + streamId: uint16 conn*: SctpConn incomingStreams: AsyncQueue[DataChannelStream] proc read*(stream: DataChannelStream): Future[seq[byte]] {.async.} = - return await stream.receivedData.popLast() + let x = await stream.receivedData.popFirst() + trace "read", length=x.len(), id=stream.id + return x proc write*(stream: DataChannelStream, buf: seq[byte]) {.async.} = + trace "write", length=buf.len(), id=stream.id var sendInfo = SctpMessageParameters( streamId: stream.id, @@ -105,14 +109,23 @@ proc sendControlMessage(stream: DataChannelStream, msg: DataChannelMessage) {.as endOfRecord: true, protocolId: uint32(WebRtcDcep) ) + trace "send control message", msg await stream.conn.write(encoded, sendInfo) proc openStream*( conn: DataChannelConnection, - streamId: uint16, + noiseHandshake: bool, reliability = Reliable, reliabilityParameter: uint32 = 0): Future[DataChannelStream] {.async.} = + let streamId: uint16 = + if not noiseHandshake: + let res = conn.streamId + conn.streamId += 2 + res + else: + 0 + trace "open stream", streamId if reliability in [Reliable, ReliableUnordered] and reliabilityParameter != 0: raise newException(ValueError, "reliabilityParameter should be 0") @@ -144,6 +157,7 @@ proc openStream*( proc handleData(conn: DataChannelConnection, msg: SctpMessage) = let streamId = msg.params.streamId + trace "handle data message", streamId, ppid = msg.params.protocolId, data = msg.data if streamId notin conn.streams: raise newException(ValueError, "got data for unknown streamid") @@ -162,6 +176,7 @@ proc handleControl(conn: DataChannelConnection, msg: SctpMessage) {.async.} = decoded = Binary.decode(msg.data, DataChannelMessage) streamId = msg.params.streamId + trace "handle control message", decoded, streamId = msg.params.streamId if decoded.messageType == Ack: if streamId notin conn.streams: raise newException(ValueError, "got ack for unknown streamid") @@ -178,6 +193,7 @@ proc handleControl(conn: DataChannelConnection, msg: SctpMessage) {.async.} = ) conn.streams[streamId] = stream + conn.incomingStreams.addLastNoWait(stream) await stream.sendControlMessage(DataChannelMessage(messageType: Ack)) @@ -185,6 +201,7 @@ proc readLoop(conn: DataChannelConnection) {.async.} = try: while true: let message = await conn.conn.read() + # TODO: might be necessary to check the others protocolId at some point if message.params.protocolId == uint32(WebRtcDcep): #TODO should we really await? await conn.handleControl(message) @@ -195,12 +212,12 @@ proc readLoop(conn: DataChannelConnection) {.async.} = discard proc accept*(conn: DataChannelConnection): Future[DataChannelStream] {.async.} = - if isNil(conn.readLoopFut): - conn.readLoopFut = conn.readLoop() return await conn.incomingStreams.popFirst() proc new*(_: type DataChannelConnection, conn: SctpConn): DataChannelConnection = - DataChannelConnection( + result = DataChannelConnection( conn: conn, - incomingStreams: newAsyncQueue[DataChannelStream]() + incomingStreams: newAsyncQueue[DataChannelStream](), + streamId: 1'u16 # TODO: Serveur == 1, client == 2 ) + conn.readLoopFut = conn.readLoop() diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index 099d22e..20fd3ab 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -8,9 +8,10 @@ # those terms. import tables, bitops, posix, strutils, sequtils -import chronos, chronicles, stew/[ranges/ptr_arith, byteutils] +import chronos, chronicles, stew/[ranges/ptr_arith, byteutils, endians2] import usrsctp import dtls/dtls +import binary_serialization export chronicles @@ -37,7 +38,7 @@ type SctpMessage* = ref object data*: seq[byte] - info: sctp_rcvinfo + info: sctp_recvv_rn params*: SctpMessageParameters SctpConn* = ref object @@ -67,6 +68,19 @@ type sentAddress: TransportAddress sentFuture: Future[void] + # Those two objects are only here for debugging purpose + SctpChunk = object + chunkType: uint8 + flag: uint8 + length {.bin_value: it.data.len() + 4.}: uint16 + data {.bin_len: it.length - 4.}: seq[byte] + + SctpPacketStructure = object + srcPort: uint16 + dstPort: uint16 + verifTag: uint32 + checksum: uint32 + const IPPROTO_SCTP = 132 @@ -86,6 +100,19 @@ template usrsctpAwait(self: SctpConn|Sctp, body: untyped): untyped = proc perror(error: cstring) {.importc, cdecl, header: "".} proc printf(format: cstring) {.cdecl, importc: "printf", varargs, header: "", gcsafe.} +proc printSctpPacket(buffer: seq[byte]) = + let s = Binary.decode(buffer, SctpPacketStructure) + echo " => \e[31;1mStructure\e[0m: ", s + var size = sizeof(SctpPacketStructure) + var i = 1 + while size < buffer.len: + let c = Binary.decode(buffer[size..^1], SctpChunk) + echo " ===> \e[32;1mChunk ", i, "\e[0m ", c + i.inc() + size.inc(c.length.int) + while size mod 4 != 0: + size.inc() + proc packetPretty(packet: cstring): string = let data = $packet let ctn = data[23..^16] @@ -137,22 +164,23 @@ proc write*( self.sctp.sentConnection = self self.sctp.sentAddress = self.address - let + var cpy = buf + var (sendInfo, infoType) = if sendParams != default(SctpMessageParameters): (sctp_sndinfo( snd_sid: sendParams.streamId, - snd_ppid: sendParams.protocolId, + snd_ppid: sendParams.protocolId.swapBytes(), snd_flags: sendParams.toFlags ), cuint(SCTP_SENDV_SNDINFO)) else: (default(sctp_sndinfo), cuint(SCTP_SENDV_NOINFO)) sendvErr = self.usrsctpAwait: - self.sctpSocket.usrsctp_sendv(unsafeAddr buf[0], buf.len.uint, - nil, 0, unsafeAddr sendInfo, sizeof(sendInfo).SockLen, + self.sctpSocket.usrsctp_sendv(cast[pointer](addr cpy[0]), cpy.len.uint, nil, 0, + cast[pointer](addr sendInfo), sizeof(sendInfo).SockLen, infoType, 0) if sendvErr < 0: - perror("usrsctp_sendv") + perror("usrsctp_sendv") # TODO: throw an exception trace "write sendv error?", sendvErr, sendParams proc write*(self: SctpConn, s: string) {.async.} = @@ -182,7 +210,7 @@ proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = address: Sockaddr_storage rn: sctp_recvv_rn addressLen = sizeof(Sockaddr_storage).SockLen - rnLen = sizeof(message.info).SockLen + rnLen = sizeof(sctp_recvv_rn).SockLen infotype: uint flags: int trace "recv from", sockuint64=cast[uint64](sock) @@ -197,11 +225,12 @@ proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = perror("usrsctp_recvv") return elif n > 0: - if infotype == SCTP_RECVV_RCVINFO: - message.params = SctpMessageParameters( - #TODO endianness? - protocolId: message.info.rcv_ppid, - streamId: message.info.rcv_sid + # It might be necessary to check if infotype == SCTP_RECVV_RCVINFO + message.data.delete(n..\e[0m" let res = Stun.getResponse(msg, self.laddr) if res.isSome(): await self.conn.write(raddr, res.get()) diff --git a/webrtc/udp_connection.nim b/webrtc/udp_connection.nim index adf2463..8c873f7 100644 --- a/webrtc/udp_connection.nim +++ b/webrtc/udp_connection.nim @@ -24,7 +24,7 @@ proc init*(self: UdpConn, laddr: TransportAddress) = proc onReceive(udp: DatagramTransport, address: TransportAddress) {.async, gcsafe.} = let msg = udp.getMessage() - echo "\e[33m\e[0;1m onReceive\e[0m: ", msg.len() + echo "\e[33m\e[0;1m onReceive\e[0m" self.dataRecv.addLastNoWait((msg, address)) self.dataRecv = newAsyncQueue[(seq[byte], TransportAddress)]() From 0fa09ba6f734892652cda3719723bad406043bff Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 23 Feb 2024 15:14:54 +0100 Subject: [PATCH 56/66] first draft --- webrtc/dtls/dtls.nim | 103 +++++++++++++++++++++++++++++++++---------- webrtc/sctp.nim | 35 ++++++++------- 2 files changed, 97 insertions(+), 41 deletions(-) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 22398e9..9d44f1f 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -84,14 +84,16 @@ proc init*(self: DtlsConn, conn: StunConn, laddr: TransportAddress) {.async.} = proc write*(self: DtlsConn, msg: seq[byte]) {.async.} = trace "Dtls write", length = msg.len() var buf = msg - discard mbedtls_ssl_write(addr self.ssl, cast[ptr byte](addr buf[0]), buf.len().uint) + # TODO: exception catching + discard mb_ssl_write(self.ssl, buf) proc read*(self: DtlsConn): Future[seq[byte]] {.async.} = var res = newSeq[byte](8192) while true: let tmp = await self.dataRecv.popFirst() self.dataRecv.addFirstNoWait(tmp) - let length = mbedtls_ssl_read(addr self.ssl, cast[ptr byte](addr res[0]), res.len().uint) + # TODO: exception catching + let length = mb_ssl_read(self.ssl, res) if length == MBEDTLS_ERR_SSL_WANT_READ: continue if length < 0: @@ -191,10 +193,37 @@ proc serverHandshake(self: DtlsConn) {.async.} = continue elif res != 0: raise newException(DtlsError, $(res.mbedtls_high_level_strerr())) - # var remoteCertPtr = mbedtls_ssl_get_peer_cert(addr self.ssl) - # let remoteCert = remoteCertPtr[] - # self.remoteCert = newSeq[byte](remoteCert.raw.len) - # copyMem(addr self.remoteCert[0], remoteCert.raw.p, remoteCert.raw.len) + +proc clientHandshake(self: DtlsConn) {.async.} = + var shouldRead = false + while self.ssl.private_state != MBEDTLS_SSL_HANDSHAKE_OVER: + if shouldRead: + case self.raddr.family + of AddressFamily.IPv4: + mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v4) + of AddressFamily.IPv6: + mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v6) + else: + raise newException(DtlsError, "Remote address isn't an IP address") + let tmp = await self.dataRecv.popFirst() + self.dataRecv.addFirstNoWait(tmp) + self.sendFuture = nil + let res = mb_ssl_handshake_step(self.ssl) + if not self.sendFuture.isNil(): await self.sendFuture + shouldRead = false + if res == MBEDTLS_ERR_SSL_WANT_WRITE: + continue + elif res == MBEDTLS_ERR_SSL_WANT_READ: + # or self.ssl.private_state == MBEDTLS_SSL_SERVER_KEY_EXCHANGE: + # TODO: Might need to check directly on mbedtls C source + shouldRead = true + continue + elif res == MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED: + mb_ssl_session_reset(self.ssl) + shouldRead = true + continue + elif res != 0: + raise newException(DtlsError, $(res.mbedtls_high_level_strerr())) proc remoteCertificate*(conn: DtlsConn): seq[byte] = conn.remoteCert @@ -245,8 +274,8 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} = mb_ssl_set_timer_cb(res.ssl, res.timer) mb_ssl_setup(res.ssl, res.config) mb_ssl_session_reset(res.ssl) - mbedtls_ssl_set_verify(addr res.ssl, verify, cast[pointer](res)) - mbedtls_ssl_conf_authmode(addr res.config, MBEDTLS_SSL_VERIFY_OPTIONAL) # TODO: create template + mb_ssl_set_verify(res.ssl, verify, res) + mb_ssl_conf_authmode(res.config, MBEDTLS_SSL_VERIFY_OPTIONAL) mb_ssl_set_bio(res.ssl, cast[pointer](res), dtlsSend, dtlsRecv, nil) while true: @@ -263,20 +292,46 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} = continue return res -proc dial*(self: Dtls, raddr: TransportAddress): Future[DtlsConn] {.async.} = - discard +proc connect*(self: Dtls, raddr: TransportAddress): Future[DtlsConn] {.async.} = + var + selfvar = self + res = DtlsConn() -#import ../udp_connection -#import stew/byteutils -#proc main() {.async.} = -# let laddr = initTAddress("127.0.0.1:4433") -# let udp = UdpConn() -# await udp.init(laddr) -# let stun = StunConn() -# await stun.init(udp, laddr) -# let dtls = Dtls() -# dtls.start(stun, laddr) -# let x = await dtls.accept() -# echo "Recv: <", string.fromBytes(await x.read()), ">" -# -#waitFor(main()) + await res.init(self.conn, self.laddr) + mb_ssl_init(res.ssl) + mb_ssl_config_init(res.config) + + var pkey = res.ctr_drbg.generateKey() + var srvcert = res.ctr_drbg.generateCertificate(pkey) + res.localCert = newSeq[byte](srvcert.raw.len) + copyMem(addr res.localCert[0], srvcert.raw.p, srvcert.raw.len) + + mb_ctr_drbg_init(res.ctr_drbg) + mb_entropy_init(res.entropy) + mb_ctr_drbg_seed(res.ctr_drbg, mbedtls_entropy_func, res.entropy, nil, 0) + + mb_ssl_config_defaults(res.config, + MBEDTLS_SSL_IS_CLIENT, + MBEDTLS_SSL_TRANSPORT_DATAGRAM, + MBEDTLS_SSL_PRESET_DEFAULT) + mb_ssl_conf_rng(res.config, mbedtls_ctr_drbg_random, res.ctr_drbg) + mb_ssl_conf_read_timeout(res.config, 10000) # in milliseconds + mb_ssl_conf_ca_chain(res.config, srvcert.next, nil) + mb_ssl_set_timer_cb(res.ssl, res.timer) + mb_ssl_setup(res.ssl, res.config) + mb_ssl_set_verify(res.ssl, verify, res) + mb_ssl_conf_authmode(res.config, MBEDTLS_SSL_VERIFY_OPTIONAL) + mb_ssl_set_bio(res.ssl, cast[pointer](res), + dtlsSend, dtlsRecv, nil) + + res.raddr = raddr + self.connections[raddr] = res + + try: + await res.clientHandshake() + except CatchableError as exc: + trace "Handshake fail", remoteAddress = raddr, error = exc.msg + self.connections.del(raddr) + raise exc + + return res diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index 20fd3ab..d77058b 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -398,7 +398,7 @@ proc readLoopProc(res: SctpConn) {.async.} = proc accept*(self: Sctp): Future[SctpConn] {.async.} = if not self.isServer: raise newSctpError("Not a server") - var res = SctpConn.new(await self.dtls.accept, self) + var res = SctpConn.new(await self.dtls.accept(), self) usrsctp_register_address(cast[pointer](res)) res.readLoop = res.readLoopProc() res.acceptEvent.clear() @@ -429,20 +429,21 @@ proc listen*(self: Sctp, sctpPort: uint16 = 5000) = proc connect*(self: Sctp, address: TransportAddress, sctpPort: uint16 = 5000): Future[SctpConn] {.async.} = - discard + let + sctpSocket = usrsctp_socket(AF_CONN, posix.SOCK_STREAM, IPPROTO_SCTP, nil, nil, 0, nil) + res = SctpConn.new(await self.dtls.connect(address), self) -# proc connect*(self: Sctp, -# address: TransportAddress, -# sctpPort: uint16 = 5000): Future[SctpConn] {.async.} = -# trace "Connect", address, sctpPort -# let conn = await self.getOrCreateConnection(self.udp, address, sctpPort) -# if conn.state == Connected: -# return conn -# try: -# await conn.connectEvent.wait() # TODO: clear? -# except CancelledError as exc: -# conn.sctpSocket.usrsctp_close() -# return nil -# if conn.state != Connected: -# raise newSctpError("Cannot connect to " & $address) -# return conn + #usrsctp_register_address(cast[pointer](res)) + +# trace "Connect", address, sctpPort +# let conn = await self.getOrCreateConnection(self.udp, address, sctpPort) +# if conn.state == Connected: +# return conn +# try: +# await conn.connectEvent.wait() # TODO: clear? +# except CancelledError as exc: +# conn.sctpSocket.usrsctp_close() +# return nil +# if conn.state != Connected: +# raise newSctpError("Cannot connect to " & $address) +# return conn From f6ba79428124dbd89d086b8ece0ceb7d6e6d0010 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Wed, 28 Feb 2024 13:49:43 +0100 Subject: [PATCH 57/66] sctp/dtls client done --- webrtc.nimble | 1 - webrtc/dtls/dtls.nim | 72 ++++++------------ webrtc/sctp.nim | 150 ++++++++++++-------------------------- webrtc/udp_connection.nim | 6 +- 4 files changed, 74 insertions(+), 155 deletions(-) diff --git a/webrtc.nimble b/webrtc.nimble index 0031ecd..c30bde2 100644 --- a/webrtc.nimble +++ b/webrtc.nimble @@ -11,6 +11,5 @@ requires "nim >= 1.2.0", "https://github.com/status-im/nim-binary-serialization.git", "https://github.com/status-im/nim-mbedtls.git" - proc runTest(filename: string) = discard diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 9d44f1f..808a5f1 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -82,10 +82,13 @@ proc init*(self: DtlsConn, conn: StunConn, laddr: TransportAddress) {.async.} = self.dataRecv = newAsyncQueue[seq[byte]]() proc write*(self: DtlsConn, msg: seq[byte]) {.async.} = - trace "Dtls write", length = msg.len() var buf = msg - # TODO: exception catching - discard mb_ssl_write(self.ssl, buf) + try: + let write = mb_ssl_write(self.ssl, buf) + trace "Dtls write", msgLen = msg.len(), actuallyWrote = write + except MbedTLSError as exc: + trace "Dtls write error", errorMsg = exc.msg + raise exc proc read*(self: DtlsConn): Future[seq[byte]] {.async.} = var res = newSeq[byte](8192) @@ -97,7 +100,7 @@ proc read*(self: DtlsConn): Future[seq[byte]] {.async.} = if length == MBEDTLS_ERR_SSL_WANT_READ: continue if length < 0: - trace "dtls read", error = $(length.mbedtls_high_level_strerr()) + trace "dtls read", error = $(length.cint.mbedtls_high_level_strerr()) res.setLen(length) return res @@ -164,47 +167,18 @@ proc stop*(self: Dtls) = self.readLoop.cancel() self.started = false -proc serverHandshake(self: DtlsConn) {.async.} = - var shouldRead = true +proc dtlsHandshake(self: DtlsConn, isServer: bool) {.async.} = + var shouldRead = isServer while self.ssl.private_state != MBEDTLS_SSL_HANDSHAKE_OVER: if shouldRead: - case self.raddr.family - of AddressFamily.IPv4: - mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v4) - of AddressFamily.IPv6: - mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v6) - else: - raise newException(DtlsError, "Remote address isn't an IP address") - let tmp = await self.dataRecv.popFirst() - self.dataRecv.addFirstNoWait(tmp) - self.sendFuture = nil - let res = mb_ssl_handshake_step(self.ssl) - if not self.sendFuture.isNil(): await self.sendFuture - shouldRead = false - if res == MBEDTLS_ERR_SSL_WANT_WRITE: - continue - elif res == MBEDTLS_ERR_SSL_WANT_READ or - self.ssl.private_state == MBEDTLS_SSL_CLIENT_KEY_EXCHANGE: - shouldRead = true - continue - elif res == MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED: - mb_ssl_session_reset(self.ssl) - shouldRead = true - continue - elif res != 0: - raise newException(DtlsError, $(res.mbedtls_high_level_strerr())) - -proc clientHandshake(self: DtlsConn) {.async.} = - var shouldRead = false - while self.ssl.private_state != MBEDTLS_SSL_HANDSHAKE_OVER: - if shouldRead: - case self.raddr.family - of AddressFamily.IPv4: - mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v4) - of AddressFamily.IPv6: - mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v6) - else: - raise newException(DtlsError, "Remote address isn't an IP address") + if isServer: + case self.raddr.family + of AddressFamily.IPv4: + mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v4) + of AddressFamily.IPv6: + mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v6) + else: + raise newException(DtlsError, "Remote address isn't an IP address") let tmp = await self.dataRecv.popFirst() self.dataRecv.addFirstNoWait(tmp) self.sendFuture = nil @@ -214,8 +188,6 @@ proc clientHandshake(self: DtlsConn) {.async.} = if res == MBEDTLS_ERR_SSL_WANT_WRITE: continue elif res == MBEDTLS_ERR_SSL_WANT_READ: - # or self.ssl.private_state == MBEDTLS_SSL_SERVER_KEY_EXCHANGE: - # TODO: Might need to check directly on mbedtls C source shouldRead = true continue elif res == MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED: @@ -284,7 +256,7 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} = res.raddr = raddr res.dataRecv.addLastNoWait(buf) self.connections[raddr] = res - await res.serverHandshake() + await res.dtlsHandshake(true) break except CatchableError as exc: trace "Handshake fail", remoteAddress = raddr, error = exc.msg @@ -301,6 +273,9 @@ proc connect*(self: Dtls, raddr: TransportAddress): Future[DtlsConn] {.async.} = mb_ssl_init(res.ssl) mb_ssl_config_init(res.config) + res.ctr_drbg = self.ctr_drbg + res.entropy = self.entropy + var pkey = res.ctr_drbg.generateKey() var srvcert = res.ctr_drbg.generateCertificate(pkey) res.localCert = newSeq[byte](srvcert.raw.len) @@ -321,14 +296,13 @@ proc connect*(self: Dtls, raddr: TransportAddress): Future[DtlsConn] {.async.} = mb_ssl_setup(res.ssl, res.config) mb_ssl_set_verify(res.ssl, verify, res) mb_ssl_conf_authmode(res.config, MBEDTLS_SSL_VERIFY_OPTIONAL) - mb_ssl_set_bio(res.ssl, cast[pointer](res), - dtlsSend, dtlsRecv, nil) + mb_ssl_set_bio(res.ssl, cast[pointer](res), dtlsSend, dtlsRecv, nil) res.raddr = raddr self.connections[raddr] = res try: - await res.clientHandshake() + await res.dtlsHandshake(false) except CatchableError as exc: trace "Handshake fail", remoteAddress = raddr, error = exc.msg self.connections.del(raddr) diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index d77058b..8cd5f41 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -64,7 +64,6 @@ type sockServer: ptr socket pendingConnections: seq[SctpConn] pendingConnections2: Table[SockAddr, SctpConn] - sentConnection: SctpConn sentAddress: TransportAddress sentFuture: Future[void] @@ -161,24 +160,23 @@ proc write*( sendParams = default(SctpMessageParameters), ) {.async.} = trace "Write", buf, sctp = cast[uint64](self), sock = cast[uint64](self.sctpSocket) - self.sctp.sentConnection = self self.sctp.sentAddress = self.address var cpy = buf - var - (sendInfo, infoType) = - if sendParams != default(SctpMessageParameters): - (sctp_sndinfo( - snd_sid: sendParams.streamId, - snd_ppid: sendParams.protocolId.swapBytes(), - snd_flags: sendParams.toFlags - ), cuint(SCTP_SENDV_SNDINFO)) - else: - (default(sctp_sndinfo), cuint(SCTP_SENDV_NOINFO)) - sendvErr = self.usrsctpAwait: - self.sctpSocket.usrsctp_sendv(cast[pointer](addr cpy[0]), cpy.len.uint, nil, 0, - cast[pointer](addr sendInfo), sizeof(sendInfo).SockLen, - infoType, 0) + let sendvErr = + if sendParams == default(SctpMessageParameters): + self.usrsctpAwait: + self.sctpSocket.usrsctp_sendv(cast[pointer](addr cpy[0]), cpy.len().uint, nil, 0, + nil, 0, SCTP_SENDV_NOINFO.cuint, 0) + else: + let sendInfo = sctp_sndinfo( + snd_sid: sendParams.streamId, + snd_ppid: sendParams.protocolId.swapBytes(), + snd_flags: sendParams.toFlags) + self.usrsctpAwait: + self.sctpSocket.usrsctp_sendv(cast[pointer](addr cpy[0]), cpy.len().uint, nil, 0, + cast[pointer](addr sendInfo), sizeof(sendInfo).SockLen, + SCTP_SENDV_SNDINFO.cuint, 0) if sendvErr < 0: perror("usrsctp_sendv") # TODO: throw an exception trace "write sendv error?", sendvErr, sendParams @@ -194,7 +192,7 @@ proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = conn = cast[SctpConn](data) events = usrsctp_get_events(sock) - trace "Handle Upcall", events + trace "Handle Upcall", events, state = conn.state if conn.state == Connecting: if bitand(events, SCTP_EVENT_ERROR) != 0: warn "Cannot connect", address = conn.address @@ -202,7 +200,8 @@ proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = elif bitand(events, SCTP_EVENT_WRITE) != 0: conn.state = Connected conn.connectEvent.fire() - elif bitand(events, SCTP_EVENT_READ) != 0: + + if bitand(events, SCTP_EVENT_READ) != 0: var message = SctpMessage( data: newSeq[byte](4096) @@ -253,12 +252,12 @@ proc handleAccept(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = sctp = cast[Sctp](data) sctpSocket = usrsctp_accept(sctp.sockServer, cast[ptr SockAddr](addr sconn), addr slen) - doAssert 0 == sctpSocket.usrsctp_set_non_blocking(1) let conn = cast[SctpConn](sconn.sconn_addr) conn.sctpSocket = sctpSocket conn.state = Connected var nodelay: uint32 = 1 var recvinfo: uint32 = 1 + doAssert 0 == sctpSocket.usrsctp_set_non_blocking(1) doAssert 0 == conn.sctpSocket.usrsctp_set_upcall(handleUpcall, cast[pointer](conn)) doAssert 0 == conn.sctpSocket.usrsctp_setsockopt(IPPROTO_SCTP, SCTP_NODELAY, addr nodelay, sizeof(nodelay).SockLen) @@ -266,36 +265,6 @@ proc handleAccept(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = addr recvinfo, sizeof(recvinfo).SockLen) conn.acceptEvent.fire() -# proc getOrCreateConnection(self: Sctp, -# udp: DatagramTransport, -# address: TransportAddress, -# sctpPort: uint16 = 5000): Future[SctpConn] {.async.} = -# #TODO remove the = 5000 -# if self.connections.hasKey(address): -# return self.connections[address] -# trace "Create Connection", address -# let -# sctpSocket = usrsctp_socket(AF_CONN, posix.SOCK_STREAM, IPPROTO_SCTP, nil, nil, 0, nil) -# conn = SctpConn.new(self, udp, address, sctpSocket) -# var on: int = 1 -# doAssert 0 == conn.sctpSocket.usrsctp_setsockopt(IPPROTO_SCTP, -# SCTP_RECVRCVINFO, -# addr on, -# sizeof(on).SockLen) -# doAssert 0 == usrsctp_set_non_blocking(conn.sctpSocket, 1) -# doAssert 0 == usrsctp_set_upcall(conn.sctpSocket, handleUpcall, cast[pointer](conn)) -# var sconn: Sockaddr_conn -# sconn.sconn_family = AF_CONN -# sconn.sconn_port = htons(sctpPort) -# sconn.sconn_addr = cast[pointer](self) -# self.sentConnection = conn -# self.sentAddress = address -# let connErr = self.usrsctpAwait: -# conn.sctpSocket.usrsctp_connect(cast[ptr SockAddr](addr sconn), SockLen(sizeof(sconn))) -# doAssert 0 == connErr or errno == posix.EINPROGRESS, ($errno) -# self.connections[address] = conn -# return conn - proc sendCallback(ctx: pointer, buffer: pointer, length: uint, @@ -310,6 +279,7 @@ proc sendCallback(ctx: pointer, proc testSend() {.async.} = try: trace "Send To", address = sctpConn.address + # printSctpPacket(buf) # TODO: defined it printSctpPacket(buf) await sctpConn.conn.write(buf) except CatchableError as exc: @@ -343,43 +313,6 @@ proc new*(T: typedesc[Sctp], dtls: Dtls, laddr: TransportAddress): T = usrsctp_register_address(cast[pointer](sctp)) return sctp -#proc new*(T: typedesc[Sctp], port: uint16 = 9899): T = -# logScope: topics = "webrtc sctp" -# let sctp = T(gotConnection: newAsyncEvent()) -# proc onReceive(udp: DatagramTransport, raddr: TransportAddress) {.async, gcsafe.} = -# let -# msg = udp.getMessage() -# data = usrsctp_dumppacket(unsafeAddr msg[0], uint(msg.len), SCTP_DUMP_INBOUND) -# if data != nil: -# if sctp.isServer: -# trace "onReceive (server)", data = data.packetPretty(), length = msg.len(), raddr -# else: -# trace "onReceive (client)", data = data.packetPretty(), length = msg.len(), raddr -# usrsctp_freedumpbuffer(data) -# -# if sctp.isServer: -# sctp.sentAddress = raddr -# usrsctp_conninput(cast[pointer](sctp), unsafeAddr msg[0], uint(msg.len), 0) -# else: -# let conn = await sctp.getOrCreateConnection(udp, raddr) -# sctp.sentConnection = conn -# sctp.sentAddress = raddr -# usrsctp_conninput(cast[pointer](sctp), unsafeAddr msg[0], uint(msg.len), 0) -# let -# localAddr = TransportAddress(family: AddressFamily.IPv4, port: Port(port)) -# laddr = initTAddress("127.0.0.1:" & $port) -# udp = newDatagramTransport(onReceive, local = laddr) -# trace "local address", localAddr, laddr -# sctp.udp = udp -# sctp.timersHandler = timersHandler() -# -# usrsctp_init_nothreads(port, sendCallback, printf) -# discard usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_NONE) -# discard usrsctp_sysctl_set_sctp_ecn_enable(1) -# usrsctp_register_address(cast[pointer](sctp)) -# -# return sctp - proc stop*(self: Sctp) {.async.} = discard self.usrsctpAwait usrsctp_finish() self.udp.close() @@ -392,7 +325,7 @@ proc readLoopProc(res: SctpConn) {.async.} = if not data.isNil(): trace "Receive data", remoteAddress = res.conn.raddr, data = data.packetPretty() usrsctp_freedumpbuffer(data) - res.sctp.sentConnection = res + # printSctpPacket(msg) TODO: defined it usrsctp_conninput(cast[pointer](res), unsafeAddr msg[0], uint(msg.len), 0) proc accept*(self: Sctp): Future[SctpConn] {.async.} = @@ -431,19 +364,32 @@ proc connect*(self: Sctp, sctpPort: uint16 = 5000): Future[SctpConn] {.async.} = let sctpSocket = usrsctp_socket(AF_CONN, posix.SOCK_STREAM, IPPROTO_SCTP, nil, nil, 0, nil) - res = SctpConn.new(await self.dtls.connect(address), self) + conn = SctpConn.new(await self.dtls.connect(address), self) - #usrsctp_register_address(cast[pointer](res)) - -# trace "Connect", address, sctpPort -# let conn = await self.getOrCreateConnection(self.udp, address, sctpPort) -# if conn.state == Connected: -# return conn -# try: -# await conn.connectEvent.wait() # TODO: clear? -# except CancelledError as exc: -# conn.sctpSocket.usrsctp_close() -# return nil -# if conn.state != Connected: -# raise newSctpError("Cannot connect to " & $address) -# return conn + trace "Create Connection", address + conn.sctpSocket = sctpSocket + conn.state = Connected + var nodelay: uint32 = 1 + var recvinfo: uint32 = 1 + doAssert 0 == usrsctp_set_non_blocking(conn.sctpSocket, 1) + doAssert 0 == usrsctp_set_upcall(conn.sctpSocket, handleUpcall, cast[pointer](conn)) + doAssert 0 == conn.sctpSocket.usrsctp_setsockopt(IPPROTO_SCTP, SCTP_NODELAY, + addr nodelay, sizeof(nodelay).SockLen) + doAssert 0 == conn.sctpSocket.usrsctp_setsockopt(IPPROTO_SCTP, SCTP_RECVRCVINFO, + addr recvinfo, sizeof(recvinfo).SockLen) + var sconn: Sockaddr_conn + sconn.sconn_family = AF_CONN + sconn.sconn_port = htons(sctpPort) + sconn.sconn_addr = cast[pointer](conn) + self.sentAddress = address + usrsctp_register_address(cast[pointer](conn)) + conn.readLoop = conn.readLoopProc() + let connErr = self.usrsctpAwait: + conn.sctpSocket.usrsctp_connect(cast[ptr SockAddr](addr sconn), SockLen(sizeof(sconn))) + doAssert 0 == connErr or errno == posix.EINPROGRESS, ($errno) + conn.state = Connecting + conn.connectEvent.clear() + await conn.connectEvent.wait() + # TODO: check connection state, if closed throw some exception I guess + self.connections[address] = conn + return conn diff --git a/webrtc/udp_connection.nim b/webrtc/udp_connection.nim index 8c873f7..cfec28d 100644 --- a/webrtc/udp_connection.nim +++ b/webrtc/udp_connection.nim @@ -24,7 +24,7 @@ proc init*(self: UdpConn, laddr: TransportAddress) = proc onReceive(udp: DatagramTransport, address: TransportAddress) {.async, gcsafe.} = let msg = udp.getMessage() - echo "\e[33m\e[0;1m onReceive\e[0m" + trace "UDP onReceive", msg self.dataRecv.addLastNoWait((msg, address)) self.dataRecv = newAsyncQueue[(seq[byte], TransportAddress)]() @@ -34,9 +34,9 @@ proc close*(self: UdpConn) {.async.} = self.udp.close() proc write*(self: UdpConn, raddr: TransportAddress, msg: seq[byte]) {.async.} = - echo "\e[33m\e[0;1m write\e[0m" + trace "UDP write", msg await self.udp.sendTo(raddr, msg) proc read*(self: UdpConn): Future[(seq[byte], TransportAddress)] {.async.} = - echo "\e[33m\e[0;1m read\e[0m" + trace "UDP read" return await self.dataRecv.popFirst() From 6ccad5732da813b289dbf7f9745a1e6673d429f8 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Wed, 28 Feb 2024 14:06:51 +0100 Subject: [PATCH 58/66] add a todo to usrsctp_accept return check --- webrtc/sctp.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index 8cd5f41..e0b952d 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -250,6 +250,7 @@ proc handleAccept(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = slen: Socklen = sizeof(Sockaddr_conn).uint32 let sctp = cast[Sctp](data) + # TODO: check if sctpSocket != nil sctpSocket = usrsctp_accept(sctp.sockServer, cast[ptr SockAddr](addr sconn), addr slen) let conn = cast[SctpConn](sconn.sconn_addr) From e377262919039edb7b268cef1b8e1e5d20df2dee Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Thu, 29 Feb 2024 15:15:55 +0100 Subject: [PATCH 59/66] Stun comments --- README.md | 28 ++++++++++++ webrtc/stun/stun_attributes.nim | 76 ++++++++++++++++++++++++++++----- webrtc/stun/stun_connection.nim | 1 - webrtc/utils.nim | 46 -------------------- 4 files changed, 94 insertions(+), 57 deletions(-) create mode 100644 README.md delete mode 100644 webrtc/utils.nim diff --git a/README.md b/README.md new file mode 100644 index 0000000..23aed32 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# Nim-Webrtc + +![Stability: experimental](https://img.shields.io/badge/stability-experimental-orange.svg) +[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) +[![License: Apache](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) + +A simple WebRTC stack first implemented for [libp2p WebRTC direct transport](https://github.com/libp2p/specs/blob/master/webrtc/webrtc-direct.md). +It uses a wrapper from two different C libraries: + - [usrsctp]() for the SCTP stack + - [mbedtls]() for the DTLS stack + +## Usage + +## Installation + +## TODO + +## License + +Licensed and distributed under either of + +* MIT license: [LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT + +or + +* Apache License, Version 2.0, ([LICENSE-APACHEv2](LICENSE-APACHEv2) or http://www.apache.org/licenses/LICENSE-2.0) + +at your option. This file may not be copied, modified, or distributed except according to those terms. diff --git a/webrtc/stun/stun_attributes.nim b/webrtc/stun/stun_attributes.nim index bb8ebd2..eaffc82 100644 --- a/webrtc/stun/stun_attributes.nim +++ b/webrtc/stun/stun_attributes.nim @@ -7,14 +7,61 @@ # This file may not be copied, modified, or distributed except according to # those terms. -import sequtils, typetraits +import std/sha1, sequtils, typetraits, std/md5 import binary_serialization, stew/byteutils, chronos import ../utils -type - StunAttributeEncodingError* = object of CatchableError +# -- Utils -- + +proc createCrc32Table(): array[0..255, uint32] = + for i in 0..255: + var rem = i.uint32 + for j in 0..7: + if (rem and 1) > 0: + rem = (rem shr 1) xor 0xedb88320'u32 + else: + rem = rem shr 1 + result[i] = rem + +proc crc32(s: seq[byte]): uint32 = + # CRC-32 is used for the fingerprint attribute + # See https://datatracker.ietf.org/doc/html/rfc5389#section-15.5 + const crc32table = createCrc32Table() + result = 0xffffffff'u32 + for c in s: + result = (result shr 8) xor crc32table[(result and 0xff) xor c] + result = not result + +proc hmacSha1(key: seq[byte], msg: seq[byte]): seq[byte] = + # HMAC-SHA1 is used for the message integrity attribute + # See https://datatracker.ietf.org/doc/html/rfc5389#section-15.4 + let + keyPadded = + if len(key) > 64: + @(secureHash(key.mapIt(it.chr)).distinctBase) + elif key.len() < 64: + key.concat(newSeq[byte](64 - key.len())) + else: + key + innerHash = keyPadded. + mapIt(it xor 0x36'u8). + concat(msg). + mapIt(it.chr). + secureHash() + outerHash = keyPadded. + mapIt(it xor 0x5c'u8). + concat(@(innerHash.distinctBase)). + mapIt(it.chr). + secureHash() + return @(outerHash.distinctBase) + +# -- Attributes -- +# There are obviously some attributes implementation that are missing, +# it might be something to do eventually if we want to make this +# repository work for other project than nim-libp2p +# # Stun Attribute # 0 1 2 3 # 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 @@ -23,6 +70,10 @@ type # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ # | Value (variable) .... # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +type + StunAttributeEncodingError* = object of CatchableError + RawStunAttribute* = object attributeType*: uint16 length* {.bin_value: it.value.len.}: uint16 @@ -74,6 +125,8 @@ proc isRequired*(typ: uint16): bool = typ <= 0x7FFF'u16 proc isOptional*(typ: uint16): bool = typ >= 0x8000'u16 # Error Code +# https://datatracker.ietf.org/doc/html/rfc5389#section-15.6 + type ErrorCodeEnum* = enum ECTryAlternate = 300 @@ -100,6 +153,8 @@ proc encode*(T: typedesc[ErrorCode], code: ErrorCodeEnum, reason: string = ""): value: value) # Unknown Attribute +# https://datatracker.ietf.org/doc/html/rfc5389#section-15.9 + type UnknownAttribute* = object unknownAttr: seq[uint16] @@ -113,6 +168,7 @@ proc encode*(T: typedesc[UnknownAttribute], unknownAttr: seq[uint16]): RawStunAt value: value) # Fingerprint +# https://datatracker.ietf.org/doc/html/rfc5389#section-15.5 type Fingerprint* = object @@ -125,6 +181,7 @@ proc encode*(T: typedesc[Fingerprint], msg: seq[byte]): RawStunAttribute = value: value) # Xor Mapped Address +# https://datatracker.ietf.org/doc/html/rfc5389#section-15.2 type MappedAddressFamily {.size: 1.} = enum @@ -141,26 +198,26 @@ proc encode*(T: typedesc[XorMappedAddress], ta: TransportAddress, tid: array[12, byte]): RawStunAttribute = const magicCookie = @[ 0x21'u8, 0x12, 0xa4, 0x42 ] let - address = + (address, family) = if ta.family == AddressFamily.IPv4: var s = newSeq[uint8](4) for i in 0..3: s[i] = ta.address_v4[i] xor magicCookie[i] - s + (s, MAFIPv4) else: let magicCookieTid = magicCookie.concat(@tid) var s = newSeq[uint8](16) for i in 0..15: s[i] = ta.address_v6[i] xor magicCookieTid[i] - s - xma = T(family: if ta.family == AddressFamily.IPv4: MAFIPv4 else: MAFIPv6, - port: ta.port.distinctBase xor 0x2112'u16, address: address) + (s, MAFIPv6) + xma = T(family: family, port: ta.port.distinctBase xor 0x2112'u16, address: address) value = Binary.encode(xma) result = RawStunAttribute(attributeType: AttrXORMappedAddress.uint16, length: value.len().uint16, value: value) # Message Integrity +# https://datatracker.ietf.org/doc/html/rfc5389#section-15.4 type MessageIntegrity* = object @@ -169,5 +226,4 @@ type proc encode*(T: typedesc[MessageIntegrity], msg: seq[byte], key: seq[byte]): RawStunAttribute = let value = Binary.encode(T(msgInt: hmacSha1(key, msg))) result = RawStunAttribute(attributeType: AttrMessageIntegrity.uint16, - length: value.len().uint16, - value: value) + length: value.len().uint16, value: value) diff --git a/webrtc/stun/stun_connection.nim b/webrtc/stun/stun_connection.nim index b906f09..26913bb 100644 --- a/webrtc/stun/stun_connection.nim +++ b/webrtc/stun/stun_connection.nim @@ -21,7 +21,6 @@ proc handles(self: StunConn) {.async.} = while true: # TODO: while not self.conn.atEof() let (msg, raddr) = await self.conn.read() if Stun.isMessage(msg): - echo "\e[35;1m\e[0m" let res = Stun.getResponse(msg, self.laddr) if res.isSome(): await self.conn.write(raddr, res.get()) diff --git a/webrtc/utils.nim b/webrtc/utils.nim deleted file mode 100644 index 1e0ddf2..0000000 --- a/webrtc/utils.nim +++ /dev/null @@ -1,46 +0,0 @@ -# Nim-WebRTC -# Copyright (c) 2023 Status Research & Development GmbH -# Licensed under either of -# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) -# * MIT license ([LICENSE-MIT](LICENSE-MIT)) -# at your option. -# This file may not be copied, modified, or distributed except according to -# those terms. - -import std/sha1, sequtils, typetraits, std/md5 - -proc createCrc32Table(): array[0..255, uint32] = - for i in 0..255: - var rem = i.uint32 - for j in 0..7: - if (rem and 1) > 0: rem = (rem shr 1) xor 0xedb88320'u32 - else: rem = rem shr 1 - result[i] = rem - -proc crc32*(s: seq[byte]): uint32 = - const crc32table = createCrc32Table() - result = 0xffffffff'u32 - for c in s: - result = (result shr 8) xor crc32table[(result and 0xff) xor c] - result = not result - -proc hmacSha1*(key: seq[byte], msg: seq[byte]): seq[byte] = - let - keyPadded = - if len(key) > 64: - @(secureHash(key.mapIt(it.chr)).distinctBase) - elif key.len() < 64: - key.concat(newSeq[byte](64 - key.len())) - else: - key - innerHash = keyPadded. - mapIt(it xor 0x36'u8). - concat(msg). - mapIt(it.chr). - secureHash() - outerHash = keyPadded. - mapIt(it xor 0x5c'u8). - concat(@(innerHash.distinctBase)). - mapIt(it.chr). - secureHash() - return @(outerHash.distinctBase) From 1f98fae1af2bc51c241a93612c7462439bb84bcb Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Thu, 29 Feb 2024 16:55:48 +0100 Subject: [PATCH 60/66] Udp comments --- webrtc/stun/stun_connection.nim | 2 +- webrtc/udp_connection.nim | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/webrtc/stun/stun_connection.nim b/webrtc/stun/stun_connection.nim index 26913bb..6a60141 100644 --- a/webrtc/stun/stun_connection.nim +++ b/webrtc/stun/stun_connection.nim @@ -18,7 +18,7 @@ type handlesFut: Future[void] proc handles(self: StunConn) {.async.} = - while true: # TODO: while not self.conn.atEof() + while true: let (msg, raddr) = await self.conn.read() if Stun.isMessage(msg): let res = Stun.getResponse(msg, self.laddr) diff --git a/webrtc/udp_connection.nim b/webrtc/udp_connection.nim index cfec28d..0f0e2e6 100644 --- a/webrtc/udp_connection.nim +++ b/webrtc/udp_connection.nim @@ -13,30 +13,46 @@ import chronos, chronicles logScope: topics = "webrtc udp" +# UdpConn is a small wrapper of the chronos DatagramTransport. +# It's the simplest solution we found to store the message and +# the remote address used by the underlying protocols (dtls/sctp etc...) + type UdpConn* = ref object laddr*: TransportAddress udp: DatagramTransport dataRecv: AsyncQueue[(seq[byte], TransportAddress)] + closed: bool proc init*(self: UdpConn, laddr: TransportAddress) = self.laddr = laddr + self.closed = false proc onReceive(udp: DatagramTransport, address: TransportAddress) {.async, gcsafe.} = + trace "UDP onReceive" let msg = udp.getMessage() - trace "UDP onReceive", msg self.dataRecv.addLastNoWait((msg, address)) self.dataRecv = newAsyncQueue[(seq[byte], TransportAddress)]() self.udp = newDatagramTransport(onReceive, local = laddr) proc close*(self: UdpConn) {.async.} = + if self.closed: + debug "Try to close UdpConn twice" + return + self.closed = true self.udp.close() proc write*(self: UdpConn, raddr: TransportAddress, msg: seq[byte]) {.async.} = + if self.closed: + debug "Try to write on an already closed UdpConn" + return trace "UDP write", msg await self.udp.sendTo(raddr, msg) proc read*(self: UdpConn): Future[(seq[byte], TransportAddress)] {.async.} = + if self.closed: + debug "Try to read on an already closed UdpConn" + return trace "UDP read" return await self.dataRecv.popFirst() From 4c1eb13926f94eab4514c735ef315842ff4e664f Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 1 Mar 2024 12:11:04 +0100 Subject: [PATCH 61/66] StunConn adds debug --- webrtc/stun/stun_connection.nim | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/webrtc/stun/stun_connection.nim b/webrtc/stun/stun_connection.nim index 6a60141..68d1105 100644 --- a/webrtc/stun/stun_connection.nim +++ b/webrtc/stun/stun_connection.nim @@ -7,15 +7,21 @@ # This file may not be copied, modified, or distributed except according to # those terms. -import chronos +import chronos, chronicles import ../udp_connection, stun +logScope: + topics = "webrtc stun" + +# TODO: Work fine when behaves like a server, need to implement the client side + type StunConn* = ref object conn: UdpConn laddr: TransportAddress dataRecv: AsyncQueue[(seq[byte], TransportAddress)] handlesFut: Future[void] + closed: bool proc handles(self: StunConn) {.async.} = while true: @@ -30,16 +36,26 @@ proc handles(self: StunConn) {.async.} = proc init*(self: StunConn, conn: UdpConn, laddr: TransportAddress) = self.conn = conn self.laddr = laddr + self.closed = false self.dataRecv = newAsyncQueue[(seq[byte], TransportAddress)]() self.handlesFut = self.handles() proc close*(self: StunConn) {.async.} = + if self.closed: + debug "Try to close StunConn twice" + return self.handlesFut.cancel() # check before? await self.conn.close() proc write*(self: StunConn, raddr: TransportAddress, msg: seq[byte]) {.async.} = + if self.closed: + debug "Try to write on an already closed StunConn" + return await self.conn.write(raddr, msg) proc read*(self: StunConn): Future[(seq[byte], TransportAddress)] {.async.} = + if self.closed: + debug "Try to read on an already closed StunConn" + return return await self.dataRecv.popFirst() From 359a81df4a408bfbcef4f548d594b6449490e6e5 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Fri, 1 Mar 2024 13:49:05 +0100 Subject: [PATCH 62/66] Dtls comments + close + minor improvements --- examples/ping.nim | 23 ++++ examples/pong.nim | 2 +- webrtc/dtls/dtls.nim | 200 +++++++++++++++++++++----------- webrtc/stun/stun_attributes.nim | 1 - webrtc/webrtc.nim | 4 +- 5 files changed, 162 insertions(+), 68 deletions(-) create mode 100644 examples/ping.nim diff --git a/examples/ping.nim b/examples/ping.nim new file mode 100644 index 0000000..70c9f01 --- /dev/null +++ b/examples/ping.nim @@ -0,0 +1,23 @@ +import chronos, stew/byteutils +import ../webrtc/udp_connection +import ../webrtc/stun/stun_connection +import ../webrtc/dtls/dtls +import ../webrtc/sctp + +proc main() {.async.} = + let laddr = initTAddress("127.0.0.1:4244") + let udp = UdpConn() + udp.init(laddr) + let stun = StunConn() + stun.init(udp, laddr) + let dtls = Dtls() + dtls.init(stun, laddr) + let sctp = Sctp.new(dtls, laddr) + let conn = await sctp.connect(initTAddress("127.0.0.1:4242"), sctpPort = 13) + while true: + await conn.write("ping".toBytes) + let msg = await conn.read() + echo "Received: ", string.fromBytes(msg.data) + await sleepAsync(1.seconds) + +waitFor(main()) diff --git a/examples/pong.nim b/examples/pong.nim index 69abf57..e881585 100644 --- a/examples/pong.nim +++ b/examples/pong.nim @@ -19,7 +19,7 @@ proc main() {.async.} = let stun = StunConn() stun.init(udp, laddr) let dtls = Dtls() - dtls.start(stun, laddr) + dtls.init(stun, laddr) let sctp = Sctp.new(dtls, laddr) sctp.listen(13) while true: diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 808a5f1..5d858fb 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -7,7 +7,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -import times, deques, tables +import times, deques, tables, sequtils import chronos, chronicles import ./utils, ../stun/stun_connection @@ -29,11 +29,22 @@ import mbedtls/timing logScope: topics = "webrtc dtls" -# TODO: Check the viability of the add/pop first/last of the asyncqueue with the limit. -# There might be some errors (or crashes) in weird cases with the no wait option +# Implementation of a DTLS client and a DTLS Server by using the mbedtls library. +# Multiple things here are unintuitive partly because of the callbacks +# used by mbedtls and that those callbacks cannot be async. +# +# TODO: +# - Check the viability of the add/pop first/last of the asyncqueue with the limit. +# There might be some errors (or crashes) with some edge cases with the no wait option +# - Not critical - Check how to make a better use of MBEDTLS_ERR_SSL_WANT_WRITE +# - Not critical - May be interesting to split Dtls and DtlsConn into two files -const - PendingHandshakeLimit = 1024 +# This limit is arbitrary, it could be interesting to make it configurable. +const PendingHandshakeLimit = 1024 + +# -- DtlsConn -- +# A Dtls connection to a specific IP address recovered by the receiving part of +# the Udp "connection" type DtlsError* = object of CatchableError @@ -43,6 +54,8 @@ type raddr*: TransportAddress dataRecv: AsyncQueue[seq[byte]] sendFuture: Future[void] + closed: bool + closeEvent: AsyncEvent timer: mbedtls_timing_delay_context @@ -57,55 +70,99 @@ type localCert: seq[byte] remoteCert: seq[byte] -proc dtlsSend*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = - var self = cast[DtlsConn](ctx) - var toWrite = newSeq[byte](len) - if len > 0: - copyMem(addr toWrite[0], buf, len) - trace "dtls send", len - self.sendFuture = self.conn.write(self.raddr, toWrite) - result = len.cint - -proc dtlsRecv*(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = - let self = cast[DtlsConn](ctx) - if self.dataRecv.len() == 0: - return MBEDTLS_ERR_SSL_WANT_READ - - var dataRecv = self.dataRecv.popFirstNoWait() - copyMem(buf, addr dataRecv[0], dataRecv.len()) - result = dataRecv.len().cint - trace "dtls receive", len, result - -proc init*(self: DtlsConn, conn: StunConn, laddr: TransportAddress) {.async.} = +proc init(self: DtlsConn, conn: StunConn, laddr: TransportAddress) = self.conn = conn self.laddr = laddr self.dataRecv = newAsyncQueue[seq[byte]]() + self.closed = false + self.closeEvent = newAsyncEvent() + +proc join(self: DtlsConn) {.async.} = + await self.closeEvent.wait() + +proc dtlsHandshake(self: DtlsConn, isServer: bool) {.async.} = + var shouldRead = isServer + while self.ssl.private_state != MBEDTLS_SSL_HANDSHAKE_OVER: + if shouldRead: + if isServer: + case self.raddr.family + of AddressFamily.IPv4: + mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v4) + of AddressFamily.IPv6: + mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v6) + else: + raise newException(DtlsError, "Remote address isn't an IP address") + let tmp = await self.dataRecv.popFirst() + self.dataRecv.addFirstNoWait(tmp) + self.sendFuture = nil + let res = mb_ssl_handshake_step(self.ssl) + if not self.sendFuture.isNil(): + await self.sendFuture + shouldRead = false + if res == MBEDTLS_ERR_SSL_WANT_WRITE: + continue + elif res == MBEDTLS_ERR_SSL_WANT_READ: + shouldRead = true + continue + elif res == MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED: + mb_ssl_session_reset(self.ssl) + shouldRead = isServer + continue + elif res != 0: + raise newException(DtlsError, $(res.mbedtls_high_level_strerr())) + +proc close*(self: DtlsConn) {.async.} = + if self.closed: + debug "Try to close DtlsConn twice" + return + + self.closed = true + self.sendFuture = nil + # TODO: proc mbedtls_ssl_close_notify => template mb_ssl_close_notify in nim-mbedtls + let x = mbedtls_ssl_close_notify(addr self.ssl) + if not self.sendFuture.isNil(): + await self.sendFuture + self.closeEvent.fire() proc write*(self: DtlsConn, msg: seq[byte]) {.async.} = + if self.closed: + debug "Try to write on an already closed DtlsConn" + return var buf = msg try: + let sendFuture = newFuture[void]("DtlsConn write") + self.sendFuture = nil let write = mb_ssl_write(self.ssl, buf) + if not self.sendFuture.isNil(): + await self.sendFuture trace "Dtls write", msgLen = msg.len(), actuallyWrote = write except MbedTLSError as exc: trace "Dtls write error", errorMsg = exc.msg raise exc proc read*(self: DtlsConn): Future[seq[byte]] {.async.} = + if self.closed: + debug "Try to read on an already closed DtlsConn" + return var res = newSeq[byte](8192) while true: let tmp = await self.dataRecv.popFirst() self.dataRecv.addFirstNoWait(tmp) - # TODO: exception catching - let length = mb_ssl_read(self.ssl, res) + # TODO: Find a clear way to use the template `mb_ssl_read` without + # messing up things with exception + let length = mbedtls_ssl_read(addr self.ssl, cast[ptr byte](addr res[0]), res.len().uint) if length == MBEDTLS_ERR_SSL_WANT_READ: continue if length < 0: - trace "dtls read", error = $(length.cint.mbedtls_high_level_strerr()) + raise newException(DtlsError, $(length.cint.mbedtls_high_level_strerr())) res.setLen(length) return res -proc close*(self: DtlsConn) {.async.} = - discard +# -- Dtls -- +# The Dtls object read every messages from the UdpConn/StunConn and, if the address +# is not yet stored in the Table `Connection`, adds it to the `pendingHandshake` queue +# to be accepted later, if the address is stored, add the message received to the +# corresponding DtlsConn `dataRecv` queue. type Dtls* = ref object of RootObj @@ -130,7 +187,7 @@ proc updateOrAdd(aq: AsyncQueue[(TransportAddress, seq[byte])], return aq.addLastNoWait((raddr, buf)) -proc start*(self: Dtls, conn: StunConn, laddr: TransportAddress) = +proc init*(self: Dtls, conn: StunConn, laddr: TransportAddress) = if self.started: warn "Already started" return @@ -159,43 +216,16 @@ proc start*(self: Dtls, conn: StunConn, laddr: TransportAddress) = self.localCert = newSeq[byte](self.serverCert.raw.len) copyMem(addr self.localCert[0], self.serverCert.raw.p, self.serverCert.raw.len) -proc stop*(self: Dtls) = +proc stop*(self: Dtls) {.async.} = if not self.started: warn "Already stopped" return + await allFutures(toSeq(self.connections.values()).mapIt(it.close())) self.readLoop.cancel() self.started = false -proc dtlsHandshake(self: DtlsConn, isServer: bool) {.async.} = - var shouldRead = isServer - while self.ssl.private_state != MBEDTLS_SSL_HANDSHAKE_OVER: - if shouldRead: - if isServer: - case self.raddr.family - of AddressFamily.IPv4: - mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v4) - of AddressFamily.IPv6: - mb_ssl_set_client_transport_id(self.ssl, self.raddr.address_v6) - else: - raise newException(DtlsError, "Remote address isn't an IP address") - let tmp = await self.dataRecv.popFirst() - self.dataRecv.addFirstNoWait(tmp) - self.sendFuture = nil - let res = mb_ssl_handshake_step(self.ssl) - if not self.sendFuture.isNil(): await self.sendFuture - shouldRead = false - if res == MBEDTLS_ERR_SSL_WANT_WRITE: - continue - elif res == MBEDTLS_ERR_SSL_WANT_READ: - shouldRead = true - continue - elif res == MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED: - mb_ssl_session_reset(self.ssl) - shouldRead = true - continue - elif res != 0: - raise newException(DtlsError, $(res.mbedtls_high_level_strerr())) +# -- Remote / Local certificate getter -- proc remoteCertificate*(conn: DtlsConn): seq[byte] = conn.remoteCert @@ -206,8 +236,14 @@ proc localCertificate*(conn: DtlsConn): seq[byte] = proc localCertificate*(self: Dtls): seq[byte] = self.localCert +# -- MbedTLS Callbacks -- + proc verify(ctx: pointer, pcert: ptr mbedtls_x509_crt, state: cint, pflags: ptr uint32): cint {.cdecl.} = + # verify is the procedure called by mbedtls when receiving the remote + # certificate. It's usually used to verify the validity of the certificate. + # We use this procedure to store the remote certificate as it's mandatory + # to have it for the Prologue of the Noise protocol, aswell as the localCertificate. var self = cast[DtlsConn](ctx) let cert = pcert[] @@ -215,12 +251,45 @@ proc verify(ctx: pointer, pcert: ptr mbedtls_x509_crt, copyMem(addr self.remoteCert[0], cert.raw.p, cert.raw.len) return 0 +proc dtlsSend(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = + # dtlsSend is the procedure called by mbedtls when data needs to be sent. + # As the StunConn's write proc is asynchronous and dtlsSend cannot be async, + # we store the future of this write and await it after the end of the + # function (see write or dtlsHanshake for example). + var self = cast[DtlsConn](ctx) + var toWrite = newSeq[byte](len) + if len > 0: + copyMem(addr toWrite[0], buf, len) + trace "dtls send", len + self.sendFuture = self.conn.write(self.raddr, toWrite) + result = len.cint + +proc dtlsRecv(ctx: pointer, buf: ptr byte, len: uint): cint {.cdecl.} = + # dtlsRecv is the procedure called by mbedtls when data needs to be received. + # As we cannot asynchronously await for data to be received, we use a data received + # queue. If this queue is empty, we return `MBEDTLS_ERR_SSL_WANT_READ` for us to await + # when the mbedtls proc resumed (see read or dtlsHandshake for example) + let self = cast[DtlsConn](ctx) + if self.dataRecv.len() == 0: + return MBEDTLS_ERR_SSL_WANT_READ + + var dataRecv = self.dataRecv.popFirstNoWait() + copyMem(buf, addr dataRecv[0], dataRecv.len()) + result = dataRecv.len().cint + trace "dtls receive", len, result + +# -- Dtls Accept / Connect procedures -- + +proc removeConnection(self: Dtls, conn: DtlsConn, raddr: TransportAddress) {.async.} = + await conn.join() + self.connections.del(raddr) + proc accept*(self: Dtls): Future[DtlsConn] {.async.} = var selfvar = self res = DtlsConn() - await res.init(self.conn, self.laddr) + res.init(self.conn, self.laddr) mb_ssl_init(res.ssl) mb_ssl_config_init(res.config) mb_ssl_cookie_init(res.cookie) @@ -248,8 +317,7 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} = mb_ssl_session_reset(res.ssl) mb_ssl_set_verify(res.ssl, verify, res) mb_ssl_conf_authmode(res.config, MBEDTLS_SSL_VERIFY_OPTIONAL) - mb_ssl_set_bio(res.ssl, cast[pointer](res), - dtlsSend, dtlsRecv, nil) + mb_ssl_set_bio(res.ssl, cast[pointer](res), dtlsSend, dtlsRecv, nil) while true: let (raddr, buf) = await self.pendingHandshakes.popFirst() try: @@ -257,6 +325,7 @@ proc accept*(self: Dtls): Future[DtlsConn] {.async.} = res.dataRecv.addLastNoWait(buf) self.connections[raddr] = res await res.dtlsHandshake(true) + asyncSpawn self.removeConnection(res, raddr) break except CatchableError as exc: trace "Handshake fail", remoteAddress = raddr, error = exc.msg @@ -269,7 +338,7 @@ proc connect*(self: Dtls, raddr: TransportAddress): Future[DtlsConn] {.async.} = selfvar = self res = DtlsConn() - await res.init(self.conn, self.laddr) + res.init(self.conn, self.laddr) mb_ssl_init(res.ssl) mb_ssl_config_init(res.config) @@ -303,6 +372,7 @@ proc connect*(self: Dtls, raddr: TransportAddress): Future[DtlsConn] {.async.} = try: await res.dtlsHandshake(false) + asyncSpawn self.removeConnection(res, raddr) except CatchableError as exc: trace "Handshake fail", remoteAddress = raddr, error = exc.msg self.connections.del(raddr) diff --git a/webrtc/stun/stun_attributes.nim b/webrtc/stun/stun_attributes.nim index eaffc82..bd6179f 100644 --- a/webrtc/stun/stun_attributes.nim +++ b/webrtc/stun/stun_attributes.nim @@ -11,7 +11,6 @@ import std/sha1, sequtils, typetraits, std/md5 import binary_serialization, stew/byteutils, chronos -import ../utils # -- Utils -- diff --git a/webrtc/webrtc.nim b/webrtc/webrtc.nim index 1c39eb8..d93a8b8 100644 --- a/webrtc/webrtc.nim +++ b/webrtc/webrtc.nim @@ -17,6 +17,8 @@ import sctp, datachannel logScope: topics = "webrtc" +# TODO: Implement a connect (or dial) procedure + type WebRTC* = ref object udp*: UdpConn @@ -29,7 +31,7 @@ proc new*(T: typedesc[WebRTC], address: TransportAddress): T = var webrtc = T(udp: UdpConn(), stun: StunConn(), dtls: Dtls()) webrtc.udp.init(address) webrtc.stun.init(webrtc.udp, address) - webrtc.dtls.start(webrtc.stun, address) + webrtc.dtls.init(webrtc.stun, address) webrtc.sctp = Sctp.new(webrtc.dtls, address) return webrtc From f49ca90491c8e82661017549f290701ddfde14a0 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Wed, 6 Mar 2024 13:47:32 +0100 Subject: [PATCH 63/66] Sctp comments + refacto --- webrtc/dtls/utils.nim | 10 +-- webrtc/sctp.nim | 161 ++++++++++++++++++++++-------------------- 2 files changed, 88 insertions(+), 83 deletions(-) diff --git a/webrtc/dtls/utils.nim b/webrtc/dtls/utils.nim index 6f9ad5b..ebecd40 100644 --- a/webrtc/dtls/utils.nim +++ b/webrtc/dtls/utils.nim @@ -20,6 +20,7 @@ import mbedtls/md import chronicles +# This sequence is used for debugging. const mb_ssl_states* = @[ "MBEDTLS_SSL_HELLO_REQUEST", "MBEDTLS_SSL_CLIENT_HELLO", @@ -53,14 +54,6 @@ const mb_ssl_states* = @[ "MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH" ] -proc mbedtls_pk_rsa*(pk: mbedtls_pk_context): ptr mbedtls_rsa_context = - var key = pk - case mbedtls_pk_get_type(addr key) - of MBEDTLS_PK_RSA: - return cast[ptr mbedtls_rsa_context](pk.private_pk_ctx) - else: - return nil - template generateKey*(random: mbedtls_ctr_drbg_context): mbedtls_pk_context = var res: mbedtls_pk_context mb_pk_init(res) @@ -72,6 +65,7 @@ template generateKey*(random: mbedtls_ctr_drbg_context): mbedtls_pk_context = template generateCertificate*(random: mbedtls_ctr_drbg_context, issuer_key: mbedtls_pk_context): mbedtls_x509_crt = let + # To be honest, I have no clue what to put here as a name name = "C=FR,O=Status,CN=webrtc" time_format = initTimeFormat("YYYYMMddHHmmss") time_from = times.now().format(time_format) diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index e0b952d..4d8afde 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -18,9 +18,18 @@ export chronicles logScope: topics = "webrtc sctp" +# Implementation of an Sctp client and server using the usrsctp library. +# Usrsctp is usable as a single thread but it's not the intended way to +# use it. There's a lot of callbacks calling each other in a synchronous +# way where we want to be able to call asynchronous procedure, but cannot. + # TODO: # - Replace doAssert by a proper exception management # - Find a clean way to manage SCTP ports +# - Unregister address when closing + +proc perror(error: cstring) {.importc, cdecl, header: "".} +proc printf(format: cstring) {.cdecl, importc: "printf", varargs, header: "", gcsafe.} type SctpError* = object of CatchableError @@ -67,26 +76,43 @@ type sentAddress: TransportAddress sentFuture: Future[void] - # Those two objects are only here for debugging purpose + # These three objects are used for debugging/trace only SctpChunk = object chunkType: uint8 flag: uint8 length {.bin_value: it.data.len() + 4.}: uint16 data {.bin_len: it.length - 4.}: seq[byte] - SctpPacketStructure = object + SctpPacketHeader = object srcPort: uint16 dstPort: uint16 verifTag: uint32 checksum: uint32 -const - IPPROTO_SCTP = 132 + SctpPacketStructure = object + header: SctpPacketHeader + chunks: seq[SctpChunk] -proc newSctpError(msg: string): ref SctpError = - result = newException(SctpError, msg) +const IPPROTO_SCTP = 132 + +proc getSctpPacket(buffer: seq[byte]): SctpPacketStructure = + # Only used for debugging/trace + result.header = Binary.decode(buffer, SctpPacketHeader) + var size = sizeof(SctpPacketStructure) + while size < buffer.len: + let chunk = Binary.decode(buffer[size..^1], SctpChunk) + result.chunks.add(chunk) + size.inc(chunk.length.int) + while size mod 4 != 0: + # padding; could use `size.inc(-size %% 4)` instead but it lacks clarity + size.inc(1) + +# -- Asynchronous wrapper -- template usrsctpAwait(self: SctpConn|Sctp, body: untyped): untyped = + # usrsctpAwait is template which set `sentFuture` to nil then calls (usually) + # an usrsctp function. If during the synchronous run of the usrsctp function + # `sendCallback` is called, then `sentFuture` is set and waited. self.sentFuture = nil when type(body) is void: body @@ -96,45 +122,7 @@ template usrsctpAwait(self: SctpConn|Sctp, body: untyped): untyped = if self.sentFuture != nil: await self.sentFuture res -proc perror(error: cstring) {.importc, cdecl, header: "".} -proc printf(format: cstring) {.cdecl, importc: "printf", varargs, header: "", gcsafe.} - -proc printSctpPacket(buffer: seq[byte]) = - let s = Binary.decode(buffer, SctpPacketStructure) - echo " => \e[31;1mStructure\e[0m: ", s - var size = sizeof(SctpPacketStructure) - var i = 1 - while size < buffer.len: - let c = Binary.decode(buffer[size..^1], SctpChunk) - echo " ===> \e[32;1mChunk ", i, "\e[0m ", c - i.inc() - size.inc(c.length.int) - while size mod 4 != 0: - size.inc() - -proc packetPretty(packet: cstring): string = - let data = $packet - let ctn = data[23..^16] - result = data[1..14] - if ctn.len > 30: - result = result & ctn[0..14] & " ... " & ctn[^14..^1] - else: - result = result & ctn - -proc new(T: typedesc[SctpConn], - sctp: Sctp, - udp: DatagramTransport, - address: TransportAddress, - sctpSocket: ptr socket): T = - T(sctp: sctp, - state: Connecting, - udp: udp, - address: address, - sctpSocket: sctpSocket, - connectEvent: AsyncEvent(), - #TODO add some limit for backpressure? - dataRecv: newAsyncQueue[SctpMessage]() - ) +# -- SctpConn -- proc new(T: typedesc[SctpConn], conn: DtlsConn, sctp: Sctp): T = T(conn: conn, @@ -142,10 +130,12 @@ proc new(T: typedesc[SctpConn], conn: DtlsConn, sctp: Sctp): T = state: Connecting, connectEvent: AsyncEvent(), acceptEvent: AsyncEvent(), - dataRecv: newAsyncQueue[SctpMessage]() #TODO add some limit for backpressure? + dataRecv: newAsyncQueue[SctpMessage]() # TODO add some limit for backpressure? ) proc read*(self: SctpConn): Future[SctpMessage] {.async.} = + # Used by DataChannel, returns SctpMessage in order to get the stream + # and protocol ids return await self.dataRecv.popFirst() proc toFlags(params: SctpMessageParameters): uint16 = @@ -154,23 +144,24 @@ proc toFlags(params: SctpMessageParameters): uint16 = if params.unordered: result = result or SCTP_UNORDERED -proc write*( - self: SctpConn, - buf: seq[byte], - sendParams = default(SctpMessageParameters), - ) {.async.} = - trace "Write", buf, sctp = cast[uint64](self), sock = cast[uint64](self.sctpSocket) +proc write*(self: SctpConn, buf: seq[byte], + sendParams = default(SctpMessageParameters)) {.async.} = + # Used by DataChannel, writes buf on the Dtls connection. + trace "Write", buf self.sctp.sentAddress = self.address var cpy = buf let sendvErr = if sendParams == default(SctpMessageParameters): + # If writes is called by DataChannel, sendParams should never + # be the default value. This split is useful for testing. self.usrsctpAwait: self.sctpSocket.usrsctp_sendv(cast[pointer](addr cpy[0]), cpy.len().uint, nil, 0, nil, 0, SCTP_SENDV_NOINFO.cuint, 0) else: let sendInfo = sctp_sndinfo( snd_sid: sendParams.streamId, + # TODO: swapBytes => htonl? snd_ppid: sendParams.protocolId.swapBytes(), snd_flags: sendParams.toFlags) self.usrsctpAwait: @@ -178,29 +169,26 @@ proc write*( cast[pointer](addr sendInfo), sizeof(sendInfo).SockLen, SCTP_SENDV_SNDINFO.cuint, 0) if sendvErr < 0: - perror("usrsctp_sendv") # TODO: throw an exception - trace "write sendv error?", sendvErr, sendParams + # TODO: throw an exception + perror("usrsctp_sendv") proc write*(self: SctpConn, s: string) {.async.} = await self.write(s.toBytes()) proc close*(self: SctpConn) {.async.} = - self.usrsctpAwait: self.sctpSocket.usrsctp_close() + self.usrsctpAwait: + self.sctpSocket.usrsctp_close() + +# -- usrsctp receive data callbacks -- proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = + # Callback procedure called when we receive data after + # connection has been established. let conn = cast[SctpConn](data) events = usrsctp_get_events(sock) - trace "Handle Upcall", events, state = conn.state - if conn.state == Connecting: - if bitand(events, SCTP_EVENT_ERROR) != 0: - warn "Cannot connect", address = conn.address - conn.state = Closed - elif bitand(events, SCTP_EVENT_WRITE) != 0: - conn.state = Connected - conn.connectEvent.fire() - + trace "Handle Upcall", events if bitand(events, SCTP_EVENT_READ) != 0: var message = SctpMessage( @@ -212,8 +200,8 @@ proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = rnLen = sizeof(sctp_recvv_rn).SockLen infotype: uint flags: int - trace "recv from", sockuint64=cast[uint64](sock) - let n = sock.usrsctp_recvv(cast[pointer](addr message.data[0]), message.data.len.uint, + let n = sock.usrsctp_recvv(cast[pointer](addr message.data[0]), + message.data.len.uint, cast[ptr SockAddr](addr address), cast[ptr SockLen](addr addressLen), cast[pointer](addr message.info), @@ -239,11 +227,12 @@ proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = except AsyncQueueFullError: trace "Queue full, dropping packet" elif bitand(events, SCTP_EVENT_WRITE) != 0: - trace "sctp event write in the upcall" + debug "sctp event write in the upcall" else: warn "Handle Upcall unexpected event", events proc handleAccept(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = + # Callback procedure called when accepting a connection. trace "Handle Accept" var sconn: Sockaddr_conn @@ -266,6 +255,27 @@ proc handleAccept(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = addr recvinfo, sizeof(recvinfo).SockLen) conn.acceptEvent.fire() +proc handleConnect(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = + # Callback procedure called when connecting + trace "Handle Connect" + let + conn = cast[SctpConn](data) + events = usrsctp_get_events(sock) + + trace "Handle Upcall", events, state = conn.state + if conn.state == Connecting: + if bitand(events, SCTP_EVENT_ERROR) != 0: + warn "Cannot connect", address = conn.address + conn.state = Closed + elif bitand(events, SCTP_EVENT_WRITE) != 0: + conn.state = Connected + doAssert 0 == usrsctp_set_upcall(conn.sctpSocket, handleUpcall, data) + conn.connectEvent.fire() + else: + warn "should be connecting", currentState = conn.state + +# -- usrsctp send data callback -- + proc sendCallback(ctx: pointer, buffer: pointer, length: uint, @@ -273,20 +283,20 @@ proc sendCallback(ctx: pointer, set_df: uint8): cint {.cdecl.} = let data = usrsctp_dumppacket(buffer, length, SCTP_DUMP_OUTBOUND) if data != nil: - trace "sendCallback", data = data.packetPretty(), length + trace "sendCallback", sctpPacket = data.getSctpPacket(), length usrsctp_freedumpbuffer(data) let sctpConn = cast[SctpConn](ctx) let buf = @(buffer.makeOpenArray(byte, int(length))) proc testSend() {.async.} = try: trace "Send To", address = sctpConn.address - # printSctpPacket(buf) - # TODO: defined it printSctpPacket(buf) await sctpConn.conn.write(buf) except CatchableError as exc: trace "Send Failed", message = exc.msg sctpConn.sentFuture = testSend() +# -- Sctp -- + proc timersHandler() {.async.} = while true: await sleepAsync(500.milliseconds) @@ -315,6 +325,7 @@ proc new*(T: typedesc[Sctp], dtls: Dtls, laddr: TransportAddress): T = return sctp proc stop*(self: Sctp) {.async.} = + # TODO: close every connections discard self.usrsctpAwait usrsctp_finish() self.udp.close() @@ -324,14 +335,14 @@ proc readLoopProc(res: SctpConn) {.async.} = msg = await res.conn.read() data = usrsctp_dumppacket(unsafeAddr msg[0], uint(msg.len), SCTP_DUMP_INBOUND) if not data.isNil(): - trace "Receive data", remoteAddress = res.conn.raddr, data = data.packetPretty() + trace "Receive data", remoteAddress = res.conn.raddr, + sctpPacket = data.getSctpPacket() usrsctp_freedumpbuffer(data) - # printSctpPacket(msg) TODO: defined it usrsctp_conninput(cast[pointer](res), unsafeAddr msg[0], uint(msg.len), 0) proc accept*(self: Sctp): Future[SctpConn] {.async.} = if not self.isServer: - raise newSctpError("Not a server") + raise newException(SctpError, "Not a server") var res = SctpConn.new(await self.dtls.accept(), self) usrsctp_register_address(cast[pointer](res)) res.readLoop = res.readLoopProc() @@ -373,7 +384,7 @@ proc connect*(self: Sctp, var nodelay: uint32 = 1 var recvinfo: uint32 = 1 doAssert 0 == usrsctp_set_non_blocking(conn.sctpSocket, 1) - doAssert 0 == usrsctp_set_upcall(conn.sctpSocket, handleUpcall, cast[pointer](conn)) + doAssert 0 == usrsctp_set_upcall(conn.sctpSocket, handleConnect, cast[pointer](conn)) doAssert 0 == conn.sctpSocket.usrsctp_setsockopt(IPPROTO_SCTP, SCTP_NODELAY, addr nodelay, sizeof(nodelay).SockLen) doAssert 0 == conn.sctpSocket.usrsctp_setsockopt(IPPROTO_SCTP, SCTP_RECVRCVINFO, @@ -391,6 +402,6 @@ proc connect*(self: Sctp, conn.state = Connecting conn.connectEvent.clear() await conn.connectEvent.wait() - # TODO: check connection state, if closed throw some exception I guess + # TODO: check connection state, if closed throw an exception self.connections[address] = conn return conn From 5343605c497fbed59951090b2d95ec17f1ecd0c1 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Wed, 6 Mar 2024 16:05:53 +0100 Subject: [PATCH 64/66] update header year --- webrtc/datachannel.nim | 8 ++++++-- webrtc/dtls/dtls.nim | 2 +- webrtc/dtls/utils.nim | 2 +- webrtc/sctp.nim | 2 +- webrtc/stun/stun.nim | 2 +- webrtc/stun/stun_attributes.nim | 2 +- webrtc/stun/stun_connection.nim | 2 +- webrtc/udp_connection.nim | 2 +- webrtc/webrtc.nim | 2 +- 9 files changed, 14 insertions(+), 10 deletions(-) diff --git a/webrtc/datachannel.nim b/webrtc/datachannel.nim index 56fba3a..5439cef 100644 --- a/webrtc/datachannel.nim +++ b/webrtc/datachannel.nim @@ -1,5 +1,5 @@ # Nim-WebRTC -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) @@ -20,6 +20,10 @@ export binary_serialization logScope: topics = "webrtc datachannel" +# Implementation of the DataChannel protocol, mostly following +# https://www.rfc-editor.org/rfc/rfc8831.html and +# https://www.rfc-editor.org/rfc/rfc8832.html + type DataChannelProtocolIds* {.size: 4.} = enum WebRtcDcep = 50 @@ -201,7 +205,7 @@ proc readLoop(conn: DataChannelConnection) {.async.} = try: while true: let message = await conn.conn.read() - # TODO: might be necessary to check the others protocolId at some point + # TODO: check the protocolId if message.params.protocolId == uint32(WebRtcDcep): #TODO should we really await? await conn.handleControl(message) diff --git a/webrtc/dtls/dtls.nim b/webrtc/dtls/dtls.nim index 5d858fb..b09a888 100644 --- a/webrtc/dtls/dtls.nim +++ b/webrtc/dtls/dtls.nim @@ -1,5 +1,5 @@ # Nim-WebRTC -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) diff --git a/webrtc/dtls/utils.nim b/webrtc/dtls/utils.nim index ebecd40..06fb990 100644 --- a/webrtc/dtls/utils.nim +++ b/webrtc/dtls/utils.nim @@ -1,5 +1,5 @@ # Nim-WebRTC -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index 4d8afde..313f2a7 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -1,5 +1,5 @@ # Nim-WebRTC -# Copyright (c) 2022 Status Research & Development GmbH +# Copyright (c) 2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) diff --git a/webrtc/stun/stun.nim b/webrtc/stun/stun.nim index fdd685f..3248d53 100644 --- a/webrtc/stun/stun.nim +++ b/webrtc/stun/stun.nim @@ -1,5 +1,5 @@ # Nim-WebRTC -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) diff --git a/webrtc/stun/stun_attributes.nim b/webrtc/stun/stun_attributes.nim index bd6179f..11e3c0e 100644 --- a/webrtc/stun/stun_attributes.nim +++ b/webrtc/stun/stun_attributes.nim @@ -1,5 +1,5 @@ # Nim-WebRTC -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) diff --git a/webrtc/stun/stun_connection.nim b/webrtc/stun/stun_connection.nim index 68d1105..a7289ec 100644 --- a/webrtc/stun/stun_connection.nim +++ b/webrtc/stun/stun_connection.nim @@ -1,5 +1,5 @@ # Nim-WebRTC -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) diff --git a/webrtc/udp_connection.nim b/webrtc/udp_connection.nim index 0f0e2e6..a096231 100644 --- a/webrtc/udp_connection.nim +++ b/webrtc/udp_connection.nim @@ -1,5 +1,5 @@ # Nim-WebRTC -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) diff --git a/webrtc/webrtc.nim b/webrtc/webrtc.nim index d93a8b8..57b1d2f 100644 --- a/webrtc/webrtc.nim +++ b/webrtc/webrtc.nim @@ -1,5 +1,5 @@ # Nim-WebRTC -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) From b1f8d71f71ab17b38866579a4221d53092f79498 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Wed, 6 Mar 2024 16:17:09 +0100 Subject: [PATCH 65/66] harmonize sctp new/init --- examples/ping.nim | 3 ++- examples/pong.nim | 3 ++- webrtc/sctp.nim | 13 ++++++------- webrtc/webrtc.nim | 21 +++++++++++---------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/examples/ping.nim b/examples/ping.nim index 70c9f01..ea11c12 100644 --- a/examples/ping.nim +++ b/examples/ping.nim @@ -12,7 +12,8 @@ proc main() {.async.} = stun.init(udp, laddr) let dtls = Dtls() dtls.init(stun, laddr) - let sctp = Sctp.new(dtls, laddr) + let sctp = Sctp() + sctp.init(dtls, laddr) let conn = await sctp.connect(initTAddress("127.0.0.1:4242"), sctpPort = 13) while true: await conn.write("ping".toBytes) diff --git a/examples/pong.nim b/examples/pong.nim index e881585..b614b59 100644 --- a/examples/pong.nim +++ b/examples/pong.nim @@ -20,7 +20,8 @@ proc main() {.async.} = stun.init(udp, laddr) let dtls = Dtls() dtls.init(stun, laddr) - let sctp = Sctp.new(dtls, laddr) + let sctp = Sctp() + sctp.init(dtls, laddr) sctp.listen(13) while true: let conn = await sctp.accept() diff --git a/webrtc/sctp.nim b/webrtc/sctp.nim index 313f2a7..31a4b8b 100644 --- a/webrtc/sctp.nim +++ b/webrtc/sctp.nim @@ -227,7 +227,7 @@ proc handleUpcall(sock: ptr socket, data: pointer, flags: cint) {.cdecl.} = except AsyncQueueFullError: trace "Queue full, dropping packet" elif bitand(events, SCTP_EVENT_WRITE) != 0: - debug "sctp event write in the upcall" + trace "sctp event write in the upcall" else: warn "Handle Upcall unexpected event", events @@ -313,16 +313,15 @@ proc stopServer*(self: Sctp) = pc.sctpSocket.usrsctp_close() self.sockServer.usrsctp_close() -proc new*(T: typedesc[Sctp], dtls: Dtls, laddr: TransportAddress): T = - let sctp = T(gotConnection: newAsyncEvent(), - timersHandler: timersHandler(), - dtls: dtls) +proc init*(self: Sctp, dtls: Dtls, laddr: TransportAddress) = + self.gotConnection = newAsyncEvent() + self.timersHandler = timersHandler() + self.dtls = dtls usrsctp_init_nothreads(laddr.port.uint16, sendCallback, printf) discard usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_NONE) discard usrsctp_sysctl_set_sctp_ecn_enable(1) - usrsctp_register_address(cast[pointer](sctp)) - return sctp + usrsctp_register_address(cast[pointer](self)) proc stop*(self: Sctp) {.async.} = # TODO: close every connections diff --git a/webrtc/webrtc.nim b/webrtc/webrtc.nim index 57b1d2f..5328c83 100644 --- a/webrtc/webrtc.nim +++ b/webrtc/webrtc.nim @@ -17,8 +17,6 @@ import sctp, datachannel logScope: topics = "webrtc" -# TODO: Implement a connect (or dial) procedure - type WebRTC* = ref object udp*: UdpConn @@ -28,15 +26,18 @@ type port: int proc new*(T: typedesc[WebRTC], address: TransportAddress): T = - var webrtc = T(udp: UdpConn(), stun: StunConn(), dtls: Dtls()) - webrtc.udp.init(address) - webrtc.stun.init(webrtc.udp, address) - webrtc.dtls.init(webrtc.stun, address) - webrtc.sctp = Sctp.new(webrtc.dtls, address) - return webrtc + result = T(udp: UdpConn(), stun: StunConn(), dtls: Dtls(), sctp: Sctp()) + result.udp.init(address) + result.stun.init(webrtc.udp, address) + result.dtls.init(webrtc.stun, address) + result.sctp.init(webrtc.dtls, address) -proc listen*(w: WebRTC) = - w.sctp.listen() +proc listen*(self: WebRTC) = + self.sctp.listen() + +proc connect*(self: WebRTC): Future[DataChannelConnection] {.async.} = + let sctpConn = await self.sctp.connect() + result = DataChannelConnection.new(sctpConn) proc accept*(w: WebRTC): Future[DataChannelConnection] {.async.} = let sctpConn = await w.sctp.accept() From d525da3d62ed65e989d782e4cbb7edf221128568 Mon Sep 17 00:00:00 2001 From: Ludovic Chenut Date: Wed, 6 Mar 2024 16:47:39 +0100 Subject: [PATCH 66/66] fix: oversight on renaming variable --- webrtc/datachannel.nim | 2 +- webrtc/webrtc.nim | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/webrtc/datachannel.nim b/webrtc/datachannel.nim index 5439cef..5505a45 100644 --- a/webrtc/datachannel.nim +++ b/webrtc/datachannel.nim @@ -224,4 +224,4 @@ proc new*(_: type DataChannelConnection, conn: SctpConn): DataChannelConnection incomingStreams: newAsyncQueue[DataChannelStream](), streamId: 1'u16 # TODO: Serveur == 1, client == 2 ) - conn.readLoopFut = conn.readLoop() + result.readLoopFut = result.readLoop() diff --git a/webrtc/webrtc.nim b/webrtc/webrtc.nim index 5328c83..f67a231 100644 --- a/webrtc/webrtc.nim +++ b/webrtc/webrtc.nim @@ -28,15 +28,15 @@ type proc new*(T: typedesc[WebRTC], address: TransportAddress): T = result = T(udp: UdpConn(), stun: StunConn(), dtls: Dtls(), sctp: Sctp()) result.udp.init(address) - result.stun.init(webrtc.udp, address) - result.dtls.init(webrtc.stun, address) - result.sctp.init(webrtc.dtls, address) + result.stun.init(result.udp, address) + result.dtls.init(result.stun, address) + result.sctp.init(result.dtls, address) proc listen*(self: WebRTC) = self.sctp.listen() -proc connect*(self: WebRTC): Future[DataChannelConnection] {.async.} = - let sctpConn = await self.sctp.connect() +proc connect*(self: WebRTC, raddr: TransportAddress): Future[DataChannelConnection] {.async.} = + let sctpConn = await self.sctp.connect(raddr) # TODO: Port? result = DataChannelConnection.new(sctpConn) proc accept*(w: WebRTC): Future[DataChannelConnection] {.async.} =