35 Commits

Author SHA1 Message Date
eyedeekay
f90555ba4d Add github sync for libsam3
Some checks failed
Sync Primary Repository to GitHub Mirror / sync (push) Has been cancelled
2025-05-10 18:48:13 -04:00
idk
ea52a3251d Merge pull request #23 from i2p/macos-build-fixes
Macos build fixes
2024-02-25 15:01:14 -05:00
eyedeekay
03954db321 add MSG_NOSIGNAL to libsam3.c 2024-02-18 13:05:52 -05:00
eyedeekay
c8185f0ea8 add MSG_NOSIGNAL during mac pp phase 2024-02-17 10:33:42 -05:00
eyedeekay
02b3826685 include time header 2024-02-13 12:05:00 -05:00
eyedeekay
a71a49800f fix typo 2024-02-13 10:47:43 -05:00
eyedeekay
3166418a2d define SOCK_NONBLOCK and SOCK_CLOEXEC for OSX" 2024-02-13 10:46:06 -05:00
eyedeekay
b5ae6552d0 Include section needs to be true if __APPLE__ is defined 2024-02-13 10:36:37 -05:00
eyedeekay
344c62307d It needs to go in sam3a 2024-02-13 10:31:54 -05:00
eyedeekay
7edf37b893 that was a misidentification, use netinet/tcp instead 2024-02-13 10:24:55 -05:00
eyedeekay
140adb2141 that was a misidentification, use netinet/tcp instead 2024-02-13 10:24:37 -05:00
eyedeekay
b6d51e6284 since SOL_SOCKET doesn't exist on Mac, pass SOL_TCP on that platform 2024-02-13 10:17:17 -05:00
eyedeekay
b84a3caddf Merge branch 'macos-build-fixes' of github.com:i2p/libsam3 into macos-build-fixes 2024-02-09 16:55:06 -05:00
eyedeekay
7dbc7c1aae extern sam3atimeval2ms, sam3ams2timeval 2024-02-09 16:50:51 -05:00
idk
c38987ac1c Update src/libsam3a/libsam3a.c
Co-authored-by: Sergey Fedorov <vital.had@gmail.com>
2024-02-09 17:21:46 +00:00
eyedeekay
92b38de9cb Remove sysinfo.h from the Apple header section 2024-02-09 10:25:48 -05:00
eyedeekay
8b554c13b5 Include mach_time on osx platforms 2024-02-08 11:23:59 -05:00
eyedeekay
390793bdb8 Use getpid and TickCount when on OSX platforms 2024-02-08 11:21:18 -05:00
idk
e567bb463c Update src/libsam3a/libsam3a.c
Co-authored-by: Sergey Fedorov <vital.had@gmail.com>
2024-02-08 16:21:56 +00:00
idk
883932c073 Update src/libsam3/libsam3.c
Co-authored-by: Sergey Fedorov <vital.had@gmail.com>
2024-02-08 16:21:24 +00:00
eyedeekay
64d85291fd Disable use of sysinfo.h on Mac OSX and replace deprecated functions that killed it 2024-02-07 11:44:43 -05:00
eyedeekay
6bee253ca6 Use PID/TickCount for random nickname string on __APPLE__ Platforms 2024-02-07 11:34:39 -05:00
eyedeekay
94478efec2 Fix some of the headers to make progress on fixing OSX builds 2023-12-22 12:04:24 -05:00
idk
2226ef0a20 Merge branch 'MITLicense' into 'master'
Replace License that Prominently Features an Expletive

See merge request i2p-hackers/libsam3!2
2023-07-24 23:03:12 +00:00
obscuratus
cd24279c2a Replace License that Prominently Features an Expletive
The original license prominently features an expletive in the
license name.

Replace this license with a similar permissive license (the MIT
license was choosen in this case).

Signed-off-by: obscuratus <obscuratus@mail.i2p>
2023-07-24 22:45:30 +00:00
idk
35754667d8 Merge branch 'datagram-example' into 'master'
Fixes for Datagram Example

See merge request i2p-hackers/libsam3!1
2023-07-18 19:41:23 +00:00
obscuratus
4843b0b624 Fixes for Datagram Example
The datagram examples (server and client) had accumulated a few
issues preventing them from running successfully.

The examples had not been updated to handle the longer destination
key sizes utilized by the new signature type.

Also, there was misalignment in parenthesis in the datagram
server example when evaluating the 'quit' message.

Signed-off-by: obscuratus <obscuratus@mail.i2p>
2022-08-16 16:18:23 -05:00
idk
27fabf8a82 fix out-of-bounds sig, closes #2, thanks @obscuratus 2022-08-07 23:26:15 -04:00
idk
36528099fd check in fix from @obscuratus, thanks for the MR, closes #1 2022-08-07 23:23:27 -04:00
idk
3b004ee4c7 add note to non-functioning boost example 2022-06-28 15:37:19 -04:00
idk
1920a37572 fix missing signature type in sam3CreateSession DESTINATION GENERATE 2022-06-28 15:36:11 -04:00
idk
ebf7d0b012 Merge pull request #16 from i2p/generateKeys
fix public key out put in generateKeys
2020-12-13 13:51:33 +00:00
idk
b410da5986 add new examples/tests 2020-12-13 01:01:44 -05:00
idk
1b7b8cf8ba add new examples/tests 2020-12-13 01:00:46 -05:00
idk
9ca783a022 fix public key out put in generateKeys 2020-12-13 00:57:13 -05:00
22 changed files with 632 additions and 176 deletions

66
.github/workflows/sync.yaml vendored Normal file
View File

@@ -0,0 +1,66 @@
# GitHub Actions workflow file to sync an external repository to this GitHub mirror.
# This file was automatically generated by go-github-sync.
#
# The workflow does the following:
# - Runs on a scheduled basis (and can also be triggered manually)
# - Clones the GitHub mirror repository
# - Fetches changes from the primary external repository
# - Applies those changes to the mirror repository
# - Pushes the updated content back to the GitHub mirror
#
# Authentication is handled by the GITHUB_TOKEN secret provided by GitHub Actions.
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Validate Github Actions Environment
run: if [ "$GITHUB_ACTIONS" != "true" ]; then echo 'This script must be run in a GitHub Actions environment.'; exit 1; fi
- name: Checkout GitHub Mirror
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Configure Git
run: |-
git config user.name 'GitHub Actions'
git config user.email 'actions@github.com'
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Sync Primary Repository
run: |-
# Add the primary repository as a remote
git remote add primary https://i2pgit.org/I2P_Developers/libsam3.git
# Fetch the latest changes from the primary repository
git fetch primary
# Check if the primary branch exists in the primary repository
if git ls-remote --heads primary master | grep -q master; then
echo "Primary branch master found in primary repository"
else
echo "Error: Primary branch master not found in primary repository"
exit 1
fi
# Check if we're already on the mirror branch
if git rev-parse --verify --quiet master; then
git checkout master
else
# Create the mirror branch if it doesn't exist
git checkout -b master
fi
# Force-apply all changes from primary, overriding any conflicts
echo "Performing force sync from primary/master to master"
git reset --hard primary/master
# Push changes back to the mirror repository
git push origin master
name: Sync Primary Repository to GitHub Mirror
"on":
push: {}
schedule:
- cron: 0 * * * *
workflow_dispatch: {}

13
.gitignore vendored
View File

@@ -1,3 +1,14 @@
*.o
libsam3-tests
*.a
*.a
examples/libsam3
examples/sam3/dgrams
examples/sam3/dgramc
examples/sam3/keys
examples/sam3/keysp
examples/sam3namelookup
examples/sam3/streamss
examples/sam3/streamcs
examples/sam3/log
examples/sam3/err

View File

@@ -32,6 +32,10 @@ libsam3-tests: ${TEST_OBJS} ${LIB}
clean:
rm -f libsam3-tests ${LIB} ${OBJS} examples/sam3/samtest
# TODO: this does not work yet because I don't know how to do it.
boost:
gcc -Werror -Wall -Wextra -Wno-unused-parameter -std=c++11 -g -lboost_system -lboost_thread -lpthread examples/boost/boost.cpp -o boost
%.o: %.c Makefile
${CC} ${CFLAGS} $(LDFLAGS) -c $< -o $@

View File

@@ -28,9 +28,14 @@ ssclient:
ssserver:
${CC} ${CFLAGS} streamss.c -o streamss ../libsam3/libsam3.o
keysp:
${CXX} ${CFLAGS} keys.cc -o keysp ../libsam3/libsam3.o
keys:
${CC} ${CFLAGS} keys.c -o keys ../libsam3/libsam3.o
clean:
rm -f samtest lookup dgramc dgrams streamc streams streams.key test-lookup
rm -f samtest lookup dgramc dgrams streamc streams streams.key test-lookup keys keysp
debug:
sed -i 's|// libsam3_debug = 1;|libsam3_debug = 1;|g' *.c

View File

@@ -1,12 +1,28 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -25,8 +41,9 @@
int main(int argc, char *argv[]) {
Sam3Session ses;
char buf[1024];
char destkey[517] = {0}; // 516 chars + \0
char destkey[SAM3_PUBKEY_SIZE + SAM3_CERT_SIZE + 1] = {0};
int sz;
size_t sizeread;
//
libsam3_debug = 1;
//
@@ -34,17 +51,27 @@ int main(int argc, char *argv[]) {
FILE *fl = fopen(KEYFILE, "rb");
//
if (fl != NULL) {
if (fread(destkey, 516, 1, fl) == 1) {
fprintf(stderr, "Reading key file...\n");
sizeread = fread(destkey, sizeof(char), sizeof(destkey), fl);
fprintf(stderr, "Read %li bytes\n", sizeread);
if (ferror(fl) != 0) {
fprintf(stderr, "I/O Error\n");
return 1;
}
// Insure that the bytes read safely fits into destkey
if (sizeread == sizeof(destkey)) {
fprintf(stderr, "Error, key file is to large (> %li)\n", sizeread);
fclose(fl);
goto ok;
return 1;
}
fclose(fl);
goto ok;
}
printf("usage: dgramc PUBKEY\n");
return 1;
} else {
if (strlen(argv[1]) != 516) {
fprintf(stderr, "FATAL: invalid key length!\n");
if (strlen(argv[1]) > (SAM3_PUBKEY_SIZE + SAM3_CERT_SIZE)) {
fprintf(stderr, "FATAL: invalid key length (%li)!\n", strlen(argv[1]));
return 1;
}
strcpy(destkey, argv[1]);

View File

@@ -1,12 +1,28 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -19,7 +35,9 @@
int main(int argc, char *argv[]) {
Sam3Session ses;
char privkey[1024], pubkey[1024], buf[33 * 1024];
char privkey[SAM3_PRIVKEY_MAX_SIZE + 1],
pubkey[SAM3_PUBKEY_SIZE + SAM3_CERT_SIZE + 1],
buf[33 * 1024];
/** quit command */
const char *quitstr = "quit";
@@ -46,7 +64,7 @@ int main(int argc, char *argv[]) {
/** create sam session */
printf("creating session...\n");
if (sam3CreateSession(&ses, SAM3_HOST_DEFAULT, SAM3_PORT_DEFAULT, privkey,
SAM3_SESSION_DGRAM, 5, NULL) < 0) {
SAM3_SESSION_DGRAM, 4, NULL) < 0) {
fprintf(stderr, "FATAL: can't create session\n");
return 1;
}
@@ -58,7 +76,8 @@ int main(int argc, char *argv[]) {
return 1;
}
/** print destination to stdout */
printf("PUB KEY\n=======\n%s\n=======\n", ses.pubkey);
printf("PUB KEY (length = %li)\n=======\n%s\n=======\n",
strlen(ses.pubkey), ses.pubkey);
if ((fl = fopen(KEYFILE, "wb")) != NULL) {
/** write public key to keyfile */
fwrite(pubkey, strlen(pubkey), 1, fl);
@@ -74,7 +93,8 @@ int main(int argc, char *argv[]) {
int sz, isquit;
printf("waiting for datagram...\n");
/** blocks until we get a UDP packet */
if ((sz = sam3DatagramReceive(&ses, datagramBuf, datagramMaxLen) < 0)) {
sz = sam3DatagramReceive(&ses, datagramBuf, datagramMaxLen);
if (sz < 0) {
fprintf(stderr, "ERROR: %s\n", ses.error);
goto error;
}

20
examples/sam3/keys.c Normal file
View File

@@ -0,0 +1,20 @@
//#include <string>
//#include <iostream>
#include "../libsam3/libsam3.h"
#include <stdio.h>
int main() {
// The session is only usef for transporting the data
Sam3Session ss;
if (0 > sam3GenerateKeys(&ss, SAM3_HOST_DEFAULT, SAM3_PORT_DEFAULT, 4)) {
printf("got error");
return -1;
}
printf("\tpubkey: %s \n \tprivkey: %s", ss.pubkey, ss.privkey);
/*auto pub = std::string(ss.pubkey);
auto priv = std::string(ss.privkey);
std::cout << "pub " << pub << std::endl << "priv " << priv << std::endl;*/
return 0;
}

19
examples/sam3/keys.cc Normal file
View File

@@ -0,0 +1,19 @@
#include <string>
#include <iostream>
#include <stdio.h>
#include "../libsam3/libsam3.h"
int main() {
// The session is only usef for transporting the data
Sam3Session ss;
if (0 > sam3GenerateKeys(&ss, SAM3_HOST_DEFAULT, SAM3_PORT_DEFAULT, Sam3SigType::EdDSA_SHA512_Ed25519)) {
printf("got error");
return -1;
}
auto pub = std::string(ss.pubkey);
auto priv = std::string(ss.privkey);
std::cout << "pub " << pub << std::endl << "priv " << priv << std::endl;
return 0;
}

View File

@@ -1,12 +1,28 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@@ -1,12 +1,28 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

View File

@@ -1,12 +1,28 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

View File

@@ -1,12 +1,28 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

View File

@@ -1,12 +1,28 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

View File

@@ -1,12 +1,28 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

View File

@@ -1,12 +1,28 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

View File

@@ -1,12 +1,28 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

View File

@@ -1,12 +1,28 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

View File

@@ -1,12 +1,28 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include "libsam3.h"
#include <ctype.h>
@@ -32,14 +48,31 @@
#endif
#endif
#ifdef __unix__
#if defined(__unix__) || defined(__APPLE__)
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/sysinfo.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#endif
#if defined(__unix__) && !defined(__APPLE__)
#include <sys/sysinfo.h>
#endif
#if defined(__APPLE__)
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
#include <mach/mach_time.h>
uint32_t TickCount() {
uint64_t mat = mach_absolute_time();
uint32_t mul = 0x80d9594e;
return ((((0xffffffff & mat) * mul) >> 32) + (mat >> 32) * mul) >> 23;
}
#endif
////////////////////////////////////////////////////////////////////////////////
int libsam3_debug = 0;
@@ -609,19 +642,27 @@ static inline uint32_t hashint(uint32_t a) {
}
static uint32_t genSeed(void) {
volatile uint32_t seed = 1;
uint32_t res;
#ifndef WIN32
struct sysinfo sy;
pid_t pid = getpid();
//
sysinfo(&sy);
res = hashint((uint32_t)pid) ^ hashint((uint32_t)time(NULL)) ^
hashint((uint32_t)sy.sharedram) ^ hashint((uint32_t)sy.bufferram) ^
hashint((uint32_t)sy.uptime);
#ifndef __APPLE__
struct sysinfo sy;
pid_t pid = getpid();
//
sysinfo(&sy);
res = hashint((uint32_t)pid) ^ hashint((uint32_t)time(NULL)) ^
hashint((uint32_t)sy.sharedram) ^ hashint((uint32_t)sy.bufferram) ^
hashint((uint32_t)sy.uptime);
#else
res = hashint((uint32_t)getpid()) ^
hashint((uint32_t)TickCount());
#endif
#else
res = hashint((uint32_t)GetCurrentProcessId()) ^
hashint((uint32_t)GetTickCount());
#endif
res += __sync_fetch_and_add(&seed, 1);
//
return hashint(res);
}
@@ -716,20 +757,23 @@ int sam3GenerateKeys(Sam3Session *ses, const char *hostname, int port,
return -1;
}
//
if (sam3tcpPrintf(fd, "DEST GENERATE %s\n", sigtypes[sigType]) >= 0) {
if ((rep = sam3ReadReply(fd)) != NULL &&
sam3IsGoodReply(rep, "DEST", "REPLY", NULL, NULL)) {
const char *pub = sam3FindField(rep, "PUB"),
*priv = sam3FindField(rep, "PRIV");
//
if (pub != NULL && sam3CheckValidKeyLength(pub) && priv != NULL &&
strlen(priv) >= SAM3_PRIVKEY_MIN_SIZE) {
strcpy(ses->pubkey, pub);
strcpy(ses->privkey, priv);
res = 0;
}
}
if (sam3tcpPrintf(fd, "DEST GENERATE %s\n", sigtypes[(int)sigType]) < 0) {
strcpyerr(ses, "DEST_ERROR");
}
rep = sam3ReadReply(fd);
// sam3DumpFieldList(rep);
if (!sam3IsGoodReply(rep, "DEST", "REPLY", "PUB", NULL)) {
strcpyerr(ses, "PUBKEY_ERROR");
}
if (!sam3IsGoodReply(rep, "DEST", "REPLY", "PRIV", NULL)) {
strcpyerr(ses, "PRIVKEY_ERROR");
}
const char *pub = sam3FindField(rep, "PUB");
strcpy(ses->pubkey, pub);
const char *priv = sam3FindField(rep, "PRIV");
strcpy(ses->privkey, priv);
res = 0;
//
sam3FreeFieldList(rep);
sam3tcpDisconnect(fd);
@@ -893,6 +937,10 @@ int sam3CreateSession(Sam3Session *ses, const char *hostname, int port,
goto error;
}
// save our keys
if (strlen(v) > SAM3_PRIVKEY_MAX_SIZE) {
fprintf(stderr, "ERROR, Unexpected key size (%li)!\n", strlen(v));
goto error;
}
strcpy(ses->privkey, v);
sam3FreeFieldList(rep);
// get public key
@@ -1135,11 +1183,12 @@ int sam3DatagramSend(Sam3Session *ses, const char *destkey, const void *buf,
strcpyerr(ses, "INVALID_DATA");
return -1;
}
dbufsz = bufsize + 4 + SAM3_PUBKEY_SIZE + 1 + strlen(ses->channel) + 1;
dbufsz = bufsize + 4 + strlen(destkey) + 1 + strlen(ses->channel) + 1;
if ((dbuf = malloc(dbufsz)) == NULL) {
strcpyerr(ses, "OUT_OF_MEMORY");
return -1;
}
memset(dbuf, 0, dbufsz);
sprintf(dbuf, "3.0 %s %s\n", ses->channel, destkey);
memcpy(dbuf + strlen(dbuf), buf, bufsize);
res = sam3udpSendToIP(ses->ip, ses->port, dbuf, dbufsz);

View File

@@ -1,18 +1,34 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#ifndef LIBSAM3_H
#define LIBSAM3_H
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
#ifndef _SSIZE_T_DEFINED
#define _SSIZE_T_DEFINED
@@ -39,6 +55,7 @@ extern int libsam3_debug;
#define SAM3_PUBKEY_SIZE (516)
#define SAM3_CERT_SIZE (100)
#define SAM3_PRIVKEY_MIN_SIZE (884)
#define SAM3_PRIVKEY_MAX_SIZE (1024)
////////////////////////////////////////////////////////////////////////////////
/* returns fd or -1 */
@@ -136,7 +153,7 @@ typedef struct Sam3Session {
Sam3SessionType type;
Sam3SigType sigType;
int fd;
char privkey[SAM3_PRIVKEY_MIN_SIZE + 1]; // destination private key (asciiz)
char privkey[SAM3_PRIVKEY_MAX_SIZE + 1]; // destination private key (asciiz)
char pubkey[SAM3_PUBKEY_SIZE + SAM3_CERT_SIZE +
1]; // destination public key (asciiz)
char channel[66]; // name of this sam session (asciiz)

View File

@@ -1,14 +1,28 @@
/* async SAMv3 library
/*
* Copyright © 2023 I2P
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include "libsam3a.h"
#include <ctype.h>
@@ -34,15 +48,39 @@
#endif
#endif
#ifdef __unix__
#if defined(__unix__) && !defined(__APPLE__)
#include <sys/sysinfo.h>
#endif
#if defined(__unix__) || defined(__APPLE__)
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/sysinfo.h>
#include <sys/types.h>
#endif
#if defined(__APPLE__)
#include <mach/mach_time.h>
#include <netinet/tcp.h>
#ifndef SOCK_CLOEXEC
#define SOCK_CLOEXEC 0
#endif
#ifndef SOCK_NONBLOCK
#include <fcntl.h>
#define SOCK_NONBLOCK O_NONBLOCK
#endif
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
uint32_t TickCount() {
uint64_t mat = mach_absolute_time();
uint32_t mul = 0x80d9594e;
return ((((0xffffffff & mat) * mul) >> 32) + (mat >> 32) * mul) >> 23;
}
#endif
////////////////////////////////////////////////////////////////////////////////
int libsam3a_debug = 0;
@@ -50,11 +88,11 @@ int libsam3a_debug = 0;
#define DEFAULT_UDP_PORT (7655)
////////////////////////////////////////////////////////////////////////////////
uint64_t sam3atimeval2ms(const struct timeval *tv) {
extern uint64_t sam3atimeval2ms(const struct timeval *tv) {
return ((uint64_t)tv->tv_sec) * 1000 + ((uint64_t)tv->tv_usec) / 1000;
}
void sam3ams2timeval(struct timeval *tv, uint64_t ms) {
extern void sam3ams2timeval(struct timeval *tv, uint64_t ms) {
tv->tv_sec = ms / 1000;
tv->tv_usec = (ms % 1000) * 1000;
}
@@ -651,13 +689,18 @@ static uint32_t genSeed(void) {
volatile uint32_t seed = 1;
uint32_t res;
#ifndef WIN32
struct sysinfo sy;
pid_t pid = getpid();
//
sysinfo(&sy);
res = hashint((uint32_t)pid) ^ hashint((uint32_t)time(NULL)) ^
hashint((uint32_t)sy.sharedram) ^ hashint((uint32_t)sy.bufferram) ^
hashint((uint32_t)sy.uptime);
#ifndef __APPLE__
struct sysinfo sy;
pid_t pid = getpid();
//
sysinfo(&sy);
res = hashint((uint32_t)pid) ^ hashint((uint32_t)time(NULL)) ^
hashint((uint32_t)sy.sharedram) ^ hashint((uint32_t)sy.bufferram) ^
hashint((uint32_t)sy.uptime);
#else
res = hashint((uint32_t)getpid()) ^
hashint((uint32_t)TickCount());
#endif
#else
res = hashint((uint32_t)GetCurrentProcessId()) ^
hashint((uint32_t)GetTickCount());

View File

@@ -1,14 +1,28 @@
/* async SAMv3 library
/*
* Copyright © 2023 I2P
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#ifndef LIBSAM3A_H
#define LIBSAM3A_H
@@ -17,6 +31,7 @@
#include <time.h>
#include <sys/types.h>
#include <sys/time.h>
#ifdef __MINGW32__
//#include <winsock.h>

View File

@@ -1,12 +1,28 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
/*
* Copyright © 2023 I2P
*
* I2P-Bote:
* 5m77dFKGEq6~7jgtrfw56q3t~SmfwZubmGdyOLQOPoPp8MYwsZ~pfUCwud6LB1EmFxkm4C3CGlzq-hVs9WnhUV
* we are the Borg. */
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the “Software”), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://git.idk.i2p/i2p-hackers/libsam3/
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>