From dc411abdd167faecaa500ff297f6c30c14a36f9b Mon Sep 17 00:00:00 2001 From: Andrew Wasielewski Date: Tue, 19 Sep 2023 21:29:29 -0400 Subject: [PATCH] Support building pgsodium on windows (#72) * adding scripts to generate root secret key * add PGDLLEXPORT * support executing and reading getkey_script on windows * add visual studio solution/project files * add windows build instructions and update gitignore * remove nonfunctional powershell root key script * use compiler defined _WIN32 * remove check for write permissions * define getline function for windows builds * update windows build process to use msbuild from the command line * - Adding github action to build pgsodium using msbuild and the v143 platform toolset - Unit tests do not yet run, requires pgtap * windows tests: adding pgtap and running test suite --------- Co-authored-by: Michel Pelletier --- .github/workflows/test.yml | 58 ++++++++- .gitignore | 5 + build/pgsodium.vcxproj | 107 ++++++++++++++++ build/windows.md | 22 ++++ getkey_scripts/pgsodium_getkey.bat | 7 ++ src/aead.c | 2 +- src/box.c | 2 +- src/pgsodium.c | 27 +++- src/pgsodium.h | 194 ++++++++++++++--------------- src/random.c | 2 +- src/sign.c | 2 +- src/signcrypt.c | 8 +- 12 files changed, 328 insertions(+), 108 deletions(-) create mode 100644 build/pgsodium.vcxproj create mode 100644 build/windows.md create mode 100644 getkey_scripts/pgsodium_getkey.bat diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6f6376b..cde3fb3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,10 +3,64 @@ name: Tests on: [push, pull_request] jobs: - tests: + test_linux: + name: Linux build and tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Checkout source code + uses: actions/checkout@v2 + - name: Run tests run: | ./test.sh + test_windows: + name: Windows build and tests + runs-on: windows-latest + steps: + - name: Checkout source code + uses: actions/checkout@v2 + + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@v1 + + - name: Install dependencies + run: | + Invoke-WebRequest -URI https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable-msvc.zip -OutFile libsodium-1.0.18-stable-msvc.zip + tar -xf libsodium-1.0.18-stable-msvc.zip + rm libsodium-1.0.18-stable-msvc.zip + cp .\libsodium\x64\Release\v143\dynamic\libsodium.dll $env:PGROOT\lib + Invoke-WebRequest -URI https://github.com/theory/pgtap/archive/refs/tags/v1.2.0.zip -OutFile pgtap.zip + tar -xf pgtap.zip + rm pgtap.zip + cd pgtap-1.2.0 + cp .\sql\pgtap.sql.in .\sql\pgtap.sql + perl.exe '-pi.bak' -e "s/TAPSCHEMA/tap/g" .\sql\pgtap.sql + perl.exe '-pi.bak' -e "s/__OS__/win32/g" .\sql\pgtap.sql + perl.exe '-pi.bak' -e "s/__VERSION__/0.24/g" .\sql\pgtap.sql + perl.exe '-pi.bak' -e "s/^-- ## //g" .\sql\pgtap.sql + cp .\sql\pgtap.sql $env:PGROOT\share\extension + cp .\pgtap.control $env:PGROOT\share\extension + cp .\contrib\pgtap.spec $env:PGROOT\share\contrib + ren $env:PGROOT\share\extension\pgtap.sql $env:PGROOT\share\extension\pgtap--1.2.0.sql + shell: pwsh + + - name: Run msbuild + working-directory: ./build + run: | + msbuild pgsodium.vcxproj /p:libsodiumLocation=..\libsodium /p:PostgreSQLLocation=%PGROOT% /p:Configuration=Release /p:Platform=x64 /p:platformToolset=v143 + + - name: Install pgsodium, update config, and restart + run: | + cp .\build\x64\Release\pgsodium.dll $env:PGROOT\lib + cp pgsodium.control $env:PGROOT\share\extension + cp .\sql\* $env:PGROOT\share\extension + cp .\getkey_scripts\pgsodium_getkey.bat $env:PGDATA\ + ((Get-Content -Path $env:PGDATA\postgresql.conf) -Replace "#shared_preload_libraries = ''","shared_preload_libraries = 'pgsodium'") | Set-Content -Path $env:PGDATA\postgresql.conf + Add-Content -Path $env:PGDATA\postgresql.conf -Value ("pgsodium.getkey_script = '$env:PGDATA\pgsodium_getkey.bat'" -Replace "\\","/") + & $env:PGBIN\pg_ctl restart -D $env:PGDATA + shell: pwsh + + - name: Run pgsodium tests + run: | + & $env:PGBIN\psql -q -U postgres -f .\test\test.sql + shell: pwsh diff --git a/.gitignore b/.gitignore index 45837d0..0ab52d2 100644 --- a/.gitignore +++ b/.gitignore @@ -33,5 +33,10 @@ *.su *~ +# Visual Studio Build files +build/.vs/ +*.vcxproj.user +build/x64/ + pgsodium_encrypted_root.key .ipynb_checkpoints/ \ No newline at end of file diff --git a/build/pgsodium.vcxproj b/build/pgsodium.vcxproj new file mode 100644 index 0000000..76f2afc --- /dev/null +++ b/build/pgsodium.vcxproj @@ -0,0 +1,107 @@ + + + + + Debug + Win64 + + + Release + Win64 + + + + + + + x64 + DynamicLibrary + true + pgsodium + 10.0 + $(platformToolset) + Unicode + + + + true + false + false + Level3 + true + + + + true + true + false + All + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + true + CompileAsC + + $(PostgreSQLLocation)\include\server\port\win32_msvc; + $(PostgreSQLLocation)\include\server\port\win32; + $(PostgreSQLLocation)\include\server; + $(PostgreSQLLocation)\include; + $(libsodiumLocation)\include; + %(AdditionalIncludeDirectories) + + stdcpp17 + + + + Console + true + + $(libsodiumLocation)\x64\Release\$(platformToolset)\dynamic; + $(PostgreSQLLocation)\lib; + %(AdditionalLibraryDirectories) + + + postgres.lib; + libsodium.lib; + %(AdditionalDependencies) + + + + + + + + \ No newline at end of file diff --git a/build/windows.md b/build/windows.md new file mode 100644 index 0000000..bdb690c --- /dev/null +++ b/build/windows.md @@ -0,0 +1,22 @@ +#### Building on Windows +--------- + +- Download [libsodium](https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable-msvc.zip) >= 1.018 and unzip +- Download and run the [postgresql installer](https://www.postgresql.org/download/windows/) +- From the `/pgsodium/build` directory, run `msbuild` on `pgsodium.vcxproj` + - `msbuild` can be invoked though the *x64 Native Tools Command Prompt for VS 2022* + +The following properties ( **`/p`** or **`/property`** ) must be specified: +- `libsodiumLocation`: root libsodium directory +- `PostgreSQLLocation`: root postgresql directory, typically `C:\Program Files\PostgreSQL\ +- `Configuration`: [`Release`, `Debug`] +- `Platform`: [x64] +- `platformToolset`: [`v142`, `v143`] + +ie. + +``` +msbuild pgsodium.vcxproj /p:libsodiumLocation="C:\libsodium" /p:PostgreSQLLocation="C:\Program Files\PostgreSQL\15" /p:Configuration=Release /p:Platform=x64 /p:platformToolset=v143 +``` + +- Copy the `libsodium.dll` (from `libsodium\x64\Release\\dynamic`) and the newly built `pgsodium.dll` into your `\PostgreSQL\\lib` directory \ No newline at end of file diff --git a/getkey_scripts/pgsodium_getkey.bat b/getkey_scripts/pgsodium_getkey.bat new file mode 100644 index 0000000..134940f --- /dev/null +++ b/getkey_scripts/pgsodium_getkey.bat @@ -0,0 +1,7 @@ +@echo off +set KEY_FILE="%PGDATA%/pgsodium_root.key" + +IF NOT EXIST %KEY_FILE% ( + openssl rand -hex 32 > %KEY_FILE% +) +type "%PGDATA%/pgsodium_root.key" \ No newline at end of file diff --git a/src/aead.c b/src/aead.c index 0d841d5..1b0bc3d 100644 --- a/src/aead.c +++ b/src/aead.c @@ -250,7 +250,7 @@ pgsodium_crypto_aead_det_keygen (PG_FUNCTION_ARGS) PG_RETURN_BYTEA_P (result); } -PG_FUNCTION_INFO_V1 (pgsodium_crypto_aead_det_noncegen); +PGDLLEXPORT PG_FUNCTION_INFO_V1 (pgsodium_crypto_aead_det_noncegen); Datum pgsodium_crypto_aead_det_noncegen (PG_FUNCTION_ARGS) { diff --git a/src/box.c b/src/box.c index 9e57717..a5a7460 100644 --- a/src/box.c +++ b/src/box.c @@ -30,7 +30,7 @@ pgsodium_crypto_box_keypair (PG_FUNCTION_ARGS) return result; } -PG_FUNCTION_INFO_V1 (pgsodium_crypto_box_new_seed); +PGDLLEXPORT PG_FUNCTION_INFO_V1 (pgsodium_crypto_box_new_seed); Datum pgsodium_crypto_box_new_seed (PG_FUNCTION_ARGS) { diff --git a/src/pgsodium.c b/src/pgsodium.c index ff969b4..b49b94b 100644 --- a/src/pgsodium.c +++ b/src/pgsodium.c @@ -1,5 +1,25 @@ #include "pgsodium.h" +#ifdef _WIN32 +#define X_OK 4 +#define access _access +size_t getline(char **lineptr, size_t *n, FILE *stream) +{ + // We expect 64 bytes, allocate enough to be sure. + const int BUFFERSIZE = 1024; + char *buffer = malloc (BUFFERSIZE); + if (fgets (buffer, BUFFERSIZE - 1 , stream) == NULL) + { + free (buffer); + return -1; + } + *lineptr = buffer; + size_t char_read = strlen (*lineptr); + *n = char_read; + return char_read; +} +#endif + PG_MODULE_MAGIC; bytea *pgsodium_secret_key; @@ -136,7 +156,12 @@ _PG_init (void) proc_exit (1); } - char_read = getline (&secret_buf, &secret_len, fp); + if ((char_read = getline (&secret_buf, &secret_len, fp)) == -1) + { + ereport(ERROR, errmsg("unable to read secret key")); + proc_exit (1); + } + if (secret_buf[char_read - 1] == '\n') secret_buf[char_read - 1] = '\0'; diff --git a/src/pgsodium.h b/src/pgsodium.h index 52162b0..89a3877 100644 --- a/src/pgsodium.h +++ b/src/pgsodium.h @@ -59,7 +59,7 @@ static inline bytea *_pgsodium_zalloc_bytea (size_t); static inline bytea *pgsodium_derive_helper (unsigned long long subkey_id, size_t subkey_size, bytea * context); -extern bytea *pgsodium_secret_key; +extern PGDLLEXPORT bytea *pgsodium_secret_key; /* allocator attached zero-callback to clean up memory */ static inline bytea * @@ -119,150 +119,150 @@ pgsodium_derive_helper (unsigned long long subkey_id, return result; } -void _PG_init (void); +PGDLLEXPORT void _PG_init (void); /* Random data */ -Datum pgsodium_randombytes_random (PG_FUNCTION_ARGS); -Datum pgsodium_randombytes_uniform (PG_FUNCTION_ARGS); -Datum pgsodium_randombytes_buf (PG_FUNCTION_ARGS); -Datum pgsodium_randombytes_seed (PG_FUNCTION_ARGS); -Datum pgsodium_randombytes_buf_deterministic (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_randombytes_random (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_randombytes_uniform (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_randombytes_buf (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_randombytes_seed (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_randombytes_buf_deterministic (PG_FUNCTION_ARGS); /* Secret key authenticated encryption */ -Datum pgsodium_crypto_secretbox_keygen (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_secretbox_noncegen (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_secretbox (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_secretbox_open (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_secretbox_by_id (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_secretbox_open_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_secretbox_keygen (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_secretbox_noncegen (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_secretbox (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_secretbox_open (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_secretbox_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_secretbox_open_by_id (PG_FUNCTION_ARGS); /* Secret key authentication */ -Datum pgsodium_crypto_auth_keygen (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_auth (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_auth_verify (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_auth_by_id (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_auth_verify_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_auth_keygen (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_auth (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_auth_verify (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_auth_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_auth_verify_by_id (PG_FUNCTION_ARGS); /* Secret streams */ -Datum +PGDLLEXPORT Datum pgsodium_crypto_secretstream_xchacha20poly1305_keygen (PG_FUNCTION_ARGS); /* AEAD */ -Datum pgsodium_crypto_aead_ietf_keygen (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_aead_ietf_noncegen (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_aead_ietf_encrypt (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_aead_ietf_decrypt (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_aead_ietf_encrypt_by_id (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_aead_ietf_decrypt_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_aead_ietf_keygen (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_aead_ietf_noncegen (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_aead_ietf_encrypt (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_aead_ietf_decrypt (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_aead_ietf_encrypt_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_aead_ietf_decrypt_by_id (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_aead_det_keygen (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_aead_det_encrypt (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_aead_det_decrypt (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_aead_det_encrypt_by_id (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_aead_det_decrypt_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_aead_det_keygen (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_aead_det_encrypt (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_aead_det_decrypt (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_aead_det_encrypt_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_aead_det_decrypt_by_id (PG_FUNCTION_ARGS); /* Hashing */ -Datum pgsodium_crypto_generichash_keygen (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_generichash (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_generichash_by_id (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_shorthash_keygen (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_shorthash (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_shorthash_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_generichash_keygen (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_generichash (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_generichash_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_shorthash_keygen (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_shorthash (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_shorthash_by_id (PG_FUNCTION_ARGS); /* password Hashing */ -Datum pgsodium_crypto_pwhash_saltgen (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_pwhash (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_pwhash_str (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_pwhash_str_verify (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_pwhash_saltgen (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_pwhash (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_pwhash_str (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_pwhash_str_verify (PG_FUNCTION_ARGS); /* Public Key */ -Datum pgsodium_crypto_box_keypair (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_box_seed_keypair (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_box_noncegen (PG_FUNCTION_ARGS); - -Datum pgsodium_crypto_box (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_box_open (PG_FUNCTION_ARGS); - -Datum pgsodium_crypto_box_seal (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_box_seal_open (PG_FUNCTION_ARGS); - -Datum pgsodium_crypto_sign_keypair (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_sign_seed_keypair (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_sign (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_sign_open (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_sign_detached (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_sign_verify_detached (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_sign_init (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_sign_update (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_sign_final_create (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_sign_final_verify (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_sign_init (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_sign_update (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_sign_final_create (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_sign_final_verify (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_box_keypair (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_box_seed_keypair (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_box_noncegen (PG_FUNCTION_ARGS); + +PGDLLEXPORT Datum pgsodium_crypto_box (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_box_open (PG_FUNCTION_ARGS); + +PGDLLEXPORT Datum pgsodium_crypto_box_seal (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_box_seal_open (PG_FUNCTION_ARGS); + +PGDLLEXPORT Datum pgsodium_crypto_sign_keypair (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_sign_seed_keypair (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_sign (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_sign_open (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_sign_detached (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_sign_verify_detached (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_sign_init (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_sign_update (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_sign_final_create (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_sign_final_verify (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_sign_init (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_sign_update (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_sign_final_create (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_sign_final_verify (PG_FUNCTION_ARGS); /* Key Derivation */ -Datum pgsodium_crypto_kdf_keygen (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_kdf_derive_from_key (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_kdf_keygen (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_kdf_derive_from_key (PG_FUNCTION_ARGS); /* Key Exchange */ -Datum pgsodium_crypto_kx_keypair (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_kx_seed_keypair (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_kx_new_seed (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_kx_client_session_keys (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_kx_server_session_keys (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_kx_keypair (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_kx_seed_keypair (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_kx_new_seed (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_kx_client_session_keys (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_kx_server_session_keys (PG_FUNCTION_ARGS); /* Advanced */ -Datum pgsodium_crypto_auth_hmacsha512_keygen (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_auth_hmacsha512 (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_auth_hmacsha512_verify (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_auth_hmacsha512_by_id (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_auth_hmacsha512_verify_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_auth_hmacsha512_keygen (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_auth_hmacsha512 (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_auth_hmacsha512_verify (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_auth_hmacsha512_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_auth_hmacsha512_verify_by_id (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_auth_hmacsha256_keygen (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_auth_hmacsha256 (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_auth_hmacsha256_by_id (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_auth_hmacsha256_verify (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_auth_hmacsha256_verify_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_auth_hmacsha256_keygen (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_auth_hmacsha256 (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_auth_hmacsha256_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_auth_hmacsha256_verify (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_auth_hmacsha256_verify_by_id (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_hash_sha256 (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_hash_sha512 (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_hash_sha256 (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_hash_sha512 (PG_FUNCTION_ARGS); /* Server Managed Keys */ -Datum pgsodium_derive (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_derive (PG_FUNCTION_ARGS); /* Streaming */ -Datum pgsodium_crypto_stream_xchacha20_keygen (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_stream_xchacha20_noncegen (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_stream_xchacha20 (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_stream_xchacha20_xor (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_stream_xchacha20_xor_ic (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_stream_xchacha20_by_id (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_stream_xchacha20_xor_by_id (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_stream_xchacha20_xor_ic_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_stream_xchacha20_keygen (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_stream_xchacha20_noncegen (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_stream_xchacha20 (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_stream_xchacha20_xor (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_stream_xchacha20_xor_ic (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_stream_xchacha20_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_stream_xchacha20_xor_by_id (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_stream_xchacha20_xor_ic_by_id (PG_FUNCTION_ARGS); /* Sign-Cryption */ -Datum pgsodium_crypto_signcrypt_sign_before (PG_FUNCTION_ARGS); -Datum pgsodium_crypto_signcrypt_keypair (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_signcrypt_sign_before (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_crypto_signcrypt_keypair (PG_FUNCTION_ARGS); /* Helpers */ -Datum pgsodium_cmp (PG_FUNCTION_ARGS); -Datum pgsodium_sodium_bin2base64 (PG_FUNCTION_ARGS); -Datum pgsodium_sodium_base642bin (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_cmp (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_sodium_bin2base64 (PG_FUNCTION_ARGS); +PGDLLEXPORT Datum pgsodium_sodium_base642bin (PG_FUNCTION_ARGS); #endif /* PGSODIUM_H */ diff --git a/src/random.c b/src/random.c index 00aa47c..04162aa 100644 --- a/src/random.c +++ b/src/random.c @@ -34,7 +34,7 @@ pgsodium_randombytes_buf (PG_FUNCTION_ARGS) PG_RETURN_BYTEA_P (result); } -PG_FUNCTION_INFO_V1 (pgsodium_randombytes_new_seed); +PGDLLEXPORT PG_FUNCTION_INFO_V1 (pgsodium_randombytes_new_seed); Datum pgsodium_randombytes_new_seed (PG_FUNCTION_ARGS) { diff --git a/src/sign.c b/src/sign.c index 6e43ae6..22a999c 100644 --- a/src/sign.c +++ b/src/sign.c @@ -31,7 +31,7 @@ pgsodium_crypto_sign_keypair (PG_FUNCTION_ARGS) return result; } -PG_FUNCTION_INFO_V1 (pgsodium_crypto_sign_new_seed); +PGDLLEXPORT PG_FUNCTION_INFO_V1 (pgsodium_crypto_sign_new_seed); Datum pgsodium_crypto_sign_new_seed (PG_FUNCTION_ARGS) { diff --git a/src/signcrypt.c b/src/signcrypt.c index 5499404..141588c 100644 --- a/src/signcrypt.c +++ b/src/signcrypt.c @@ -95,7 +95,7 @@ pgsodium_crypto_signcrypt_sign_before (PG_FUNCTION_ARGS) return result; } -PG_FUNCTION_INFO_V1 (pgsodium_crypto_signcrypt_sign_after); +PGDLLEXPORT PG_FUNCTION_INFO_V1 (pgsodium_crypto_signcrypt_sign_after); Datum pgsodium_crypto_signcrypt_sign_after (PG_FUNCTION_ARGS) { @@ -124,7 +124,7 @@ pgsodium_crypto_signcrypt_sign_after (PG_FUNCTION_ARGS) PG_RETURN_BYTEA_P (signature); } -PG_FUNCTION_INFO_V1 (pgsodium_crypto_signcrypt_verify_before); +PGDLLEXPORT PG_FUNCTION_INFO_V1 (pgsodium_crypto_signcrypt_verify_before); Datum pgsodium_crypto_signcrypt_verify_before (PG_FUNCTION_ARGS) { @@ -189,7 +189,7 @@ pgsodium_crypto_signcrypt_verify_before (PG_FUNCTION_ARGS) return result; } -PG_FUNCTION_INFO_V1 (pgsodium_crypto_signcrypt_verify_after); +PGDLLEXPORT PG_FUNCTION_INFO_V1 (pgsodium_crypto_signcrypt_verify_after); Datum pgsodium_crypto_signcrypt_verify_after (PG_FUNCTION_ARGS) { @@ -221,7 +221,7 @@ pgsodium_crypto_signcrypt_verify_after (PG_FUNCTION_ARGS) PG_RETURN_BOOL (success == 0); } -PG_FUNCTION_INFO_V1 (pgsodium_crypto_signcrypt_verify_public); +PGDLLEXPORT PG_FUNCTION_INFO_V1 (pgsodium_crypto_signcrypt_verify_public); Datum pgsodium_crypto_signcrypt_verify_public (PG_FUNCTION_ARGS) {