mirror of
https://github.com/clearml/dropbear
synced 2025-06-26 18:17:32 +00:00
Compare commits
182 Commits
DROPBEAR_2
...
DROPBEAR_2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64bd345a5d | ||
|
|
152c507499 | ||
|
|
e2ae628b17 | ||
|
|
6eabc0fe87 | ||
|
|
bf6f04cbe6 | ||
|
|
e0c86670e2 | ||
|
|
7840691420 | ||
|
|
96e1a7e6da | ||
|
|
3996e93a20 | ||
|
|
246f24eda8 | ||
|
|
4aa72b96c1 | ||
|
|
0fc20c70af | ||
|
|
ebc915baae | ||
|
|
7435369615 | ||
|
|
2e836bb553 | ||
|
|
36ccfd21e7 | ||
|
|
44c323872a | ||
|
|
094972ea84 | ||
|
|
2707f054a5 | ||
|
|
4c95d595c0 | ||
|
|
7efe873d73 | ||
|
|
4058574cfa | ||
|
|
d17dedfa4f | ||
|
|
4768351e89 | ||
|
|
3f3f399231 | ||
|
|
316c923188 | ||
|
|
8fdaf0268d | ||
|
|
f2d86ae7d3 | ||
|
|
34ee326075 | ||
|
|
1656db9e58 | ||
|
|
802dace05e | ||
|
|
c2f2f2b817 | ||
|
|
67111efdad | ||
|
|
5fd677af76 | ||
|
|
b080f5a047 | ||
|
|
c8d852caf6 | ||
|
|
f042eb41ab | ||
|
|
017e2f07a7 | ||
|
|
3a923b72a4 | ||
|
|
5bf1214859 | ||
|
|
2ef1ab0753 | ||
|
|
c218af6ea7 | ||
|
|
e0748b1970 | ||
|
|
3ee685ad1c | ||
|
|
17be46e229 | ||
|
|
370d4c7cd5 | ||
|
|
1700987bfc | ||
|
|
a1aa161527 | ||
|
|
9a7972dcb8 | ||
|
|
191f22e11a | ||
|
|
93632660bb | ||
|
|
84d415fb66 | ||
|
|
ad9db51434 | ||
|
|
1a37d7aa48 | ||
|
|
22eb197d6c | ||
|
|
3953018c2d | ||
|
|
cfe99a79bd | ||
|
|
ee812daf69 | ||
|
|
df66daa26a | ||
|
|
8013009880 | ||
|
|
95b99cc86a | ||
|
|
6a713ad834 | ||
|
|
c81e530d3c | ||
|
|
4b021ae6f0 | ||
|
|
a36f182b36 | ||
|
|
d8bb6a7816 | ||
|
|
57d474e183 | ||
|
|
d7e12aadbe | ||
|
|
c0df3902b7 | ||
|
|
4f2eb1914b | ||
|
|
d72f50ff32 | ||
|
|
debb208553 | ||
|
|
f581ef9453 | ||
|
|
b65354d237 | ||
|
|
e4ac7ea1ca | ||
|
|
9c7ecf6d14 | ||
|
|
917722257d | ||
|
|
3d61b6eab6 | ||
|
|
e64e25e4d6 | ||
|
|
ba23b823dc | ||
|
|
fa3b0dd3ca | ||
|
|
dd8988220e | ||
|
|
cc803ee802 | ||
|
|
598056d168 | ||
|
|
89e64c631e | ||
|
|
468656b4aa | ||
|
|
22037d5fba | ||
|
|
a5ec3aca7d | ||
|
|
785459d31b | ||
|
|
a9a3746d09 | ||
|
|
74ace058a6 | ||
|
|
96382d52ab | ||
|
|
ddbc8113a9 | ||
|
|
65115b9159 | ||
|
|
e255101299 | ||
|
|
a94338dc67 | ||
|
|
364fb6019c | ||
|
|
a79b61517b | ||
|
|
99361f54ca | ||
|
|
82c06dd76b | ||
|
|
57690891ce | ||
|
|
5896a4941d | ||
|
|
521e63529c | ||
|
|
24b446705b | ||
|
|
3c5ed47804 | ||
|
|
44f36d57e6 | ||
|
|
7ab8f61974 | ||
|
|
4bba3268d5 | ||
|
|
5f76e4c1ed | ||
|
|
92c4f20089 | ||
|
|
acfd372808 | ||
|
|
6054483dc7 | ||
|
|
25931bc1e6 | ||
|
|
9250c58013 | ||
|
|
4f226ab36a | ||
|
|
33e28fb96b | ||
|
|
206b9cea0d | ||
|
|
9dcb04a1e0 | ||
|
|
08543d0c76 | ||
|
|
6c43be767c | ||
|
|
924b8469cb | ||
|
|
0ab0687a3a | ||
|
|
72f85ad90f | ||
|
|
fb4e07f7a8 | ||
|
|
6e0b539e9c | ||
|
|
83b2c899f5 | ||
|
|
eb7ca20379 | ||
|
|
af2caaab72 | ||
|
|
169f41a43c | ||
|
|
d260d5148e | ||
|
|
c38927da47 | ||
|
|
ea984cfb95 | ||
|
|
f7d38a1b9c | ||
|
|
45b27b0194 | ||
|
|
2a921c2c25 | ||
|
|
4c759cde1f | ||
|
|
c3984c89f7 | ||
|
|
96dfbc882d | ||
|
|
d3883e54b8 | ||
|
|
5d2cb48f46 | ||
|
|
597f12c44a | ||
|
|
9f674382d5 | ||
|
|
6830a65923 | ||
|
|
0d9c3fe70b | ||
|
|
2e38ac7504 | ||
|
|
f208d7920c | ||
|
|
ecb4a6173d | ||
|
|
37a66fa5b6 | ||
|
|
f9e6bc2aec | ||
|
|
81a0240491 | ||
|
|
b4d31b492c | ||
|
|
32df924d02 | ||
|
|
c60a65bc93 | ||
|
|
4222251d6f | ||
|
|
c6e912f9e2 | ||
|
|
1df5c97144 | ||
|
|
b840a0f500 | ||
|
|
8db9415f2a | ||
|
|
dd19d73db4 | ||
|
|
91450c7a95 | ||
|
|
1d20df627d | ||
|
|
4a10b1961c | ||
|
|
100cbc5f3f | ||
|
|
e0c6e819c2 | ||
|
|
9025cd9b72 | ||
|
|
2b891f5eb3 | ||
|
|
01bde8ff94 | ||
|
|
eed0e2e431 | ||
|
|
bda3bc4c8d | ||
|
|
93f3c31807 | ||
|
|
3aeb557196 | ||
|
|
8c7ebc02a0 | ||
|
|
1152e47b52 | ||
|
|
32a28d0d9c | ||
|
|
d6daad29fc | ||
|
|
4664ce2c35 | ||
|
|
8174300429 | ||
|
|
a453b06168 | ||
|
|
103036c546 | ||
|
|
ac9a4c839f | ||
|
|
3d2ddd15f8 | ||
|
|
ea4ab22017 |
22
.gitignore
vendored
Normal file
22
.gitignore
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
*~
|
||||
*.o
|
||||
*.a
|
||||
*.da
|
||||
*.bb
|
||||
*.bbg
|
||||
*.prof
|
||||
/autom4te.cache
|
||||
/config.log
|
||||
/config.status
|
||||
/dbclient
|
||||
/dropbear
|
||||
/dropbearconvert
|
||||
/dropbearkey
|
||||
/dropbearmulti
|
||||
/scp
|
||||
/scp-progress
|
||||
Makefile
|
||||
config.h
|
||||
config.h.in
|
||||
configure
|
||||
default_options_guard.h
|
||||
3
.hgsigs
3
.hgsigs
@@ -20,3 +20,6 @@ af074dbcb68ff8670b3818e0d66d5dc6f1bd5877 0 iQIcBAABCgAGBQJWVdQfAAoJEPSYMBLCC7qs+
|
||||
5bb5976e6902a0c9fba974a880c68c9487ee1e77 0 iQIcBAABCgAGBQJWVyIKAAoJEESTFJTynGdzQosP/0k5bVTerpUKZLjyNuMU8o0eyc7njkX8EyMOyGbtcArKpzO2opSBTRsuCT9Zsk1iiQ1GMTY1quKD7aNr86Hipqo4th/+ZXmLe9mmaCDukKjD0ZYC4dBVUy6RSUAMvdkDP9sZs7CMTO/22a9SqOsKTv3s2NN6XnsBGnmNbvVx5hkAk5hMVNFrjKIaexzI/7bWQIDRo2HQCaWaL06JvWEDSEQd2mynGSXxT/+m4hBnuGg6qxn2pd4XfG0g10tDAFx64HQkWgZqSB+F8z71Cvfjondy1zjJYgtABqNlwCKQJZhRUW2+PblqQnz08TUy83XN2vtisOju4avGcHSaBgBbMvg8Wx4ZtM7sPP9pLrhhOTd5ceERHeTceTJy+iI1SQFvccjrRfs5aJ0zAQX5q6f4bV0zp5SmxkvnZUEkZIoetkM8VrPOYugqx31LtHAWfVT9NM+VkV/rrxLhk6J0giIQvC9MPWxRDileFVDszPiOgTLcxWjOziOLT+xijcj7dtx1b/f2bNCduN5G7i+icjjTlCNtyRPRqhBqn705W7F+xESP2gsscM/1BjQ7TGidU5m1njdkUjbrqm3+Qic6iqkG7SfETHmQB9mHqpJ0hACRPvZlhwB7oimNHllkrlw8UJw9f0SiuLjfERIgVS2EOp+mAia0RU7MlTt19o017M1ffEYL
|
||||
926e7275cef4f4f2a4251597ee4814748394824c 0 iQIcBAABCgAGBQJWYES4AAoJEESTFJTynGdzdT0P/0O/1frevtr698DwMe6kmJx35P6Bqq8szntMxYucv0HROTfr85JRcCCSvl/2SflDS215QmOxdvYLGLUWPJNz/gURCLpzsT88KLF68Y1tC72nl4Fj+LGIOlsWsvwEqQqw0v4iQkHIfcxI6q7g1r9Hfldf/ju4bzQ4HnKLxm6KNcLLoAsuehVpQ+njHpLmlLAGHU5a84B7xeXHFR+U/EBPxSdm637rNhmpLpkuK2Mym/Mzv7BThKDstpB8lhFHIwAVNqi3Cy4nGYxFZOJpooUN9pDornqAwuzHmOAMs9+49L8GZ1de5PBRGyFKibzjBIUWPEU9EIkfJVaVwTlqYK8Q/IRi9HjITPx6GpE8cZhdSvAibrQdb6BbIDrZ8eCvD9vnod6Uk0Jb9/ui6nCF9x+CN/3Qez4epV5+JCMYsqCiXFkVPm9Lab6L2eGZis7Q2TXImA/sSV+E4BGfH2urpkKlnuXTTtDp4XRG+lOISkIBXgjVY+uy8soVKNdx1gv+LeY8hu/oQ2NyOlaOeL47aSQ3who4Pk6pVRUOl6zfcKo9Vs6xDWm35A3Z6x/mrAENaXasB0JrfY5nIbefJUpbeSmi76fYldU98HdQNHPHCSeiKVYl7v/B6gi2JXp5xngLZz/5VVAurago7sRmpIp7G/AqU6LNE85IUzG8aQz8AfR0d1dW
|
||||
fd1981f41c626a969f07b4823848deaefef3c8aa 0 iQIcBAABCgAGBQJW4W2TAAoJEESTFJTynGdzuOcP/j6tvB2WRwSj39KoJuRcRebFWWv4ZHiQXYMXWa3X0Ppzz52r9W0cXDjjlp5FyGdovCQsK+IXmjPo5cCvWBrZJYA6usFr9ssnUtTC+45lvPxPYwj47ZGPngCXDt7LD+v08XhqCu4LsctXIP/zejd30KVS1eR2RHI+tnEyaIKC0Xaa0igcv74MZX7Q8/U+B730QMX5adfYAHoeyRhoctRWaxVV3To7Vadd9jNXP45MRY5auhRcK7XyQcS85vJeCRoysfDUas4ERRQWYkX+68GyzO9GrkYFle931Akw2K6ZZfUuiC2TrF5xv1eRP1Zm2GX481U4ZGFTI8IzZL8sVQ6tvzq2Mxsecu589JNui9aB2d8Gp2Su/E2zn0h0ShIRmviGzf2HiBt+Bnji5X2h/fJKWbLaWge0MdOU5Jidfyh9k0YT7xo4piJLJYSaZ3nv+j4jTYnTfL7uYvuWbYkJ1T32aQVCan7Eup3BFAgQjzbWYi1XQVg6fvu8uHPpS3tNNA9EAMeeyTyg1l6zI2EIU5gPfd/dKmdyotY2lZBkFZNJqFkKRZuzjWekcw7hAxS+Bd68GKklt/DGrQiVycAgimqwXrfkzzQagawq2fXL2uXB8ghlsyxKLSQPnAtBF2Jcn5FH2z7HOQ+e18ZrFfNy0cYa/4OdH6K5aK1igTzhZZP2Urn0
|
||||
70705edee9dd29cd3d410f19fbd15cc3489313e2 0 iQIcBAABCgAGBQJW7CQRAAoJEESTFJTynGdzTj0QAJL38CKSZthBAeI9c6B+IlwIeT6kPZaPqk1pkycCTWOe87NiNU9abrsF+JrjTuRQiO1EpM2IvfQEIXTijUcMxvld3PnzrZDDv6UvBLtOkn3i++HSVRO0MOuTKI8gFDEPUxRtcaCKXEbqYnf1OTK25FT09Vb//qP9mK1thvlLJmbV+D2a9MkMK66rom1d1h+347IsuwsM+ycHjB80VVAQLA7VYLC5YIwmL17dSmcQLvetfikAMwwmUE+KES4qiLSaqOcAWcKcU67RZzgMMv5o0rESlQmv1nj0mHZtHoUR71sd21emPaRXLOr0oT5YogWUphKq2qVthRn2B06+vd3hPdtn92CmJw9j7zT2jl4OeSjNm9qfAajsRzHIANssFxkGAb7w/LxcMoO29JC+01iUUJMdOVm+4Ns6wGI7qxssWPKdB+VbQUDlHrXLR+sopO524uhkYoWB6DVfTj4R6tImaHtj5/VXON0lsYaLGj8cSH60emL6nNQ0lYV/bSlk6l0s+0x3uXGZnp9oKA+vqMzHfG3vJeMm6KUqtFVjUsYx+q8nHm5/SlWxj1EwnkH8s8ELKZAUXjd76nWEwJ7JFRNRSQWvjOUh3/rsOo4JopzZXPsjCjm+Vql9TG0X6hB21noai32oD5RvfhtR/NX6sXNS5TKZz/j/cMsMnAAsSKb6W7Jm
|
||||
9030ffdbe5625e35ed7189ab84a41dfc8d413e9c 0 iQIcBAABCgAGBQJXkOg0AAoJEESTFJTynGdzc1kP/3vSKCnhOOvjCjnpTQadYcCUq8vTNnfLHYVu0R4ItPa/jT6RmxoaYP+lZnLnnBx9+aX7kzwHsa9BUX3MbMEyLrOzX2I+bDJbNPhQyupyCuPYlf5Q9KVcO9YlpbsC4q5XBzCn3j2+pT8kSfi9uD8fgY3TgE4w9meINrfQAealfjwMLT8S/I49/ni0r+usSfk/dnSShJYDUO7Ja0VWbJea/GkkZTu30bCnMUZPjRApipU3hPP63WFjkSMT1rp2mAXbWqyr9lf8z32yxzM9nMSjq4ViRFzFlkGtE3EVRJ4PwkO7JuiWAMPJpiQcEr+r52cCsmWhiGyHuINo01MwoMO9/n6uL1WVa3mJcE9se3xBOvfgDu2FRFGCAdm1tef+AGVo9EG1uJXi0sX2yUc6DMeuYaRWrXMMlZh7zp9cuNU9Y/lLui9RFmq66yeXG3Z2B72doju3Ig5QGrNNw2AOsSzeHdAtOp6ychqPcl9QfIeJQG18KyPSefZKM3G8YRKBRIwXFEH6iZJe5ZIP4iXrHDMn2JqtTRtDqKR8VNDAgb9z4Ffx8QRxFyj5JzTTMM1GddHb9udLvTQlO0ULYG7hCSMRNzvUBE2aTw8frjLRyfyyg3QpDu/hz8op8s1ecE8rTCD8RuX9DiiylNozypPtGNS+UDbAmkc1PCWaRpPVl+9K6787
|
||||
5c9207ceedaea794f958224c19214d66af6e2d56 0 iQIzBAABCgAdFiEE9zR+8u4uB6JnYoypRJMUlPKcZ3MFAlkdtooACgkQRJMUlPKcZ3P6ZxAAmLy/buZB/d96DJF/pViRWt/fWdjQFC4MqWfeSLW02OZ8Qkm1vPL3ln6WPHC2thy3xZWVg2uan3pLk/XXnsIFu8Q7r1EAfFFpvlMUmdl7asE8V6ilaeqmiI7bIvGMFbf4cZkQliLjiFkJX56tFHRCNi+rb7WgRuru3/GzPXUq2AvXZvFpFJgik0B72TxVlmCKeBRZq1FvP0UhAH48RJWYJksdEyzh2paMfjX9ZO5Q2SFFrmPw6k2ArdJFC1AYcgceZC84y06RKJ0WiSntUPlEUXgQbQVVWbtQDhjfJXMr/beuroNdT/vsRraLVkAzvhaDXNnHlAJNLQxci+AcLpnzZhxMW+ax7RRtrpXGxRN4cs0lBGUcSkaDybFqMYXwEjXAE8w6fdJRWCIlxctkAW/iNEO4kAG97hI2Qwcw5oU2Ymnv09zyGR+XJE35pJqPulJHExdwanJHvmjH0QF7TNFS82yxS5dKnP954cj3Lu9SWGYWjxQJRmLtOwb+lqqol4VTxG7Ois4uef9/Tpp9skeMZXVeNlpn2wrp6iFcX3uiiVDg9VKkl3ig6UqCiqQSuiIN87RXwUOeHXlCnW3adz3Xei0ziBrwLSql7lBIHGEAlUUNmJ3CrR8IwQtcynGEMKfNIeZ/XK+uNlm9cJIqZf1fzqc8KexlyS9AS0i/kiYZTr4=
|
||||
|
||||
3
.hgtags
3
.hgtags
@@ -52,3 +52,6 @@ cbd674d63cd4f3781464a8d4056a5506c8ae926f DROPBEAR_2015.67
|
||||
79a6ef02307d05cb9dda10465cb5b807baa8f62e DROPBEAR_2015.70
|
||||
9a944a243f08be6b22d32f166a0690eb4872462b DROPBEAR_2015.71
|
||||
78b12b6549be08b0bea3da329b2578060a76ca31 DROPBEAR_2016.72
|
||||
309e1c4a87682b6ca7d80b8555a1db416c3cb7ac DROPBEAR_2016.73
|
||||
0ed3d2bbf956cb8a9bf0f4b5a86b7dd9688205cb DROPBEAR_2016.74
|
||||
c31276613181c5cff7854e7ef586ace03424e55e DROPBEAR_2017.75
|
||||
|
||||
47
.travis.yml
47
.travis.yml
@@ -1,25 +1,25 @@
|
||||
language: c
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
git:
|
||||
depth: 3
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- BUNDLEDLIBTOM=--disable-bundled-libtom WEXTRAFLAGS=-Werror
|
||||
- BUNDLEDLIBTOM=--enable-bundled-libtom
|
||||
- MULTI=1
|
||||
- NOWRITEV=1
|
||||
|
||||
# TODO: remove this section when libtomcrypt compiles on OSX: https://github.com/libtom/libtomcrypt/issues/82
|
||||
matrix:
|
||||
exclude:
|
||||
include:
|
||||
# subsequent matrix options use these first settings
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: WEXTRAFLAGS=-Werror
|
||||
- env: MULTI=1 WEXTRAFLAGS=-Werror
|
||||
# libtom has some warnings, so no WEXTRAFLAGS
|
||||
- env: BUNDLEDLIBTOM=--enable-bundled-libtom WEXTRAFLAGS=""
|
||||
- env: NOWRITEV=1 WEXTRAFLAGS=-Werror
|
||||
# libtomcrypt 1.18.1 fixes clang problems, distro doesn't have that yet
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: BUNDLEDLIBTOM=--enable-bundled-libtom WEXTRAFLAGS=""
|
||||
- os: osx
|
||||
env: BUNDLEDLIBTOM=--disable-bundled-libtom WEXTRAFLAGS=-Werror
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
compiler: clang
|
||||
env: WEXTRAFLAGS=""
|
||||
|
||||
# container-based builds
|
||||
sudo: false
|
||||
@@ -35,13 +35,12 @@ addons:
|
||||
before_install:
|
||||
- if [ "$CC" = "clang" ]; then WEXTRAFLAGS="$WEXTRAFLAGS -Wno-error=incompatible-library-redeclaration" ; fi # workaround
|
||||
|
||||
install:
|
||||
- if [ "$TRAVIS_OS_NAME" = "osx" -a "$BUNDLEDLIBTOM" = "--disable-bundled-libtom" ]; then brew update > /dev/null && brew install libtomcrypt libtommath ; fi
|
||||
|
||||
script:
|
||||
- autoconf && autoheader && ./configure "$BUNDLEDLIBTOM" CFLAGS="-O2 -Wall -Wno-pointer-sign $WEXTRAFLAGS" --prefix="$HOME/inst"
|
||||
- if [ "$NOWRITEV" = "1" ]; then sed -i -e s/HAVE_WRITEV/DONT_HAVE_WRITEV/ config.h ; fi
|
||||
- make -j3 install
|
||||
- make -j3
|
||||
# avoid concurrent install, osx/freebsd is racey (https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=208093)
|
||||
- make install
|
||||
|
||||
after_success:
|
||||
- ~/inst/bin/dropbearkey -t rsa -f testrsa
|
||||
@@ -49,3 +48,9 @@ after_success:
|
||||
- ~/inst/bin/dropbearkey -t ecdsa -f testec256 -s 256
|
||||
- ~/inst/bin/dropbearkey -t ecdsa -f testec384 -s 384
|
||||
- ~/inst/bin/dropbearkey -t ecdsa -f testec521 -s 521
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- coverity
|
||||
|
||||
|
||||
137
CHANGES
137
CHANGES
@@ -1,3 +1,126 @@
|
||||
2018.76 - 27 February 2018
|
||||
|
||||
> > > Configuration/compatibility changes
|
||||
IMPORTANT
|
||||
Custom configuration is now specified in local_options.h rather than options.h
|
||||
Available options and defaults can be seen in default_options.h
|
||||
|
||||
To migrate your configuration, compare your customised options.h against the
|
||||
upstream options.h from your relevant version. Any customised options should
|
||||
be put in localoptions.h
|
||||
|
||||
- "configure --enable-static" should now be used instead of "make STATIC=1"
|
||||
This will avoid 'hardened build' flags that conflict with static binaries
|
||||
|
||||
- Set 'hardened build' flags by default if supported by the compiler.
|
||||
These can be disabled with configure --disable-harden if needed.
|
||||
-Wl,-pie
|
||||
-Wl,-z,now -Wl,-z,relro
|
||||
-fstack-protector-strong
|
||||
-D_FORTIFY_SOURCE=2
|
||||
# spectre v2 mitigation
|
||||
-mfunction-return=thunk
|
||||
-mindirect-branch=thunk
|
||||
|
||||
Spectre patch from Loganaden Velvindron
|
||||
|
||||
- "dropbear -r" option for hostkeys no longer attempts to load the default
|
||||
hostkey paths as well. If desired these can be specified manually.
|
||||
Patch from CamVan Nguyen
|
||||
|
||||
- group1-sha1 key exchange is disabled in the server by default since
|
||||
the fixed 1024-bit group may be susceptible to attacks
|
||||
|
||||
- twofish ciphers are now disabled in the default configuration
|
||||
|
||||
- Default generated ECDSA key size is now 256 (rather than 521)
|
||||
for better interoperability
|
||||
|
||||
- Minimum RSA key length has been increased to 1024 bits
|
||||
|
||||
> > > Other features and fixes
|
||||
|
||||
- Add runtime -T max_auth_tries option from Kevin Darbyshire-Bryant
|
||||
|
||||
- Add 'dbclient -J &fd' to allow dbclient to connect over an existing socket.
|
||||
See dbclient manpage for a socat example. Patch from Harald Becker
|
||||
|
||||
- Add "-c forced_command" option. Patch from Jeremy Kerr
|
||||
|
||||
- Restricted group -G option added with patch from stellarpower
|
||||
|
||||
- Support server-chosen TCP forwarding ports, patch from houseofkodai
|
||||
|
||||
- Allow choosing outgoing address for dbclient with -b [bind_address][:bind_port]
|
||||
Patch from houseofkodai
|
||||
|
||||
- Makefile will now rebuild object files when header files are modified
|
||||
|
||||
- Add group14-256 and group16 key exchange options
|
||||
|
||||
- curve25519-sha256 also supported without @libssh.org suffix
|
||||
|
||||
- Update bundled libtomcrypt to 1.18.1, libtommath to 1.0.1
|
||||
This fixes building with some recent versions of clang
|
||||
|
||||
- Set PAM_RHOST which is needed by modules such as pam_abl
|
||||
|
||||
- Improvements to DSS and RSA public key validation, found by OSS-Fuzz.
|
||||
|
||||
- Don't exit when an authorized_keys file has malformed entries. Found by OSS-Fuzz
|
||||
|
||||
- Fix null-pointer crash with malformed ECDSA or DSS keys. Found by OSS-Fuzz
|
||||
|
||||
- Numerous code cleanups and small issues fixed by Francois Perrad
|
||||
|
||||
- Test for pkt_sched.h rather than SO_PRIORITY which was problematic with some musl
|
||||
platforms. Reported by Oliver Schneider and Andrew Bainbridge
|
||||
|
||||
- Fix some platform portability problems, from Ben Gardner
|
||||
|
||||
- Add EXEEXT filename suffix for building dropbearmulti, from William Foster
|
||||
|
||||
- Support --enable-<option> properly for configure, from Stefan Hauser
|
||||
|
||||
- configure have_openpty result can be cached, from Eric Bénard
|
||||
|
||||
- handle platforms that return close() < -1 on failure, from Marco Wenzel
|
||||
|
||||
- Build and configuration cleanups from Michael Witten
|
||||
|
||||
- Fix libtomcrypt/libtommath linking order, from Andre McCurdy
|
||||
|
||||
- Fix old Linux platforms that have SYS_clock_gettime but not CLOCK_MONOTONIC
|
||||
|
||||
- Update curve25519-donna implementation to current version
|
||||
|
||||
2017.75 - 18 May 2017
|
||||
|
||||
- Security: Fix double-free in server TCP listener cleanup
|
||||
A double-free in the server could be triggered by an authenticated user if
|
||||
dropbear is running with -a (Allow connections to forwarded ports from any host)
|
||||
This could potentially allow arbitrary code execution as root by an authenticated user.
|
||||
Affects versions 2013.56 to 2016.74. Thanks to Mark Shepard for reporting the crash.
|
||||
CVE-2017-9078 https://secure.ucc.asn.au/hg/dropbear/rev/c8114a48837c
|
||||
|
||||
- Security: Fix information disclosure with ~/.ssh/authorized_keys symlink.
|
||||
Dropbear parsed authorized_keys as root, even if it were a symlink. The fix
|
||||
is to switch to user permissions when opening authorized_keys
|
||||
|
||||
A user could symlink their ~/.ssh/authorized_keys to a root-owned file they
|
||||
couldn't normally read. If they managed to get that file to contain valid
|
||||
authorized_keys with command= options it might be possible to read other
|
||||
contents of that file.
|
||||
This information disclosure is to an already authenticated user.
|
||||
Thanks to Jann Horn of Google Project Zero for reporting this.
|
||||
CVE-2017-9079 https://secure.ucc.asn.au/hg/dropbear/rev/0d889b068123
|
||||
|
||||
- Generate hostkeys with dropbearkey atomically and flush to disk with fsync
|
||||
Thanks to Andrei Gherzan for a patch
|
||||
|
||||
- Fix out of tree builds with bundled libtom
|
||||
Thanks to Henrik Nordström and Peter Krefting for patches.
|
||||
|
||||
2016.74 - 21 July 2016
|
||||
|
||||
- Security: Message printout was vulnerable to format string injection.
|
||||
@@ -9,16 +132,24 @@
|
||||
A dbclient user who can control username or host arguments could potentially
|
||||
run arbitrary code as the dbclient user. This could be a problem if scripts
|
||||
or webpages pass untrusted input to the dbclient program.
|
||||
CVE-2016-7406
|
||||
https://secure.ucc.asn.au/hg/dropbear/rev/b66a483f3dcb
|
||||
|
||||
- Security: dropbearconvert import of OpenSSH keys could run arbitrary code as
|
||||
the local dropbearconvert user when parsing malicious key files
|
||||
CVE-2016-7407
|
||||
https://secure.ucc.asn.au/hg/dropbear/rev/34e6127ef02e
|
||||
|
||||
- Security: dbclient could run arbitrary code as the local dbclient user if
|
||||
particular -m or -c arguments are provided. This could be an issue where
|
||||
dbclient is used in scripts.
|
||||
CVE-2016-7408
|
||||
https://secure.ucc.asn.au/hg/dropbear/rev/eed9376a4ad6
|
||||
|
||||
- Security: dbclient or dropbear server could expose process memory to the
|
||||
running user if compiled with DEBUG_TRACE and running with -v
|
||||
CVE-2016-7409
|
||||
https://secure.ucc.asn.au/hg/dropbear/rev/6a14b1f6dc04
|
||||
|
||||
The security issues were reported by an anonymous researcher working with
|
||||
Beyond Security's SecuriTeam Secure Disclosure www.beyondsecurity.com/ssd.html
|
||||
@@ -64,6 +195,7 @@
|
||||
|
||||
- Validate X11 forwarding input. Could allow bypass of authorized_keys command= restrictions,
|
||||
found by github.com/tintinweb. Thanks for Damien Miller for a patch. CVE-2016-3116
|
||||
https://secure.ucc.asn.au/hg/dropbear/rev/a3e8389e01ff
|
||||
|
||||
2015.71 - 3 December 2015
|
||||
|
||||
@@ -297,6 +429,8 @@ kernels, from Steve Dover
|
||||
|
||||
2013.61test - Thursday 14 November 2013
|
||||
|
||||
- Default generated RSA key size changed from 1024 to 2048 bits
|
||||
|
||||
- ECC (elliptic curve) support. Supports ECDSA hostkeys (requires new keys to
|
||||
be generated) and ECDH for setting up encryption keys (no intervention
|
||||
required). This is significantly faster.
|
||||
@@ -342,9 +476,11 @@ kernels, from Steve Dover
|
||||
- Limit the size of decompressed payloads, avoids memory exhaustion denial
|
||||
of service
|
||||
Thanks to Logan Lamb for reporting and investigating it. CVE-2013-4421
|
||||
https://secure.ucc.asn.au/hg/dropbear/rev/0bf76f54de6f
|
||||
|
||||
- Avoid disclosing existence of valid users through inconsistent delays
|
||||
Thanks to Logan Lamb for reporting. CVE-2013-4434
|
||||
https://secure.ucc.asn.au/hg/dropbear/rev/d7784616409a
|
||||
|
||||
- Update config.guess and config.sub for newer architectures
|
||||
|
||||
@@ -447,6 +583,7 @@ though probably will be soon
|
||||
This bug affects releases 0.52 onwards. Ref CVE-2012-0920.
|
||||
Thanks to Danny Fullerton of Mantor Organization for reporting
|
||||
the bug.
|
||||
https://secure.ucc.asn.au/hg/dropbear/rev/818108bf7749
|
||||
|
||||
- Compile fix, only apply IPV6 socket options if they are available in headers
|
||||
Thanks to Gustavo Zacarias for the patch
|
||||
|
||||
28
INSTALL
28
INSTALL
@@ -1,20 +1,26 @@
|
||||
Basic Dropbear build instructions:
|
||||
|
||||
- Edit options.h to set which features you want.
|
||||
- Edit debug.h if you want any debug options (not usually required).
|
||||
- Edit localoptions.h to set which features you want. Available options
|
||||
are described in default_options.h, these will be overridden by
|
||||
anything set in localoptions.h
|
||||
|
||||
(If using a non-tarball copy, "autoconf; autoheader")
|
||||
- If using a Mercurial or Git checkout, "autoconf; autoheader"
|
||||
|
||||
./configure (optionally with --disable-zlib or --disable-syslog,
|
||||
- Configure for your system:
|
||||
./configure (optionally with --disable-zlib or --disable-syslog,
|
||||
or --help for other options)
|
||||
|
||||
Now compile:
|
||||
- Compile:
|
||||
|
||||
make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp"
|
||||
make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp"
|
||||
|
||||
And install (/usr/local/bin is usual default):
|
||||
- Optionally install, or copy the binaries another way
|
||||
|
||||
make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" install
|
||||
make install (/usr/local/bin is usual default):
|
||||
|
||||
or
|
||||
|
||||
make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" install
|
||||
|
||||
(you can leave items out of the PROGRAMS list to avoid compiling them. If you
|
||||
recompile after changing the PROGRAMS list, you *MUST* "make clean" before
|
||||
@@ -22,7 +28,11 @@ recompiling - bad things will happen otherwise)
|
||||
|
||||
See MULTI for instructions on making all-in-one binaries.
|
||||
|
||||
If you want to compile statically, add "STATIC=1" to the make command-line.
|
||||
If you want to compile statically use ./configure --enable-static
|
||||
|
||||
By default Dropbear adds various build flags that improve robustness
|
||||
against programming bugs (good for security). If these cause problems
|
||||
they can be disabled with ./configure --disable-harden
|
||||
|
||||
Binaries can be stripped with "make strip"
|
||||
|
||||
|
||||
65
Makefile.in
65
Makefile.in
@@ -2,12 +2,11 @@
|
||||
# @configure_input@
|
||||
|
||||
# invocation:
|
||||
# make PROGRAMS="dropbear dbclient scp" MULTI=1 STATIC=1 SCPPROGRESS=1
|
||||
# make PROGRAMS="dropbear dbclient scp" MULTI=1 SCPPROGRESS=1
|
||||
#
|
||||
# to make a multiple-program statically linked binary "staticdropbearmulti".
|
||||
# to make a multiple-program binary "dropbearmulti".
|
||||
# This example will include dropbear, scp, dropbearkey, dropbearconvert, and
|
||||
# dbclient functionality, and includes the progress-bar functionality in scp.
|
||||
# Hopefully that seems intuitive.
|
||||
|
||||
ifndef PROGRAMS
|
||||
PROGRAMS=dropbear dbclient dropbearkey dropbearconvert
|
||||
@@ -20,8 +19,15 @@ LIBTOM_LIBS=@LIBTOM_LIBS@
|
||||
|
||||
ifeq (@BUNDLED_LIBTOM@, 1)
|
||||
LIBTOM_DEPS=$(STATIC_LTC) $(STATIC_LTM)
|
||||
LIBTOM_CLEAN=ltc-clean ltm-clean
|
||||
CFLAGS+=-I$(srcdir)/libtomcrypt/src/headers/
|
||||
LIBTOM_LIBS=$(STATIC_LTC) $(STATIC_LTM)
|
||||
LIBTOM_LIBS=$(STATIC_LTC) $(STATIC_LTM)
|
||||
endif
|
||||
|
||||
OPTION_HEADERS = default_options_guard.h sysoptions.h
|
||||
ifneq ($(wildcard localoptions.h),)
|
||||
CFLAGS+=-DLOCALOPTIONS_H_EXISTS
|
||||
OPTION_HEADERS += localoptions.h
|
||||
endif
|
||||
|
||||
COMMONOBJS=dbutil.o buffer.o dbhelpers.o \
|
||||
@@ -53,13 +59,6 @@ CONVERTOBJS=dropbearconvert.o keyimport.o
|
||||
|
||||
SCPOBJS=scp.o progressmeter.o atomicio.o scpmisc.o compat.o
|
||||
|
||||
HEADERS=options.h dbutil.h session.h packet.h algo.h ssh.h buffer.h kex.h \
|
||||
dss.h bignum.h signkey.h rsa.h dbrandom.h service.h auth.h \
|
||||
debug.h channel.h chansession.h config.h queue.h sshpty.h \
|
||||
termcodes.h gendss.h genrsa.h runopts.h includes.h \
|
||||
loginrec.h atomicio.h x11fwd.h agentfwd.h tcpfwd.h compat.h \
|
||||
listener.h fake-rfc2553.h ecc.h ecdsa.h
|
||||
|
||||
dropbearobjs=$(COMMONOBJS) $(CLISVROBJS) $(SVROBJS)
|
||||
dbclientobjs=$(COMMONOBJS) $(CLISVROBJS) $(CLIOBJS)
|
||||
dropbearkeyobjs=$(COMMONOBJS) $(KEYOBJS)
|
||||
@@ -76,6 +75,8 @@ bindir=@bindir@
|
||||
sbindir=@sbindir@
|
||||
mandir=@mandir@
|
||||
|
||||
.DELETE_ON_ERROR:
|
||||
|
||||
CC=@CC@
|
||||
AR=@AR@
|
||||
RANLIB=@RANLIB@
|
||||
@@ -88,9 +89,10 @@ LDFLAGS=@LDFLAGS@
|
||||
|
||||
EXEEXT=@EXEEXT@
|
||||
|
||||
STATIC=@STATIC@
|
||||
|
||||
# whether we're building client, server, or both for the common objects.
|
||||
# evilness so we detect 'dropbear' by itself as a word
|
||||
space:= $(empty) $(empty)
|
||||
ifneq (,$(strip $(foreach prog, $(PROGRAMS), $(findstring ZdropbearZ, Z$(prog)Z))))
|
||||
CFLAGS+= -DDROPBEAR_SERVER
|
||||
endif
|
||||
@@ -98,7 +100,6 @@ ifneq (,$(strip $(foreach prog, $(PROGRAMS), $(findstring ZdbclientZ, Z$(prog)Z)
|
||||
CFLAGS+= -DDROPBEAR_CLIENT
|
||||
endif
|
||||
|
||||
|
||||
# these are exported so that libtomcrypt's makefile will use them
|
||||
export CC
|
||||
export CFLAGS
|
||||
@@ -109,7 +110,7 @@ ifeq ($(STATIC), 1)
|
||||
endif
|
||||
|
||||
ifeq ($(MULTI), 1)
|
||||
TARGETS=dropbearmulti
|
||||
TARGETS=dropbearmulti$(EXEEXT)
|
||||
else
|
||||
TARGETS=$(PROGRAMS)
|
||||
endif
|
||||
@@ -121,19 +122,30 @@ endif
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
# for simplicity assume all source depends on all headers
|
||||
HEADERS=$(wildcard $(srcdir)/*.h *.h) $(OPTION_HEADERS)
|
||||
%.o : %.c $(HEADERS)
|
||||
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
|
||||
|
||||
default_options_guard.h: default_options.h
|
||||
@echo Creating $@
|
||||
@printf "/*\n > > > Do not edit this file (default_options_guard.h) < < <\nGenerated from "$^"\nLocal customisation goes in localoptions.h\n*/\n\n" > $@.tmp
|
||||
@$(srcdir)/ifndef_wrapper.sh < $^ >> $@.tmp
|
||||
@mv $@.tmp $@
|
||||
|
||||
strip: $(TARGETS)
|
||||
$(STRIP) $(addsuffix $(EXEEXT), $(TARGETS))
|
||||
|
||||
install: $(addprefix inst_, $(TARGETS))
|
||||
|
||||
insmultidropbear: dropbearmulti
|
||||
insmultidropbear: dropbearmulti$(EXEEXT)
|
||||
$(INSTALL) -d $(DESTDIR)$(sbindir)
|
||||
-rm -f $(DESTDIR)$(sbindir)/dropbear$(EXEEXT)
|
||||
-ln -s $(bindir)/dropbearmulti$(EXEEXT) $(DESTDIR)$(sbindir)/dropbear$(EXEEXT)
|
||||
$(INSTALL) -d $(DESTDIR)$(mandir)/man8
|
||||
$(INSTALL) -m 644 $(srcdir)/dropbear.8 $(DESTDIR)$(mandir)/man8/dropbear.8
|
||||
|
||||
insmulti%: dropbearmulti
|
||||
insmulti%: dropbearmulti$(EXEEXT)
|
||||
$(INSTALL) -d $(DESTDIR)$(bindir)
|
||||
-rm -f $(DESTDIR)$(bindir)/$*$(EXEEXT)
|
||||
-ln -s $(bindir)/dropbearmulti$(EXEEXT) $(DESTDIR)$(bindir)/$*$(EXEEXT)
|
||||
@@ -155,7 +167,6 @@ inst_%: %
|
||||
|
||||
inst_dropbearmulti: $(addprefix insmulti, $(PROGRAMS))
|
||||
|
||||
|
||||
# for some reason the rule further down doesn't like $($@objs) as a prereq.
|
||||
dropbear: $(dropbearobjs)
|
||||
dbclient: $(dbclientobjs)
|
||||
@@ -194,32 +205,34 @@ link%:
|
||||
-rm -f $*$(EXEEXT)
|
||||
-ln -s dropbearmulti$(EXEEXT) $*$(EXEEXT)
|
||||
|
||||
$(STATIC_LTC): options.h
|
||||
cd libtomcrypt && $(MAKE)
|
||||
$(STATIC_LTC): $(OPTION_HEADERS)
|
||||
$(MAKE) -C libtomcrypt
|
||||
|
||||
$(STATIC_LTM): options.h
|
||||
cd libtommath && $(MAKE)
|
||||
$(STATIC_LTM): $(OPTION_HEADERS)
|
||||
$(MAKE) -C libtommath
|
||||
|
||||
.PHONY : clean sizes thisclean distclean tidy ltc-clean ltm-clean
|
||||
|
||||
ltc-clean:
|
||||
cd libtomcrypt && $(MAKE) clean
|
||||
$(MAKE) -C libtomcrypt clean
|
||||
|
||||
ltm-clean:
|
||||
cd libtommath && $(MAKE) clean
|
||||
$(MAKE) -C libtommath clean
|
||||
|
||||
sizes: dropbear
|
||||
objdump -t dropbear|grep ".text"|cut -d "." -f 2|sort -rn
|
||||
|
||||
clean: ltc-clean ltm-clean thisclean
|
||||
clean: $(LIBTOM_CLEAN) thisclean
|
||||
|
||||
thisclean:
|
||||
-rm -f dropbear dbclient dropbearkey dropbearconvert scp scp-progress \
|
||||
dropbearmulti *.o *.da *.bb *.bbg *.prof
|
||||
-rm -f dropbear$(EXEEXT) dbclient$(EXEEXT) dropbearkey$(EXEEXT) \
|
||||
dropbearconvert$(EXEEXT) scp$(EXEEXT) scp-progress$(EXEEXT) \
|
||||
dropbearmulti$(EXEEXT) *.o *.da *.bb *.bbg *.prof
|
||||
|
||||
distclean: clean tidy
|
||||
-rm -f config.h
|
||||
-rm -f Makefile
|
||||
-rm -f default_options_guard.h
|
||||
|
||||
tidy:
|
||||
-rm -f *~ *.gcov */*~
|
||||
|
||||
4
README
4
README
@@ -8,8 +8,8 @@ which performs multiple tasks, to save disk space)
|
||||
|
||||
SMALL has some tips on creating small binaries.
|
||||
|
||||
See TODO for a few of the things I know need looking at, and please contact
|
||||
me if you have any questions/bugs found/features/ideas/comments etc :)
|
||||
Please contact me if you have any questions/bugs found/features/ideas/comments etc :)
|
||||
There is also a mailing list http://lists.ucc.gu.uwa.edu.au/mailman/listinfo/dropbear
|
||||
|
||||
Matt Johnston
|
||||
matt@ucc.asn.au
|
||||
|
||||
27
TODO
27
TODO
@@ -1,27 +0,0 @@
|
||||
Current:
|
||||
|
||||
Things which might need doing:
|
||||
|
||||
- default private dbclient keys
|
||||
|
||||
- Make options.h generated from configure perhaps?
|
||||
|
||||
- handle /etc/environment in AIX
|
||||
|
||||
- check that there aren't timing issues with valid/invalid user authentication
|
||||
feedback.
|
||||
|
||||
- Binding to different interfaces
|
||||
|
||||
- CTR mode
|
||||
- SSH_MSG_IGNORE sending to improve CBC security
|
||||
- DH Group Exchange possibly, or just add group14 (whatever it's called today)
|
||||
|
||||
- fix scp.c for IRIX
|
||||
|
||||
- Be able to use OpenSSH keys for the client? or at least have some form of
|
||||
encrypted keys.
|
||||
|
||||
- Client agent forwarding
|
||||
|
||||
- Handle restrictions in ~/.ssh/authorized_keys ?
|
||||
14
agentfwd.h
14
agentfwd.h
@@ -30,7 +30,7 @@
|
||||
#include "auth.h"
|
||||
#include "list.h"
|
||||
|
||||
#ifdef ENABLE_CLI_AGENTFWD
|
||||
#if DROPBEAR_CLI_AGENTFWD
|
||||
|
||||
/* An agent reply can be reasonably large, as it can
|
||||
* contain a list of all public keys held by the agent.
|
||||
@@ -40,8 +40,8 @@
|
||||
/* client functions */
|
||||
void cli_load_agent_keys(m_list * ret_list);
|
||||
void agent_buf_sign(buffer *sigblob, sign_key *key,
|
||||
buffer *data_buf);
|
||||
void cli_setup_agent(struct Channel *channel);
|
||||
const buffer *data_buf);
|
||||
void cli_setup_agent(const struct Channel *channel);
|
||||
|
||||
#ifdef __hpux
|
||||
#define seteuid(a) setresuid(-1, (a), -1)
|
||||
@@ -50,14 +50,14 @@ void cli_setup_agent(struct Channel *channel);
|
||||
|
||||
extern const struct ChanType cli_chan_agent;
|
||||
|
||||
#endif /* ENABLE_CLI_AGENTFWD */
|
||||
#endif /* DROPBEAR_CLI_AGENTFWD */
|
||||
|
||||
#ifdef ENABLE_SVR_AGENTFWD
|
||||
#if DROPBEAR_SVR_AGENTFWD
|
||||
|
||||
int svr_agentreq(struct ChanSess * chansess);
|
||||
void svr_agentcleanup(struct ChanSess * chansess);
|
||||
void svr_agentset(struct ChanSess *chansess);
|
||||
void svr_agentset(const struct ChanSess *chansess);
|
||||
|
||||
#endif /* ENABLE_SVR_AGENTFWD */
|
||||
#endif /* DROPBEAR_SVR_AGENTFWD */
|
||||
|
||||
#endif /* DROPBEAR_AGENTFWD_H_ */
|
||||
|
||||
16
algo.h
16
algo.h
@@ -83,9 +83,15 @@ struct dropbear_hash {
|
||||
};
|
||||
|
||||
enum dropbear_kex_mode {
|
||||
#if DROPBEAR_NORMAL_DH
|
||||
DROPBEAR_KEX_NORMAL_DH,
|
||||
#endif
|
||||
#if DROPBEAR_ECDH
|
||||
DROPBEAR_KEX_ECDH,
|
||||
#endif
|
||||
#if DROPBEAR_CURVE25519
|
||||
DROPBEAR_KEX_CURVE25519,
|
||||
#endif
|
||||
};
|
||||
|
||||
struct dropbear_kex {
|
||||
@@ -96,7 +102,7 @@ struct dropbear_kex {
|
||||
const int dh_p_len;
|
||||
|
||||
/* elliptic curve DH KEX */
|
||||
#ifdef DROPBEAR_ECDH
|
||||
#if DROPBEAR_ECDH
|
||||
const struct dropbear_ecc_curve *ecc_curve;
|
||||
#else
|
||||
const void* dummy;
|
||||
@@ -106,8 +112,8 @@ struct dropbear_kex {
|
||||
const struct ltc_hash_descriptor *hash_desc;
|
||||
};
|
||||
|
||||
int have_algo(char* algo, size_t algolen, algo_type algos[]);
|
||||
void buf_put_algolist(buffer * buf, algo_type localalgos[]);
|
||||
int have_algo(const char* algo, size_t algolen, const algo_type algos[]);
|
||||
void buf_put_algolist(buffer * buf, const algo_type localalgos[]);
|
||||
|
||||
enum kexguess2_used {
|
||||
KEXGUESS2_LOOK,
|
||||
@@ -122,10 +128,10 @@ enum kexguess2_used {
|
||||
algo_type * buf_match_algo(buffer* buf, algo_type localalgos[],
|
||||
enum kexguess2_used *kexguess2, int *goodguess);
|
||||
|
||||
#ifdef ENABLE_USER_ALGO_LIST
|
||||
#if DROPBEAR_USER_ALGO_LIST
|
||||
int check_user_algos(const char* user_algo_list, algo_type * algos,
|
||||
const char *algo_desc);
|
||||
char * algolist_string(algo_type algos[]);
|
||||
char * algolist_string(const algo_type algos[]);
|
||||
#endif
|
||||
|
||||
enum {
|
||||
|
||||
29
atomicio.c
29
atomicio.c
@@ -1,6 +1,8 @@
|
||||
/* $OpenBSD: atomicio.c,v 1.17 2006/04/01 05:51:34 djm Exp $ */
|
||||
/*
|
||||
* Copied from OpenSSH 3.6.1p2.
|
||||
* Copied from OpenSSH/OpenBSD.
|
||||
*
|
||||
* Copyright (c) 2005 Anil Madhavapeddy. All rights reserved.
|
||||
* Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -25,39 +27,32 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* RCSID("OpenBSD: atomicio.c,v 1.10 2001/05/08 22:48:07 markus Exp "); */
|
||||
#include "includes.h"
|
||||
|
||||
#include "atomicio.h"
|
||||
|
||||
/*
|
||||
* ensure all of data on socket comes through. f==read || f==write
|
||||
* ensure all of data on socket comes through. f==read || f==vwrite
|
||||
*/
|
||||
ssize_t
|
||||
atomicio(f, fd, _s, n)
|
||||
ssize_t (*f) ();
|
||||
int fd;
|
||||
void *_s;
|
||||
size_t n;
|
||||
size_t
|
||||
atomicio(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n)
|
||||
{
|
||||
char *s = _s;
|
||||
ssize_t res;
|
||||
size_t pos = 0;
|
||||
ssize_t res;
|
||||
|
||||
while (n > pos) {
|
||||
res = (f) (fd, s + pos, n - pos);
|
||||
switch (res) {
|
||||
case -1:
|
||||
#ifdef EWOULDBLOCK
|
||||
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
#else
|
||||
if (errno == EINTR || errno == EAGAIN)
|
||||
#endif
|
||||
continue;
|
||||
/* FALLTHROUGH */
|
||||
return 0;
|
||||
case 0:
|
||||
return (res);
|
||||
errno = EPIPE;
|
||||
return pos;
|
||||
default:
|
||||
pos += res;
|
||||
pos += (size_t)res;
|
||||
}
|
||||
}
|
||||
return (pos);
|
||||
|
||||
13
atomicio.h
13
atomicio.h
@@ -1,8 +1,7 @@
|
||||
/* $OpenBSD: atomicio.h,v 1.7 2006/03/25 22:22:42 djm Exp $ */
|
||||
|
||||
/*
|
||||
* Copied from OpenSSH 3.6.1p2, required for loginrec.c
|
||||
*
|
||||
* $OpenBSD: atomicio.h,v 1.4 2001/06/26 06:32:46 itojun Exp $
|
||||
* Copied from OpenSSH/OpenBSD, required for loginrec.c
|
||||
*
|
||||
* Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.
|
||||
* All rights reserved.
|
||||
@@ -28,9 +27,9 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
/*
|
||||
* Ensure all of data on socket comes through. f==read || f==write
|
||||
* Ensure all of data on socket comes through. f==read || f==vwrite
|
||||
*/
|
||||
ssize_t atomicio(ssize_t (*)(), int, void *, size_t);
|
||||
size_t atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t);
|
||||
|
||||
#define vwrite (ssize_t (*)(int, void *, size_t))write
|
||||
|
||||
16
auth.h
16
auth.h
@@ -36,12 +36,12 @@ void cli_authinitialise(void);
|
||||
void recv_msg_userauth_request(void);
|
||||
void send_msg_userauth_failure(int partial, int incrfail);
|
||||
void send_msg_userauth_success(void);
|
||||
void send_msg_userauth_banner(buffer *msg);
|
||||
void send_msg_userauth_banner(const buffer *msg);
|
||||
void svr_auth_password(void);
|
||||
void svr_auth_pubkey(void);
|
||||
void svr_auth_pam(void);
|
||||
|
||||
#ifdef ENABLE_SVR_PUBKEY_OPTIONS
|
||||
#if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT
|
||||
int svr_pubkey_allows_agentfwd(void);
|
||||
int svr_pubkey_allows_tcpfwd(void);
|
||||
int svr_pubkey_allows_x11fwd(void);
|
||||
@@ -74,7 +74,7 @@ void cli_pubkeyfail(void);
|
||||
void cli_auth_password(void);
|
||||
int cli_auth_pubkey(void);
|
||||
void cli_auth_interactive(void);
|
||||
char* getpass_or_cancel(char* prompt);
|
||||
char* getpass_or_cancel(const char* prompt);
|
||||
void cli_auth_pubkey_cleanup(void);
|
||||
|
||||
|
||||
@@ -105,12 +105,14 @@ struct AuthState {
|
||||
unsigned char authtypes; /* Flags indicating which auth types are still
|
||||
valid */
|
||||
unsigned int failcount; /* Number of (failed) authentication attempts.*/
|
||||
unsigned authdone : 1; /* 0 if we haven't authed, 1 if we have. Applies for
|
||||
unsigned int authdone; /* 0 if we haven't authed, 1 if we have. Applies for
|
||||
client and server (though has differing
|
||||
meanings). */
|
||||
unsigned perm_warn : 1; /* Server only, set if bad permissions on
|
||||
unsigned int perm_warn; /* Server only, set if bad permissions on
|
||||
~/.ssh/authorized_keys have already been
|
||||
logged. */
|
||||
unsigned int checkusername_failed; /* Server only, set if checkusername
|
||||
has already failed */
|
||||
|
||||
/* These are only used for the server */
|
||||
uid_t pw_uid;
|
||||
@@ -119,12 +121,12 @@ struct AuthState {
|
||||
char *pw_shell;
|
||||
char *pw_name;
|
||||
char *pw_passwd;
|
||||
#ifdef ENABLE_SVR_PUBKEY_OPTIONS
|
||||
#if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT
|
||||
struct PubKeyOptions* pubkey_options;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef ENABLE_SVR_PUBKEY_OPTIONS
|
||||
#if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT
|
||||
struct PubKeyOptions;
|
||||
struct PubKeyOptions {
|
||||
/* Flags */
|
||||
|
||||
16
bignum.c
16
bignum.c
@@ -68,6 +68,22 @@ void m_mp_alloc_init_multi(mp_int **mp, ...)
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void m_mp_free_multi(mp_int **mp, ...)
|
||||
{
|
||||
mp_int** cur_arg = mp;
|
||||
va_list args;
|
||||
|
||||
va_start(args, mp); /* init args to next argument from caller */
|
||||
while (cur_arg != NULL) {
|
||||
if (*cur_arg) {
|
||||
mp_clear(*cur_arg);
|
||||
}
|
||||
m_free(*cur_arg);
|
||||
cur_arg = va_arg(args, mp_int**);
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void bytes_to_mp(mp_int *mp, const unsigned char* bytes, unsigned int len) {
|
||||
|
||||
if (mp_read_unsigned_bin(mp, (unsigned char*)bytes, len) != MP_OKAY) {
|
||||
|
||||
1
bignum.h
1
bignum.h
@@ -30,6 +30,7 @@
|
||||
void m_mp_init(mp_int *mp);
|
||||
void m_mp_init_multi(mp_int *mp, ...) ATTRIB_SENTINEL;
|
||||
void m_mp_alloc_init_multi(mp_int **mp, ...) ATTRIB_SENTINEL;
|
||||
void m_mp_free_multi(mp_int **mp, ...) ATTRIB_SENTINEL;
|
||||
void bytes_to_mp(mp_int *mp, const unsigned char* bytes, unsigned int len);
|
||||
void hash_process_mp(const struct ltc_hash_descriptor *hash_desc,
|
||||
hash_state *hs, mp_int *mp);
|
||||
|
||||
9
buffer.c
9
buffer.c
@@ -67,7 +67,7 @@ void buf_free(buffer* buf) {
|
||||
}
|
||||
|
||||
/* overwrite the contents of the buffer to clear it */
|
||||
void buf_burn(buffer* buf) {
|
||||
void buf_burn(const buffer* buf) {
|
||||
|
||||
m_burn(buf->data, buf->size);
|
||||
|
||||
@@ -91,7 +91,7 @@ buffer* buf_resize(buffer *buf, unsigned int newsize) {
|
||||
|
||||
/* Create a copy of buf, allocating required memory etc. */
|
||||
/* The new buffer is sized the same as the length of the source buffer. */
|
||||
buffer* buf_newcopy(buffer* buf) {
|
||||
buffer* buf_newcopy(const buffer* buf) {
|
||||
|
||||
buffer* ret;
|
||||
|
||||
@@ -109,6 +109,7 @@ void buf_setlen(buffer* buf, unsigned int len) {
|
||||
dropbear_exit("Bad buf_setlen");
|
||||
}
|
||||
buf->len = len;
|
||||
buf->pos = MIN(buf->pos, buf->len);
|
||||
}
|
||||
|
||||
/* Increment the length of the buffer */
|
||||
@@ -183,7 +184,7 @@ void buf_putbyte(buffer* buf, unsigned char val) {
|
||||
|
||||
/* returns an in-place pointer to the buffer, checking that
|
||||
* the next len bytes from that position can be used */
|
||||
unsigned char* buf_getptr(buffer* buf, unsigned int len) {
|
||||
unsigned char* buf_getptr(const buffer* buf, unsigned int len) {
|
||||
|
||||
if (len > BUF_MAX_INCR || buf->pos + len > buf->len) {
|
||||
dropbear_exit("Bad buf_getptr");
|
||||
@@ -193,7 +194,7 @@ unsigned char* buf_getptr(buffer* buf, unsigned int len) {
|
||||
|
||||
/* like buf_getptr, but checks against total size, not used length.
|
||||
* This allows writing past the used length, but not past the size */
|
||||
unsigned char* buf_getwriteptr(buffer* buf, unsigned int len) {
|
||||
unsigned char* buf_getwriteptr(const buffer* buf, unsigned int len) {
|
||||
|
||||
if (len > BUF_MAX_INCR || buf->pos + len > buf->size) {
|
||||
dropbear_exit("Bad buf_getwriteptr");
|
||||
|
||||
8
buffer.h
8
buffer.h
@@ -44,8 +44,8 @@ buffer * buf_new(unsigned int size);
|
||||
/* Possibly returns a new buffer*, like realloc() */
|
||||
buffer * buf_resize(buffer *buf, unsigned int newsize);
|
||||
void buf_free(buffer* buf);
|
||||
void buf_burn(buffer* buf);
|
||||
buffer* buf_newcopy(buffer* buf);
|
||||
void buf_burn(const buffer* buf);
|
||||
buffer* buf_newcopy(const buffer* buf);
|
||||
void buf_setlen(buffer* buf, unsigned int len);
|
||||
void buf_incrlen(buffer* buf, unsigned int incr);
|
||||
void buf_setpos(buffer* buf, unsigned int pos);
|
||||
@@ -54,8 +54,8 @@ void buf_incrwritepos(buffer* buf, unsigned int incr);
|
||||
unsigned char buf_getbyte(buffer* buf);
|
||||
unsigned char buf_getbool(buffer* buf);
|
||||
void buf_putbyte(buffer* buf, unsigned char val);
|
||||
unsigned char* buf_getptr(buffer* buf, unsigned int len);
|
||||
unsigned char* buf_getwriteptr(buffer* buf, unsigned int len);
|
||||
unsigned char* buf_getptr(const buffer* buf, unsigned int len);
|
||||
unsigned char* buf_getwriteptr(const buffer* buf, unsigned int len);
|
||||
char* buf_getstring(buffer* buf, unsigned int *retlen);
|
||||
buffer * buf_getstringbuf(buffer *buf);
|
||||
void buf_eatstring(buffer *buf);
|
||||
|
||||
20
channel.h
20
channel.h
@@ -84,7 +84,7 @@ struct Channel {
|
||||
int flushing;
|
||||
|
||||
/* Used by client chansession to handle ~ escaping, NULL ignored otherwise */
|
||||
void (*read_mangler)(struct Channel*, unsigned char* bytes, int *len);
|
||||
void (*read_mangler)(const struct Channel*, const unsigned char* bytes, int *len);
|
||||
|
||||
const struct ChanType* type;
|
||||
|
||||
@@ -94,11 +94,11 @@ struct Channel {
|
||||
struct ChanType {
|
||||
|
||||
int sepfds; /* Whether this channel has separate pipes for in/out or not */
|
||||
char *name;
|
||||
const char *name;
|
||||
int (*inithandler)(struct Channel*);
|
||||
int (*check_close)(struct Channel*);
|
||||
int (*check_close)(const struct Channel*);
|
||||
void (*reqhandler)(struct Channel*);
|
||||
void (*closehandler)(struct Channel*);
|
||||
void (*closehandler)(const struct Channel*);
|
||||
};
|
||||
|
||||
/* Callback for connect_remote */
|
||||
@@ -107,7 +107,7 @@ void channel_connect_done(int result, int sock, void* user_data, const char* err
|
||||
void chaninitialise(const struct ChanType *chantypes[]);
|
||||
void chancleanup(void);
|
||||
void setchannelfds(fd_set *readfds, fd_set *writefds, int allow_reads);
|
||||
void channelio(fd_set *readfd, fd_set *writefd);
|
||||
void channelio(const fd_set *readfd, const fd_set *writefd);
|
||||
struct Channel* getchannel(void);
|
||||
/* Returns an arbitrary channel that is in a ready state - not
|
||||
being initialised and no EOF in either direction. NULL if none. */
|
||||
@@ -115,8 +115,8 @@ struct Channel* get_any_ready_channel(void);
|
||||
|
||||
void recv_msg_channel_open(void);
|
||||
void recv_msg_channel_request(void);
|
||||
void send_msg_channel_failure(struct Channel *channel);
|
||||
void send_msg_channel_success(struct Channel *channel);
|
||||
void send_msg_channel_failure(const struct Channel *channel);
|
||||
void send_msg_channel_success(const struct Channel *channel);
|
||||
void recv_msg_channel_data(void);
|
||||
void recv_msg_channel_extended_data(void);
|
||||
void recv_msg_channel_window_adjust(void);
|
||||
@@ -126,16 +126,16 @@ void recv_msg_channel_eof(void);
|
||||
void common_recv_msg_channel_data(struct Channel *channel, int fd,
|
||||
circbuffer * buf);
|
||||
|
||||
#ifdef DROPBEAR_CLIENT
|
||||
#if DROPBEAR_CLIENT
|
||||
extern const struct ChanType clichansess;
|
||||
#endif
|
||||
|
||||
#if defined(USING_LISTENERS) || defined(DROPBEAR_CLIENT)
|
||||
#if DROPBEAR_LISTENERS || DROPBEAR_CLIENT
|
||||
int send_msg_channel_open_init(int fd, const struct ChanType *type);
|
||||
void recv_msg_channel_open_confirmation(void);
|
||||
void recv_msg_channel_open_failure(void);
|
||||
#endif
|
||||
void start_send_channel_request(struct Channel *channel, char *type);
|
||||
void start_send_channel_request(const struct Channel *channel, const char *type);
|
||||
|
||||
void send_msg_request_success(void);
|
||||
void send_msg_request_failure(void);
|
||||
|
||||
@@ -58,7 +58,7 @@ struct ChanSess {
|
||||
/* Used to set $SSH_CLIENT in the child session. */
|
||||
char *client_string;
|
||||
|
||||
#ifndef DISABLE_X11FWD
|
||||
#if DROPBEAR_X11FWD
|
||||
struct Listener * x11listener;
|
||||
int x11port;
|
||||
char * x11authprot;
|
||||
@@ -67,13 +67,13 @@ struct ChanSess {
|
||||
unsigned char x11singleconn;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_SVR_AGENTFWD
|
||||
#if DROPBEAR_SVR_AGENTFWD
|
||||
struct Listener * agentlistener;
|
||||
char * agentfile;
|
||||
char * agentdir;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_SVR_PUBKEY_OPTIONS
|
||||
#if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT
|
||||
char *original_command;
|
||||
#endif
|
||||
};
|
||||
@@ -89,11 +89,12 @@ void addnewvar(const char* param, const char* var);
|
||||
void cli_send_chansess_request(void);
|
||||
void cli_tty_cleanup(void);
|
||||
void cli_chansess_winchange(void);
|
||||
#ifdef ENABLE_CLI_NETCAT
|
||||
#if DROPBEAR_CLI_NETCAT
|
||||
void cli_send_netcat_request(void);
|
||||
#endif
|
||||
|
||||
void svr_chansessinitialise(void);
|
||||
void svr_chansess_checksignal(void);
|
||||
extern const struct ChanType svrchansess;
|
||||
|
||||
struct SigMap {
|
||||
|
||||
@@ -56,19 +56,19 @@ void cbuf_free(circbuffer * cbuf) {
|
||||
m_free(cbuf);
|
||||
}
|
||||
|
||||
unsigned int cbuf_getused(circbuffer * cbuf) {
|
||||
unsigned int cbuf_getused(const circbuffer * cbuf) {
|
||||
|
||||
return cbuf->used;
|
||||
|
||||
}
|
||||
|
||||
unsigned int cbuf_getavail(circbuffer * cbuf) {
|
||||
unsigned int cbuf_getavail(const circbuffer * cbuf) {
|
||||
|
||||
return cbuf->size - cbuf->used;
|
||||
|
||||
}
|
||||
|
||||
unsigned int cbuf_writelen(circbuffer *cbuf) {
|
||||
unsigned int cbuf_writelen(const circbuffer *cbuf) {
|
||||
|
||||
dropbear_assert(cbuf->used <= cbuf->size);
|
||||
dropbear_assert(((2*cbuf->size)+cbuf->writepos-cbuf->readpos)%cbuf->size == cbuf->used%cbuf->size);
|
||||
@@ -86,7 +86,7 @@ unsigned int cbuf_writelen(circbuffer *cbuf) {
|
||||
return cbuf->size - cbuf->writepos;
|
||||
}
|
||||
|
||||
void cbuf_readptrs(circbuffer *cbuf,
|
||||
void cbuf_readptrs(const circbuffer *cbuf,
|
||||
unsigned char **p1, unsigned int *len1,
|
||||
unsigned char **p2, unsigned int *len2) {
|
||||
*p1 = &cbuf->data[cbuf->readpos];
|
||||
|
||||
@@ -38,12 +38,12 @@ typedef struct circbuf circbuffer;
|
||||
circbuffer * cbuf_new(unsigned int size);
|
||||
void cbuf_free(circbuffer * cbuf);
|
||||
|
||||
unsigned int cbuf_getused(circbuffer * cbuf); /* how much data stored */
|
||||
unsigned int cbuf_getavail(circbuffer * cbuf); /* how much we can write */
|
||||
unsigned int cbuf_writelen(circbuffer *cbuf); /* max linear write len */
|
||||
unsigned int cbuf_getused(const circbuffer * cbuf); /* how much data stored */
|
||||
unsigned int cbuf_getavail(const circbuffer * cbuf); /* how much we can write */
|
||||
unsigned int cbuf_writelen(const circbuffer *cbuf); /* max linear write len */
|
||||
|
||||
/* returns pointers to the two portions of the circular buffer that can be read */
|
||||
void cbuf_readptrs(circbuffer *cbuf,
|
||||
void cbuf_readptrs(const circbuffer *cbuf,
|
||||
unsigned char **p1, unsigned int *len1,
|
||||
unsigned char **p2, unsigned int *len2);
|
||||
unsigned char* cbuf_writeptr(circbuffer *cbuf, unsigned int len);
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#ifdef ENABLE_CLI_AGENTFWD
|
||||
#if DROPBEAR_CLI_AGENTFWD
|
||||
|
||||
#include "agentfwd.h"
|
||||
#include "session.h"
|
||||
@@ -108,7 +108,7 @@ static int new_agent_chan(struct Channel * channel) {
|
||||
data Any data, depending on packet type. Encoding as in the ssh packet
|
||||
protocol.
|
||||
*/
|
||||
static buffer * agent_request(unsigned char type, buffer *data) {
|
||||
static buffer * agent_request(unsigned char type, const buffer *data) {
|
||||
|
||||
buffer * payload = NULL;
|
||||
buffer * inbuf = NULL;
|
||||
@@ -130,7 +130,7 @@ static buffer * agent_request(unsigned char type, buffer *data) {
|
||||
}
|
||||
buf_setpos(payload, 0);
|
||||
|
||||
ret = atomicio(write, fd, buf_getptr(payload, payload->len), payload->len);
|
||||
ret = atomicio(vwrite, fd, buf_getptr(payload, payload->len), payload->len);
|
||||
if ((size_t)ret != payload->len) {
|
||||
TRACE(("write failed fd %d for agent_request, %s", fd, strerror(errno)))
|
||||
goto out;
|
||||
@@ -230,7 +230,7 @@ out:
|
||||
}
|
||||
}
|
||||
|
||||
void cli_setup_agent(struct Channel *channel) {
|
||||
void cli_setup_agent(const struct Channel *channel) {
|
||||
if (!getenv("SSH_AUTH_SOCK")) {
|
||||
return;
|
||||
}
|
||||
@@ -254,7 +254,7 @@ void cli_load_agent_keys(m_list *ret_list) {
|
||||
}
|
||||
|
||||
void agent_buf_sign(buffer *sigblob, sign_key *key,
|
||||
buffer *data_buf) {
|
||||
const buffer *data_buf) {
|
||||
buffer *request_data = NULL;
|
||||
buffer *response = NULL;
|
||||
unsigned int siglen;
|
||||
|
||||
66
cli-auth.c
66
cli-auth.c
@@ -51,7 +51,7 @@ void cli_auth_getmethods() {
|
||||
|
||||
encrypt_packet();
|
||||
|
||||
#ifdef DROPBEAR_CLI_IMMEDIATE_AUTH
|
||||
#if DROPBEAR_CLI_IMMEDIATE_AUTH
|
||||
/* We can't haven't two auth requests in-flight with delayed zlib mode
|
||||
since if the first one succeeds then the remote side will
|
||||
expect the second one to be compressed.
|
||||
@@ -60,9 +60,11 @@ void cli_auth_getmethods() {
|
||||
*/
|
||||
if (ses.keys->trans.algo_comp != DROPBEAR_COMP_ZLIB_DELAY) {
|
||||
ses.authstate.authtypes = AUTH_TYPE_PUBKEY;
|
||||
#if DROPBEAR_USE_PASSWORD_ENV
|
||||
if (getenv(DROPBEAR_PASSWORD_ENV)) {
|
||||
ses.authstate.authtypes |= AUTH_TYPE_PASSWORD | AUTH_TYPE_INTERACT;
|
||||
}
|
||||
#endif
|
||||
if (cli_auth_try() == DROPBEAR_SUCCESS) {
|
||||
TRACE(("skipped initial none auth query"))
|
||||
/* Note that there will be two auth responses in-flight */
|
||||
@@ -78,6 +80,7 @@ void recv_msg_userauth_banner() {
|
||||
char* banner = NULL;
|
||||
unsigned int bannerlen;
|
||||
unsigned int i, linecount;
|
||||
int truncated = 0;
|
||||
|
||||
TRACE(("enter recv_msg_userauth_banner"))
|
||||
if (ses.authstate.authdone) {
|
||||
@@ -90,26 +93,29 @@ void recv_msg_userauth_banner() {
|
||||
|
||||
if (bannerlen > MAX_BANNER_SIZE) {
|
||||
TRACE(("recv_msg_userauth_banner: bannerlen too long: %d", bannerlen))
|
||||
goto out;
|
||||
}
|
||||
truncated = 1;
|
||||
} else {
|
||||
cleantext(banner);
|
||||
|
||||
cleantext(banner);
|
||||
|
||||
/* Limit to 25 lines */
|
||||
linecount = 1;
|
||||
for (i = 0; i < bannerlen; i++) {
|
||||
if (banner[i] == '\n') {
|
||||
if (linecount >= MAX_BANNER_LINES) {
|
||||
banner[i] = '\0';
|
||||
break;
|
||||
/* Limit to 24 lines */
|
||||
linecount = 1;
|
||||
for (i = 0; i < bannerlen; i++) {
|
||||
if (banner[i] == '\n') {
|
||||
if (linecount >= MAX_BANNER_LINES) {
|
||||
banner[i] = '\0';
|
||||
truncated = 1;
|
||||
break;
|
||||
}
|
||||
linecount++;
|
||||
}
|
||||
linecount++;
|
||||
}
|
||||
fprintf(stderr, "%s\n", banner);
|
||||
}
|
||||
|
||||
fprintf(stderr, "%s\n", banner);
|
||||
if (truncated) {
|
||||
fprintf(stderr, "[Banner from the server is too long]\n");
|
||||
}
|
||||
|
||||
out:
|
||||
m_free(banner);
|
||||
TRACE(("leave recv_msg_userauth_banner"))
|
||||
}
|
||||
@@ -121,21 +127,21 @@ out:
|
||||
* SSH_MSG_USERAUTH_INFO_REQUEST. */
|
||||
void recv_msg_userauth_specific_60() {
|
||||
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
if (cli_ses.lastauthtype == AUTH_TYPE_PUBKEY) {
|
||||
recv_msg_userauth_pk_ok();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_CLI_INTERACT_AUTH
|
||||
#if DROPBEAR_CLI_INTERACT_AUTH
|
||||
if (cli_ses.lastauthtype == AUTH_TYPE_INTERACT) {
|
||||
recv_msg_userauth_info_request();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_CLI_PASSWORD_AUTH
|
||||
#if DROPBEAR_CLI_PASSWORD_AUTH
|
||||
if (cli_ses.lastauthtype == AUTH_TYPE_PASSWORD) {
|
||||
/* Eventually there could be proper password-changing
|
||||
* support. However currently few servers seem to
|
||||
@@ -179,7 +185,7 @@ void recv_msg_userauth_failure() {
|
||||
TRACE(("leave recv_msg_userauth_failure, ignored response, state set to USERAUTH_REQ_SENT"));
|
||||
return;
|
||||
} else {
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
/* If it was a pubkey auth request, we should cross that key
|
||||
* off the list. */
|
||||
if (cli_ses.lastauthtype == AUTH_TYPE_PUBKEY) {
|
||||
@@ -187,7 +193,7 @@ void recv_msg_userauth_failure() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_CLI_INTERACT_AUTH
|
||||
#if DROPBEAR_CLI_INTERACT_AUTH
|
||||
/* If we get a failure message for keyboard interactive without
|
||||
* receiving any request info packet, then we don't bother trying
|
||||
* keyboard interactive again */
|
||||
@@ -227,19 +233,19 @@ void recv_msg_userauth_failure() {
|
||||
for (i = 0; i <= methlen; i++) {
|
||||
if (methods[i] == '\0') {
|
||||
TRACE(("auth method '%s'", tok))
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
if (strncmp(AUTH_METHOD_PUBKEY, tok,
|
||||
AUTH_METHOD_PUBKEY_LEN) == 0) {
|
||||
ses.authstate.authtypes |= AUTH_TYPE_PUBKEY;
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_INTERACT_AUTH
|
||||
#if DROPBEAR_CLI_INTERACT_AUTH
|
||||
if (strncmp(AUTH_METHOD_INTERACT, tok,
|
||||
AUTH_METHOD_INTERACT_LEN) == 0) {
|
||||
ses.authstate.authtypes |= AUTH_TYPE_INTERACT;
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_PASSWORD_AUTH
|
||||
#if DROPBEAR_CLI_PASSWORD_AUTH
|
||||
if (strncmp(AUTH_METHOD_PASSWORD, tok,
|
||||
AUTH_METHOD_PASSWORD_LEN) == 0) {
|
||||
ses.authstate.authtypes |= AUTH_TYPE_PASSWORD;
|
||||
@@ -267,7 +273,7 @@ void recv_msg_userauth_success() {
|
||||
cli_ses.state = USERAUTH_SUCCESS_RCVD;
|
||||
cli_ses.lastauthtype = AUTH_TYPE_NONE;
|
||||
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
cli_auth_pubkey_cleanup();
|
||||
#endif
|
||||
}
|
||||
@@ -281,14 +287,14 @@ int cli_auth_try() {
|
||||
|
||||
/* Order to try is pubkey, interactive, password.
|
||||
* As soon as "finished" is set for one, we don't do any more. */
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
if (ses.authstate.authtypes & AUTH_TYPE_PUBKEY) {
|
||||
finished = cli_auth_pubkey();
|
||||
cli_ses.lastauthtype = AUTH_TYPE_PUBKEY;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_CLI_PASSWORD_AUTH
|
||||
#if DROPBEAR_CLI_PASSWORD_AUTH
|
||||
if (!finished && (ses.authstate.authtypes & AUTH_TYPE_PASSWORD)) {
|
||||
if (ses.keys->trans.algo_crypt->cipherdesc == NULL) {
|
||||
fprintf(stderr, "Sorry, I won't let you use password auth unencrypted.\n");
|
||||
@@ -300,7 +306,7 @@ int cli_auth_try() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_CLI_INTERACT_AUTH
|
||||
#if DROPBEAR_CLI_INTERACT_AUTH
|
||||
if (!finished && (ses.authstate.authtypes & AUTH_TYPE_INTERACT)) {
|
||||
if (ses.keys->trans.algo_crypt->cipherdesc == NULL) {
|
||||
fprintf(stderr, "Sorry, I won't let you use interactive auth unencrypted.\n");
|
||||
@@ -324,14 +330,14 @@ int cli_auth_try() {
|
||||
return DROPBEAR_FAILURE;
|
||||
}
|
||||
|
||||
#if defined(ENABLE_CLI_PASSWORD_AUTH) || defined(ENABLE_CLI_INTERACT_AUTH)
|
||||
#if DROPBEAR_CLI_PASSWORD_AUTH || DROPBEAR_CLI_INTERACT_AUTH
|
||||
/* A helper for getpass() that exits if the user cancels. The returned
|
||||
* password is statically allocated by getpass() */
|
||||
char* getpass_or_cancel(char* prompt)
|
||||
char* getpass_or_cancel(const char* prompt)
|
||||
{
|
||||
char* password = NULL;
|
||||
|
||||
#ifdef DROPBEAR_PASSWORD_ENV
|
||||
#if DROPBEAR_USE_PASSWORD_ENV
|
||||
/* Password provided in an environment var */
|
||||
password = getenv(DROPBEAR_PASSWORD_ENV);
|
||||
if (password)
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "ssh.h"
|
||||
#include "runopts.h"
|
||||
|
||||
#ifdef ENABLE_CLI_INTERACT_AUTH
|
||||
#if DROPBEAR_CLI_INTERACT_AUTH
|
||||
|
||||
static char* get_response(char* prompt)
|
||||
{
|
||||
@@ -172,4 +172,4 @@ void cli_auth_interactive() {
|
||||
TRACE(("leave cli_auth_interactive"))
|
||||
|
||||
}
|
||||
#endif /* ENABLE_CLI_INTERACT_AUTH */
|
||||
#endif /* DROPBEAR_CLI_INTERACT_AUTH */
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
#include "ssh.h"
|
||||
#include "runopts.h"
|
||||
|
||||
#ifdef ENABLE_CLI_PASSWORD_AUTH
|
||||
#if DROPBEAR_CLI_PASSWORD_AUTH
|
||||
|
||||
#ifdef ENABLE_CLI_ASKPASS_HELPER
|
||||
#if DROPBEAR_CLI_ASKPASS_HELPER
|
||||
/* Returns 1 if we want to use the askpass program, 0 otherwise */
|
||||
static int want_askpass()
|
||||
{
|
||||
@@ -113,7 +113,7 @@ static char *gui_getpass(const char *prompt) {
|
||||
TRACE(("leave gui_getpass"))
|
||||
return(buf);
|
||||
}
|
||||
#endif /* ENABLE_CLI_ASKPASS_HELPER */
|
||||
#endif /* DROPBEAR_CLI_ASKPASS_HELPER */
|
||||
|
||||
void cli_auth_password() {
|
||||
|
||||
@@ -125,7 +125,7 @@ void cli_auth_password() {
|
||||
|
||||
snprintf(prompt, sizeof(prompt), "%s@%s's password: ",
|
||||
cli_opts.username, cli_opts.remotehost);
|
||||
#ifdef ENABLE_CLI_ASKPASS_HELPER
|
||||
#if DROPBEAR_CLI_ASKPASS_HELPER
|
||||
if (want_askpass())
|
||||
{
|
||||
password = gui_getpass(prompt);
|
||||
@@ -158,4 +158,4 @@ void cli_auth_password() {
|
||||
|
||||
TRACE(("leave cli_auth_password"))
|
||||
}
|
||||
#endif /* ENABLE_CLI_PASSWORD_AUTH */
|
||||
#endif /* DROPBEAR_CLI_PASSWORD_AUTH */
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "auth.h"
|
||||
#include "agentfwd.h"
|
||||
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
static void send_msg_userauth_pubkey(sign_key *key, int type, int realsign);
|
||||
|
||||
/* Called when we receive a SSH_MSG_USERAUTH_FAILURE for a pubkey request.
|
||||
@@ -121,8 +121,8 @@ void recv_msg_userauth_pk_ok() {
|
||||
}
|
||||
|
||||
void cli_buf_put_sign(buffer* buf, sign_key *key, int type,
|
||||
buffer *data_buf) {
|
||||
#ifdef ENABLE_CLI_AGENTFWD
|
||||
const buffer *data_buf) {
|
||||
#if DROPBEAR_CLI_AGENTFWD
|
||||
if (key->source == SIGNKEY_SOURCE_AGENT) {
|
||||
/* Format the agent signature ourselves, as buf_put_sign would. */
|
||||
buffer *sigblob;
|
||||
@@ -131,7 +131,7 @@ void cli_buf_put_sign(buffer* buf, sign_key *key, int type,
|
||||
buf_putbufstring(buf, sigblob);
|
||||
buf_free(sigblob);
|
||||
} else
|
||||
#endif /* ENABLE_CLI_AGENTFWD */
|
||||
#endif /* DROPBEAR_CLI_AGENTFWD */
|
||||
{
|
||||
buf_put_sign(buf, key, type, data_buf);
|
||||
}
|
||||
@@ -185,7 +185,7 @@ int cli_auth_pubkey() {
|
||||
|
||||
TRACE(("enter cli_auth_pubkey"))
|
||||
|
||||
#ifdef ENABLE_CLI_AGENTFWD
|
||||
#if DROPBEAR_CLI_AGENTFWD
|
||||
if (!cli_opts.agent_keys_loaded) {
|
||||
/* get the list of available keys from the agent */
|
||||
cli_load_agent_keys(cli_opts.privkeys);
|
||||
@@ -209,7 +209,7 @@ int cli_auth_pubkey() {
|
||||
|
||||
void cli_auth_pubkey_cleanup() {
|
||||
|
||||
#ifdef ENABLE_CLI_AGENTFWD
|
||||
#if DROPBEAR_CLI_AGENTFWD
|
||||
m_close(cli_opts.agent_fd);
|
||||
cli_opts.agent_fd = -1;
|
||||
#endif
|
||||
|
||||
@@ -35,12 +35,12 @@
|
||||
#include "chansession.h"
|
||||
#include "agentfwd.h"
|
||||
|
||||
static void cli_closechansess(struct Channel *channel);
|
||||
static void cli_closechansess(const struct Channel *channel);
|
||||
static int cli_initchansess(struct Channel *channel);
|
||||
static void cli_chansessreq(struct Channel *channel);
|
||||
static void send_chansess_pty_req(struct Channel *channel);
|
||||
static void send_chansess_shell_req(struct Channel *channel);
|
||||
static void cli_escape_handler(struct Channel *channel, unsigned char* buf, int *len);
|
||||
static void send_chansess_pty_req(const struct Channel *channel);
|
||||
static void send_chansess_shell_req(const struct Channel *channel);
|
||||
static void cli_escape_handler(const struct Channel *channel, const unsigned char* buf, int *len);
|
||||
static int cli_init_netcat(struct Channel *channel);
|
||||
|
||||
static void cli_tty_setup(void);
|
||||
@@ -83,7 +83,7 @@ out:
|
||||
|
||||
|
||||
/* If the main session goes, we close it up */
|
||||
static void cli_closechansess(struct Channel *UNUSED(channel)) {
|
||||
static void cli_closechansess(const struct Channel *UNUSED(channel)) {
|
||||
cli_tty_cleanup(); /* Restore tty modes etc */
|
||||
|
||||
/* This channel hasn't gone yet, so we have > 1 */
|
||||
@@ -270,7 +270,7 @@ void cli_chansess_winchange() {
|
||||
cli_ses.winchange = 0;
|
||||
}
|
||||
|
||||
static void send_chansess_pty_req(struct Channel *channel) {
|
||||
static void send_chansess_pty_req(const struct Channel *channel) {
|
||||
|
||||
char* term = NULL;
|
||||
|
||||
@@ -303,7 +303,7 @@ static void send_chansess_pty_req(struct Channel *channel) {
|
||||
TRACE(("leave send_chansess_pty_req"))
|
||||
}
|
||||
|
||||
static void send_chansess_shell_req(struct Channel *channel) {
|
||||
static void send_chansess_shell_req(const struct Channel *channel) {
|
||||
|
||||
char* reqtype = NULL;
|
||||
|
||||
@@ -355,7 +355,7 @@ static int cli_initchansess(struct Channel *channel) {
|
||||
|
||||
cli_init_stdpipe_sess(channel);
|
||||
|
||||
#ifdef ENABLE_CLI_AGENTFWD
|
||||
#if DROPBEAR_CLI_AGENTFWD
|
||||
if (cli_opts.agent_fwd) {
|
||||
cli_setup_agent(channel);
|
||||
}
|
||||
@@ -379,7 +379,7 @@ static int cli_initchansess(struct Channel *channel) {
|
||||
return 0; /* Success */
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLI_NETCAT
|
||||
#if DROPBEAR_CLI_NETCAT
|
||||
|
||||
static const struct ChanType cli_chan_netcat = {
|
||||
0, /* sepfds */
|
||||
@@ -452,7 +452,7 @@ do_escape(unsigned char c) {
|
||||
}
|
||||
|
||||
static
|
||||
void cli_escape_handler(struct Channel* UNUSED(channel), unsigned char* buf, int *len) {
|
||||
void cli_escape_handler(const struct Channel* UNUSED(channel), const unsigned char* buf, int *len) {
|
||||
char c;
|
||||
int skip_char = 0;
|
||||
|
||||
|
||||
30
cli-kex.c
30
cli-kex.c
@@ -39,7 +39,7 @@
|
||||
#include "ecc.h"
|
||||
|
||||
|
||||
static void checkhostkey(unsigned char* keyblob, unsigned int keybloblen);
|
||||
static void checkhostkey(const unsigned char* keyblob, unsigned int keybloblen);
|
||||
#define MAX_KNOWNHOSTS_LINE 4500
|
||||
|
||||
void send_msg_kexdh_init() {
|
||||
@@ -48,6 +48,7 @@ void send_msg_kexdh_init() {
|
||||
CHECKCLEARTOWRITE();
|
||||
buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_INIT);
|
||||
switch (ses.newkeys->algo_kex->mode) {
|
||||
#if DROPBEAR_NORMAL_DH
|
||||
case DROPBEAR_KEX_NORMAL_DH:
|
||||
if (ses.newkeys->algo_kex != cli_ses.param_kex_algo
|
||||
|| !cli_ses.dh_param) {
|
||||
@@ -58,8 +59,9 @@ void send_msg_kexdh_init() {
|
||||
}
|
||||
buf_putmpint(ses.writepayload, &cli_ses.dh_param->pub);
|
||||
break;
|
||||
#endif
|
||||
#if DROPBEAR_ECDH
|
||||
case DROPBEAR_KEX_ECDH:
|
||||
#ifdef DROPBEAR_ECDH
|
||||
if (ses.newkeys->algo_kex != cli_ses.param_kex_algo
|
||||
|| !cli_ses.ecdh_param) {
|
||||
if (cli_ses.ecdh_param) {
|
||||
@@ -68,9 +70,9 @@ void send_msg_kexdh_init() {
|
||||
cli_ses.ecdh_param = gen_kexecdh_param();
|
||||
}
|
||||
buf_put_ecc_raw_pubkey_string(ses.writepayload, &cli_ses.ecdh_param->key);
|
||||
#endif
|
||||
break;
|
||||
#ifdef DROPBEAR_CURVE25519
|
||||
#endif
|
||||
#if DROPBEAR_CURVE25519
|
||||
case DROPBEAR_KEX_CURVE25519:
|
||||
if (ses.newkeys->algo_kex != cli_ses.param_kex_algo
|
||||
|| !cli_ses.curve25519_param) {
|
||||
@@ -80,8 +82,8 @@ void send_msg_kexdh_init() {
|
||||
cli_ses.curve25519_param = gen_kexcurve25519_param();
|
||||
}
|
||||
buf_putstring(ses.writepayload, (const char*)cli_ses.curve25519_param->pub, CURVE25519_LEN);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
cli_ses.param_kex_algo = ses.newkeys->algo_kex;
|
||||
@@ -118,6 +120,7 @@ void recv_msg_kexdh_reply() {
|
||||
}
|
||||
|
||||
switch (ses.newkeys->algo_kex->mode) {
|
||||
#if DROPBEAR_NORMAL_DH
|
||||
case DROPBEAR_KEX_NORMAL_DH:
|
||||
{
|
||||
DEF_MP_INT(dh_f);
|
||||
@@ -131,37 +134,38 @@ void recv_msg_kexdh_reply() {
|
||||
mp_clear(&dh_f);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if DROPBEAR_ECDH
|
||||
case DROPBEAR_KEX_ECDH:
|
||||
#ifdef DROPBEAR_ECDH
|
||||
{
|
||||
buffer *ecdh_qs = buf_getstringbuf(ses.payload);
|
||||
kexecdh_comb_key(cli_ses.ecdh_param, ecdh_qs, hostkey);
|
||||
buf_free(ecdh_qs);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
#ifdef DROPBEAR_CURVE25519
|
||||
#endif
|
||||
#if DROPBEAR_CURVE25519
|
||||
case DROPBEAR_KEX_CURVE25519:
|
||||
{
|
||||
buffer *ecdh_qs = buf_getstringbuf(ses.payload);
|
||||
kexcurve25519_comb_key(cli_ses.curve25519_param, ecdh_qs, hostkey);
|
||||
buf_free(ecdh_qs);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (cli_ses.dh_param) {
|
||||
free_kexdh_param(cli_ses.dh_param);
|
||||
cli_ses.dh_param = NULL;
|
||||
}
|
||||
#ifdef DROPBEAR_ECDH
|
||||
#if DROPBEAR_ECDH
|
||||
if (cli_ses.ecdh_param) {
|
||||
free_kexecdh_param(cli_ses.ecdh_param);
|
||||
cli_ses.ecdh_param = NULL;
|
||||
}
|
||||
#endif
|
||||
#ifdef DROPBEAR_CURVE25519
|
||||
#if DROPBEAR_CURVE25519
|
||||
if (cli_ses.curve25519_param) {
|
||||
free_kexcurve25519_param(cli_ses.curve25519_param);
|
||||
cli_ses.curve25519_param = NULL;
|
||||
@@ -181,7 +185,7 @@ void recv_msg_kexdh_reply() {
|
||||
TRACE(("leave recv_msg_kexdh_init"))
|
||||
}
|
||||
|
||||
static void ask_to_confirm(unsigned char* keyblob, unsigned int keybloblen,
|
||||
static void ask_to_confirm(const unsigned char* keyblob, unsigned int keybloblen,
|
||||
const char* algoname) {
|
||||
|
||||
char* fp = NULL;
|
||||
@@ -278,7 +282,7 @@ out:
|
||||
return hostsfile;
|
||||
}
|
||||
|
||||
static void checkhostkey(unsigned char* keyblob, unsigned int keybloblen) {
|
||||
static void checkhostkey(const unsigned char* keyblob, unsigned int keybloblen) {
|
||||
|
||||
FILE *hostsfile = NULL;
|
||||
int readonly = 0;
|
||||
|
||||
38
cli-main.c
38
cli-main.c
@@ -35,13 +35,13 @@
|
||||
static void cli_dropbear_exit(int exitcode, const char* format, va_list param) ATTRIB_NORETURN;
|
||||
static void cli_dropbear_log(int priority, const char* format, va_list param);
|
||||
|
||||
#ifdef ENABLE_CLI_PROXYCMD
|
||||
#if DROPBEAR_CLI_PROXYCMD
|
||||
static void cli_proxy_cmd(int *sock_in, int *sock_out, pid_t *pid_out);
|
||||
static void kill_proxy_sighandler(int signo);
|
||||
#endif
|
||||
|
||||
#if defined(DBMULTI_dbclient) || !defined(DROPBEAR_MULTI)
|
||||
#if defined(DBMULTI_dbclient) && defined(DROPBEAR_MULTI)
|
||||
#if defined(DBMULTI_dbclient) || !DROPBEAR_MULTI
|
||||
#if defined(DBMULTI_dbclient) && DROPBEAR_MULTI
|
||||
int cli_main(int argc, char ** argv) {
|
||||
#else
|
||||
int main(int argc, char ** argv) {
|
||||
@@ -66,15 +66,15 @@ int main(int argc, char ** argv) {
|
||||
}
|
||||
#endif
|
||||
|
||||
TRACE(("user='%s' host='%s' port='%s'", cli_opts.username,
|
||||
cli_opts.remotehost, cli_opts.remoteport))
|
||||
TRACE(("user='%s' host='%s' port='%s' bind_address='%s' bind_port='%s'", cli_opts.username,
|
||||
cli_opts.remotehost, cli_opts.remoteport, cli_opts.bind_address, cli_opts.bind_port))
|
||||
|
||||
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
|
||||
dropbear_exit("signal() error");
|
||||
}
|
||||
|
||||
pid_t proxy_cmd_pid = 0;
|
||||
#ifdef ENABLE_CLI_PROXYCMD
|
||||
#if DROPBEAR_CLI_PROXYCMD
|
||||
if (cli_opts.proxycmd) {
|
||||
cli_proxy_cmd(&sock_in, &sock_out, &proxy_cmd_pid);
|
||||
m_free(cli_opts.proxycmd);
|
||||
@@ -86,7 +86,8 @@ int main(int argc, char ** argv) {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
progress = connect_remote(cli_opts.remotehost, cli_opts.remoteport, cli_connected, &ses);
|
||||
progress = connect_remote(cli_opts.remotehost, cli_opts.remoteport,
|
||||
cli_connected, &ses, cli_opts.bind_address, cli_opts.bind_port);
|
||||
sock_in = sock_out = -1;
|
||||
}
|
||||
|
||||
@@ -107,7 +108,7 @@ static void cli_dropbear_exit(int exitcode, const char* format, va_list param) {
|
||||
vsnprintf(exitmsg, sizeof(exitmsg), format, param);
|
||||
|
||||
/* Add the prefix depending on session/auth state */
|
||||
if (!sessinitdone) {
|
||||
if (!ses.init_done) {
|
||||
snprintf(fullmsg, sizeof(fullmsg), "Exited: %s", exitmsg);
|
||||
} else {
|
||||
snprintf(fullmsg, sizeof(fullmsg),
|
||||
@@ -142,7 +143,7 @@ static void cli_dropbear_log(int priority,
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
static void exec_proxy_cmd(void *user_data_cmd) {
|
||||
static void exec_proxy_cmd(const void *user_data_cmd) {
|
||||
const char *cmd = user_data_cmd;
|
||||
char *usershell;
|
||||
|
||||
@@ -151,12 +152,27 @@ static void exec_proxy_cmd(void *user_data_cmd) {
|
||||
dropbear_exit("Failed to run '%s'\n", cmd);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLI_PROXYCMD
|
||||
#if DROPBEAR_CLI_PROXYCMD
|
||||
static void cli_proxy_cmd(int *sock_in, int *sock_out, pid_t *pid_out) {
|
||||
char * ex_cmd = NULL;
|
||||
size_t ex_cmdlen;
|
||||
int ret;
|
||||
|
||||
/* File descriptor "-j &3" */
|
||||
if (*cli_opts.proxycmd == '&') {
|
||||
char *p = cli_opts.proxycmd + 1;
|
||||
int sock = strtoul(p, &p, 10);
|
||||
/* must be a single number, and not stdin/stdout/stderr */
|
||||
if (sock > 2 && sock < 1024 && *p == '\0') {
|
||||
*sock_in = sock;
|
||||
*sock_out = sock;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Normal proxycommand */
|
||||
|
||||
/* So that spawn_command knows which shell to run */
|
||||
fill_passwd(cli_opts.own_user);
|
||||
|
||||
ex_cmdlen = strlen(cli_opts.proxycmd) + 6; /* "exec " + command + '\0' */
|
||||
@@ -176,4 +192,4 @@ static void kill_proxy_sighandler(int UNUSED(signo)) {
|
||||
kill_proxy_command();
|
||||
_exit(1);
|
||||
}
|
||||
#endif /* ENABLE_CLI_PROXYCMD */
|
||||
#endif /* DROPBEAR_CLI_PROXYCMD */
|
||||
|
||||
133
cli-runopts.c
133
cli-runopts.c
@@ -37,13 +37,13 @@ static void printhelp(void);
|
||||
static void parse_hostname(const char* orighostarg);
|
||||
static void parse_multihop_hostname(const char* orighostarg, const char* argv0);
|
||||
static void fill_own_user(void);
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
static void loadidentityfile(const char* filename, int warnfail);
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_ANYTCPFWD
|
||||
#if DROPBEAR_CLI_ANYTCPFWD
|
||||
static void addforward(const char* str, m_list *fwdlist);
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_NETCAT
|
||||
#if DROPBEAR_CLI_NETCAT
|
||||
static void add_netcat(const char *str);
|
||||
#endif
|
||||
static void add_extendedopt(const char *str);
|
||||
@@ -51,7 +51,7 @@ static void add_extendedopt(const char *str);
|
||||
static void printhelp() {
|
||||
|
||||
fprintf(stderr, "Dropbear SSH client v%s https://matt.ucc.asn.au/dropbear/dropbear.html\n"
|
||||
#ifdef ENABLE_CLI_MULTIHOP
|
||||
#if DROPBEAR_CLI_MULTIHOP
|
||||
"Usage: %s [options] [user@]host[/port][,[user@]host/port],...] [command]\n"
|
||||
#else
|
||||
"Usage: %s [options] [user@]host[/port] [command]\n"
|
||||
@@ -66,38 +66,39 @@ static void printhelp() {
|
||||
"-y -y Don't perform any remote host key checking (caution)\n"
|
||||
"-s Request a subsystem (use by external sftp)\n"
|
||||
"-o option Set option in OpenSSH-like format ('-o help' to list options)\n"
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
"-i <identityfile> (multiple allowed, default %s)\n"
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_AGENTFWD
|
||||
#if DROPBEAR_CLI_AGENTFWD
|
||||
"-A Enable agent auth forwarding\n"
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_LOCALTCPFWD
|
||||
#if DROPBEAR_CLI_LOCALTCPFWD
|
||||
"-L <[listenaddress:]listenport:remotehost:remoteport> Local port forwarding\n"
|
||||
"-g Allow remote hosts to connect to forwarded ports\n"
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_REMOTETCPFWD
|
||||
#if DROPBEAR_CLI_REMOTETCPFWD
|
||||
"-R <[listenaddress:]listenport:remotehost:remoteport> Remote port forwarding\n"
|
||||
#endif
|
||||
"-W <receive_window_buffer> (default %d, larger may be faster, max 1MB)\n"
|
||||
"-K <keepalive> (0 is never, default %d)\n"
|
||||
"-I <idle_timeout> (0 is never, default %d)\n"
|
||||
#ifdef ENABLE_CLI_NETCAT
|
||||
#if DROPBEAR_CLI_NETCAT
|
||||
"-B <endhost:endport> Netcat-alike forwarding\n"
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_PROXYCMD
|
||||
#if DROPBEAR_CLI_PROXYCMD
|
||||
"-J <proxy_program> Use program pipe rather than TCP connection\n"
|
||||
#endif
|
||||
#ifdef ENABLE_USER_ALGO_LIST
|
||||
#if DROPBEAR_USER_ALGO_LIST
|
||||
"-c <cipher list> Specify preferred ciphers ('-c help' to list options)\n"
|
||||
"-m <MAC list> Specify preferred MACs for packet verification (or '-m help')\n"
|
||||
#endif
|
||||
"-b [bind_address][:bind_port]\n"
|
||||
"-V Version\n"
|
||||
#ifdef DEBUG_TRACE
|
||||
#if DEBUG_TRACE
|
||||
"-v verbose (compiled with DEBUG_TRACE)\n"
|
||||
#endif
|
||||
,DROPBEAR_VERSION, cli_opts.progname,
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
DROPBEAR_DEFAULT_CLI_AUTHKEY,
|
||||
#endif
|
||||
DEFAULT_RECV_WINDOW, DEFAULT_KEEPALIVE, DEFAULT_IDLE_TIMEOUT);
|
||||
@@ -106,31 +107,31 @@ static void printhelp() {
|
||||
|
||||
void cli_getopts(int argc, char ** argv) {
|
||||
unsigned int i, j;
|
||||
char ** next = 0;
|
||||
char ** next = NULL;
|
||||
enum {
|
||||
OPT_EXTENDED_OPTIONS,
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
OPT_AUTHKEY,
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_LOCALTCPFWD
|
||||
#if DROPBEAR_CLI_LOCALTCPFWD
|
||||
OPT_LOCALTCPFWD,
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_REMOTETCPFWD
|
||||
#if DROPBEAR_CLI_REMOTETCPFWD
|
||||
OPT_REMOTETCPFWD,
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_NETCAT
|
||||
#if DROPBEAR_CLI_NETCAT
|
||||
OPT_NETCAT,
|
||||
#endif
|
||||
/* a flag (no arg) if 'next' is NULL, a string-valued option otherwise */
|
||||
OPT_OTHER
|
||||
} opt;
|
||||
unsigned int cmdlen;
|
||||
char* dummy = NULL; /* Not used for anything real */
|
||||
|
||||
char* recv_window_arg = NULL;
|
||||
char* keepalive_arg = NULL;
|
||||
char* idle_timeout_arg = NULL;
|
||||
char *host_arg = NULL;
|
||||
char *bind_arg = NULL;
|
||||
char c;
|
||||
|
||||
/* see printhelp() for options */
|
||||
@@ -145,31 +146,33 @@ void cli_getopts(int argc, char ** argv) {
|
||||
cli_opts.always_accept_key = 0;
|
||||
cli_opts.no_hostkey_check = 0;
|
||||
cli_opts.is_subsystem = 0;
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
cli_opts.privkeys = list_new();
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_ANYTCPFWD
|
||||
#if DROPBEAR_CLI_ANYTCPFWD
|
||||
cli_opts.exit_on_fwd_failure = 0;
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_LOCALTCPFWD
|
||||
#if DROPBEAR_CLI_LOCALTCPFWD
|
||||
cli_opts.localfwds = list_new();
|
||||
opts.listen_fwd_all = 0;
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_REMOTETCPFWD
|
||||
#if DROPBEAR_CLI_REMOTETCPFWD
|
||||
cli_opts.remotefwds = list_new();
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_AGENTFWD
|
||||
#if DROPBEAR_CLI_AGENTFWD
|
||||
cli_opts.agent_fwd = 0;
|
||||
cli_opts.agent_fd = -1;
|
||||
cli_opts.agent_keys_loaded = 0;
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_PROXYCMD
|
||||
#if DROPBEAR_CLI_PROXYCMD
|
||||
cli_opts.proxycmd = NULL;
|
||||
#endif
|
||||
cli_opts.bind_address = NULL;
|
||||
cli_opts.bind_port = NULL;
|
||||
#ifndef DISABLE_ZLIB
|
||||
opts.compress_mode = DROPBEAR_COMPRESS_ON;
|
||||
#endif
|
||||
#ifdef ENABLE_USER_ALGO_LIST
|
||||
#if DROPBEAR_USER_ALGO_LIST
|
||||
opts.cipher_list = NULL;
|
||||
opts.mac_list = NULL;
|
||||
#endif
|
||||
@@ -213,7 +216,7 @@ void cli_getopts(int argc, char ** argv) {
|
||||
case 'p': /* remoteport */
|
||||
next = &cli_opts.remoteport;
|
||||
break;
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
case 'i': /* an identityfile */
|
||||
opt = OPT_AUTHKEY;
|
||||
break;
|
||||
@@ -236,7 +239,7 @@ void cli_getopts(int argc, char ** argv) {
|
||||
case 'o':
|
||||
opt = OPT_EXTENDED_OPTIONS;
|
||||
break;
|
||||
#ifdef ENABLE_CLI_LOCALTCPFWD
|
||||
#if DROPBEAR_CLI_LOCALTCPFWD
|
||||
case 'L':
|
||||
opt = OPT_LOCALTCPFWD;
|
||||
break;
|
||||
@@ -244,17 +247,17 @@ void cli_getopts(int argc, char ** argv) {
|
||||
opts.listen_fwd_all = 1;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_REMOTETCPFWD
|
||||
#if DROPBEAR_CLI_REMOTETCPFWD
|
||||
case 'R':
|
||||
opt = OPT_REMOTETCPFWD;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_NETCAT
|
||||
#if DROPBEAR_CLI_NETCAT
|
||||
case 'B':
|
||||
opt = OPT_NETCAT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_PROXYCMD
|
||||
#if DROPBEAR_CLI_PROXYCMD
|
||||
case 'J':
|
||||
next = &cli_opts.proxycmd;
|
||||
break;
|
||||
@@ -278,12 +281,12 @@ void cli_getopts(int argc, char ** argv) {
|
||||
case 'I':
|
||||
next = &idle_timeout_arg;
|
||||
break;
|
||||
#ifdef ENABLE_CLI_AGENTFWD
|
||||
#if DROPBEAR_CLI_AGENTFWD
|
||||
case 'A':
|
||||
cli_opts.agent_fwd = 1;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ENABLE_USER_ALGO_LIST
|
||||
#if DROPBEAR_USER_ALGO_LIST
|
||||
case 'c':
|
||||
next = &opts.cipher_list;
|
||||
break;
|
||||
@@ -291,22 +294,22 @@ void cli_getopts(int argc, char ** argv) {
|
||||
next = &opts.mac_list;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DEBUG_TRACE
|
||||
#if DEBUG_TRACE
|
||||
case 'v':
|
||||
debug_trace = 1;
|
||||
break;
|
||||
#endif
|
||||
case 'F':
|
||||
case 'e':
|
||||
#ifndef ENABLE_USER_ALGO_LIST
|
||||
#if !DROPBEAR_USER_ALGO_LIST
|
||||
case 'c':
|
||||
case 'm':
|
||||
#endif
|
||||
case 'D':
|
||||
#ifndef ENABLE_CLI_REMOTETCPFWD
|
||||
#if !DROPBEAR_CLI_REMOTETCPFWD
|
||||
case 'R':
|
||||
#endif
|
||||
#ifndef ENABLE_CLI_LOCALTCPFWD
|
||||
#if !DROPBEAR_CLI_LOCALTCPFWD
|
||||
case 'L':
|
||||
#endif
|
||||
case 'V':
|
||||
@@ -314,8 +317,8 @@ void cli_getopts(int argc, char ** argv) {
|
||||
exit(EXIT_SUCCESS);
|
||||
break;
|
||||
case 'b':
|
||||
next = &dummy;
|
||||
/* FALLTHROUGH */
|
||||
next = &bind_arg;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"WARNING: Ignoring unknown option -%c\n", c);
|
||||
@@ -338,28 +341,28 @@ void cli_getopts(int argc, char ** argv) {
|
||||
add_extendedopt(&argv[i][j]);
|
||||
}
|
||||
else
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
if (opt == OPT_AUTHKEY) {
|
||||
TRACE(("opt authkey"))
|
||||
loadidentityfile(&argv[i][j], 1);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_REMOTETCPFWD
|
||||
#if DROPBEAR_CLI_REMOTETCPFWD
|
||||
if (opt == OPT_REMOTETCPFWD) {
|
||||
TRACE(("opt remotetcpfwd"))
|
||||
addforward(&argv[i][j], cli_opts.remotefwds);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_LOCALTCPFWD
|
||||
#if DROPBEAR_CLI_LOCALTCPFWD
|
||||
if (opt == OPT_LOCALTCPFWD) {
|
||||
TRACE(("opt localtcpfwd"))
|
||||
addforward(&argv[i][j], cli_opts.localfwds);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_NETCAT
|
||||
#if DROPBEAR_CLI_NETCAT
|
||||
if (opt == OPT_NETCAT) {
|
||||
TRACE(("opt netcat"))
|
||||
add_netcat(&argv[i][j]);
|
||||
@@ -405,11 +408,11 @@ void cli_getopts(int argc, char ** argv) {
|
||||
|
||||
/* And now a few sanity checks and setup */
|
||||
|
||||
#ifdef ENABLE_USER_ALGO_LIST
|
||||
#if DROPBEAR_USER_ALGO_LIST
|
||||
parse_ciphers_macs();
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_CLI_PROXYCMD
|
||||
#if DROPBEAR_CLI_PROXYCMD
|
||||
if (cli_opts.proxycmd) {
|
||||
/* To match the common path of m_freeing it */
|
||||
cli_opts.proxycmd = m_strdup(cli_opts.proxycmd);
|
||||
@@ -420,6 +423,18 @@ void cli_getopts(int argc, char ** argv) {
|
||||
cli_opts.remoteport = "22";
|
||||
}
|
||||
|
||||
if (bind_arg) {
|
||||
/* split [host][:port] */
|
||||
char *port = strrchr(bind_arg, ':');
|
||||
if (port) {
|
||||
cli_opts.bind_port = m_strdup(port+1);
|
||||
*port = '\0';
|
||||
}
|
||||
if (strlen(bind_arg) > 0) {
|
||||
cli_opts.bind_address = m_strdup(bind_arg);
|
||||
}
|
||||
}
|
||||
|
||||
/* If not explicitly specified with -t or -T, we don't want a pty if
|
||||
* there's a command, but we do otherwise */
|
||||
if (cli_opts.wantpty == 9) {
|
||||
@@ -457,13 +472,13 @@ void cli_getopts(int argc, char ** argv) {
|
||||
opts.idle_timeout_secs = val;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLI_NETCAT
|
||||
#if DROPBEAR_CLI_NETCAT
|
||||
if (cli_opts.cmd && cli_opts.netcat_host) {
|
||||
dropbear_log(LOG_INFO, "Ignoring command '%s' in netcat mode", cli_opts.cmd);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(DROPBEAR_DEFAULT_CLI_AUTHKEY) && defined(ENABLE_CLI_PUBKEY_AUTH)
|
||||
#if (DROPBEAR_CLI_PUBKEY_AUTH)
|
||||
{
|
||||
char *expand_path = expand_homedir_path(DROPBEAR_DEFAULT_CLI_AUTHKEY);
|
||||
loadidentityfile(expand_path, 0);
|
||||
@@ -474,14 +489,14 @@ void cli_getopts(int argc, char ** argv) {
|
||||
/* The hostname gets set up last, since
|
||||
* in multi-hop mode it will require knowledge
|
||||
* of other flags such as -i */
|
||||
#ifdef ENABLE_CLI_MULTIHOP
|
||||
#if DROPBEAR_CLI_MULTIHOP
|
||||
parse_multihop_hostname(host_arg, argv[0]);
|
||||
#else
|
||||
parse_hostname(host_arg);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
static void loadidentityfile(const char* filename, int warnfail) {
|
||||
sign_key *key;
|
||||
enum signkey_type keytype;
|
||||
@@ -504,7 +519,7 @@ static void loadidentityfile(const char* filename, int warnfail) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_CLI_MULTIHOP
|
||||
#if DROPBEAR_CLI_MULTIHOP
|
||||
|
||||
static char*
|
||||
multihop_passthrough_args() {
|
||||
@@ -514,13 +529,13 @@ multihop_passthrough_args() {
|
||||
m_list_elem *iter;
|
||||
/* Fill out -i, -y, -W options that make sense for all
|
||||
* the intermediate processes */
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
for (iter = cli_opts.privkeys->first; iter; iter = iter->next)
|
||||
{
|
||||
sign_key * key = (sign_key*)iter->item;
|
||||
len += 3 + strlen(key->filename);
|
||||
}
|
||||
#endif /* ENABLE_CLI_PUBKEY_AUTH */
|
||||
#endif /* DROPBEAR_CLI_PUBKEY_AUTH */
|
||||
|
||||
len += 30; /* space for -W <size>, terminator. */
|
||||
ret = m_malloc(len);
|
||||
@@ -543,7 +558,7 @@ multihop_passthrough_args() {
|
||||
total += written;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLI_PUBKEY_AUTH
|
||||
#if DROPBEAR_CLI_PUBKEY_AUTH
|
||||
for (iter = cli_opts.privkeys->first; iter; iter = iter->next)
|
||||
{
|
||||
sign_key * key = (sign_key*)iter->item;
|
||||
@@ -552,7 +567,7 @@ multihop_passthrough_args() {
|
||||
dropbear_assert((unsigned int)written < size);
|
||||
total += written;
|
||||
}
|
||||
#endif /* ENABLE_CLI_PUBKEY_AUTH */
|
||||
#endif /* DROPBEAR_CLI_PUBKEY_AUTH */
|
||||
|
||||
/* if args were passed, total will be not zero, and it will have a space at the end, so remove that */
|
||||
if (total > 0)
|
||||
@@ -636,7 +651,7 @@ static void parse_multihop_hostname(const char* orighostarg, const char* argv0)
|
||||
}
|
||||
m_free(hostbuf);
|
||||
}
|
||||
#endif /* !ENABLE_CLI_MULTIHOP */
|
||||
#endif /* !DROPBEAR_CLI_MULTIHOP */
|
||||
|
||||
/* Parses a [user@]hostname[/port] argument. */
|
||||
static void parse_hostname(const char* orighostarg) {
|
||||
@@ -675,7 +690,7 @@ static void parse_hostname(const char* orighostarg) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLI_NETCAT
|
||||
#if DROPBEAR_CLI_NETCAT
|
||||
static void add_netcat(const char* origstr) {
|
||||
char *portstr = NULL;
|
||||
|
||||
@@ -728,7 +743,7 @@ static void fill_own_user() {
|
||||
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLI_ANYTCPFWD
|
||||
#if DROPBEAR_CLI_ANYTCPFWD
|
||||
/* Turn a "[listenaddr:]listenport:remoteaddr:remoteport" string into into a forwarding
|
||||
* set, and add it to the forwarding list */
|
||||
static void addforward(const char* origstr, m_list *fwdlist) {
|
||||
@@ -870,7 +885,7 @@ static void add_extendedopt(const char* origstr) {
|
||||
|
||||
if (strcmp(origstr, "help") == 0) {
|
||||
dropbear_log(LOG_INFO, "Available options:\n"
|
||||
#ifdef ENABLE_CLI_ANYTCPFWD
|
||||
#if DROPBEAR_CLI_ANYTCPFWD
|
||||
"\tExitOnForwardFailure\n"
|
||||
#endif
|
||||
#ifndef DISABLE_SYSLOG
|
||||
@@ -880,7 +895,7 @@ static void add_extendedopt(const char* origstr) {
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLI_ANYTCPFWD
|
||||
#if DROPBEAR_CLI_ANYTCPFWD
|
||||
if (match_extendedopt(&optstr, "ExitOnForwardFailure") == DROPBEAR_SUCCESS) {
|
||||
cli_opts.exit_on_fwd_failure = parse_flag_value(optstr);
|
||||
return;
|
||||
|
||||
@@ -73,7 +73,7 @@ static const packettype cli_packettypes[] = {
|
||||
{SSH_MSG_GLOBAL_REQUEST, recv_msg_global_request_cli},
|
||||
{SSH_MSG_CHANNEL_SUCCESS, ignore_recv_response},
|
||||
{SSH_MSG_CHANNEL_FAILURE, ignore_recv_response},
|
||||
#ifdef ENABLE_CLI_REMOTETCPFWD
|
||||
#if DROPBEAR_CLI_REMOTETCPFWD
|
||||
{SSH_MSG_REQUEST_SUCCESS, cli_recv_msg_request_success}, /* client */
|
||||
{SSH_MSG_REQUEST_FAILURE, cli_recv_msg_request_failure}, /* client */
|
||||
#else
|
||||
@@ -81,14 +81,14 @@ static const packettype cli_packettypes[] = {
|
||||
{SSH_MSG_REQUEST_SUCCESS, ignore_recv_response},
|
||||
{SSH_MSG_REQUEST_FAILURE, ignore_recv_response},
|
||||
#endif
|
||||
{0, 0} /* End */
|
||||
{0, NULL} /* End */
|
||||
};
|
||||
|
||||
static const struct ChanType *cli_chantypes[] = {
|
||||
#ifdef ENABLE_CLI_REMOTETCPFWD
|
||||
#if DROPBEAR_CLI_REMOTETCPFWD
|
||||
&cli_chan_tcpremote,
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_AGENTFWD
|
||||
#if DROPBEAR_CLI_AGENTFWD
|
||||
&cli_chan_agent,
|
||||
#endif
|
||||
NULL /* Null termination */
|
||||
@@ -118,7 +118,7 @@ void cli_session(int sock_in, int sock_out, struct dropbear_progress_connection
|
||||
cli_session_init(proxy_cmd_pid);
|
||||
|
||||
/* Ready to go */
|
||||
sessinitdone = 1;
|
||||
ses.init_done = 1;
|
||||
|
||||
/* Exchange identification */
|
||||
send_session_identification();
|
||||
@@ -133,7 +133,7 @@ void cli_session(int sock_in, int sock_out, struct dropbear_progress_connection
|
||||
|
||||
}
|
||||
|
||||
#ifdef USE_KEX_FIRST_FOLLOWS
|
||||
#if DROPBEAR_KEX_FIRST_FOLLOWS
|
||||
static void cli_send_kex_first_guess() {
|
||||
send_msg_kexdh_init();
|
||||
}
|
||||
@@ -165,13 +165,6 @@ static void cli_session_init(pid_t proxy_cmd_pid) {
|
||||
cli_ses.lastprivkey = NULL;
|
||||
cli_ses.lastauthtype = 0;
|
||||
|
||||
#ifdef DROPBEAR_NONE_CIPHER
|
||||
cli_ses.cipher_none_after_auth = get_algo_usable(sshciphers, "none");
|
||||
set_algo_usable(sshciphers, "none", 0);
|
||||
#else
|
||||
cli_ses.cipher_none_after_auth = 0;
|
||||
#endif
|
||||
|
||||
/* For printing "remote host closed" for the user */
|
||||
ses.remoteclosed = cli_remoteclosed;
|
||||
|
||||
@@ -182,13 +175,13 @@ static void cli_session_init(pid_t proxy_cmd_pid) {
|
||||
|
||||
ses.isserver = 0;
|
||||
|
||||
#ifdef USE_KEX_FIRST_FOLLOWS
|
||||
#if DROPBEAR_KEX_FIRST_FOLLOWS
|
||||
ses.send_kex_first_guess = cli_send_kex_first_guess;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
static void send_msg_service_request(char* servicename) {
|
||||
static void send_msg_service_request(const char* servicename) {
|
||||
|
||||
TRACE(("enter send_msg_service_request: servicename='%s'", servicename))
|
||||
|
||||
@@ -275,19 +268,11 @@ static void cli_sessionloop() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DROPBEAR_NONE_CIPHER
|
||||
if (cli_ses.cipher_none_after_auth)
|
||||
{
|
||||
set_algo_usable(sshciphers, "none", 1);
|
||||
send_msg_kexinit();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (cli_opts.backgrounded) {
|
||||
int devnull;
|
||||
/* keeping stdin open steals input from the terminal and
|
||||
is confusing, though stdout/stderr could be useful. */
|
||||
devnull = open(_PATH_DEVNULL, O_RDONLY);
|
||||
devnull = open(DROPBEAR_PATH_DEVNULL, O_RDONLY);
|
||||
if (devnull < 0) {
|
||||
dropbear_exit("Opening /dev/null: %d %s",
|
||||
errno, strerror(errno));
|
||||
@@ -299,7 +284,7 @@ static void cli_sessionloop() {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLI_NETCAT
|
||||
#if DROPBEAR_CLI_NETCAT
|
||||
if (cli_opts.netcat_host) {
|
||||
cli_send_netcat_request();
|
||||
} else
|
||||
@@ -308,10 +293,10 @@ static void cli_sessionloop() {
|
||||
cli_send_chansess_request();
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLI_LOCALTCPFWD
|
||||
#if DROPBEAR_CLI_LOCALTCPFWD
|
||||
setup_localtcp();
|
||||
#endif
|
||||
#ifdef ENABLE_CLI_REMOTETCPFWD
|
||||
#if DROPBEAR_CLI_REMOTETCPFWD
|
||||
setup_remotetcp();
|
||||
#endif
|
||||
|
||||
@@ -353,7 +338,7 @@ void kill_proxy_command(void) {
|
||||
|
||||
static void cli_session_cleanup(void) {
|
||||
|
||||
if (!sessinitdone) {
|
||||
if (!ses.init_done) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
21
cli-tcpfwd.c
21
cli-tcpfwd.c
@@ -23,7 +23,6 @@
|
||||
* SOFTWARE. */
|
||||
|
||||
#include "includes.h"
|
||||
#include "options.h"
|
||||
#include "dbutil.h"
|
||||
#include "tcpfwd.h"
|
||||
#include "channel.h"
|
||||
@@ -32,7 +31,7 @@
|
||||
#include "ssh.h"
|
||||
#include "netio.h"
|
||||
|
||||
#ifdef ENABLE_CLI_REMOTETCPFWD
|
||||
#if DROPBEAR_CLI_REMOTETCPFWD
|
||||
static int newtcpforwarded(struct Channel * channel);
|
||||
|
||||
const struct ChanType cli_chan_tcpremote = {
|
||||
@@ -45,7 +44,7 @@ const struct ChanType cli_chan_tcpremote = {
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_CLI_LOCALTCPFWD
|
||||
#if DROPBEAR_CLI_LOCALTCPFWD
|
||||
static int cli_localtcp(const char* listenaddr,
|
||||
unsigned int listenport,
|
||||
const char* remoteaddr,
|
||||
@@ -60,7 +59,7 @@ static const struct ChanType cli_chan_tcplocal = {
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_CLI_ANYTCPFWD
|
||||
#if DROPBEAR_CLI_ANYTCPFWD
|
||||
static void fwd_failed(const char* format, ...) ATTRIB_PRINTF(1,2);
|
||||
static void fwd_failed(const char* format, ...)
|
||||
{
|
||||
@@ -77,7 +76,7 @@ static void fwd_failed(const char* format, ...)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_CLI_LOCALTCPFWD
|
||||
#if DROPBEAR_CLI_LOCALTCPFWD
|
||||
void setup_localtcp() {
|
||||
m_list_elem *iter;
|
||||
int ret;
|
||||
@@ -144,9 +143,9 @@ static int cli_localtcp(const char* listenaddr,
|
||||
TRACE(("leave cli_localtcp: %d", ret))
|
||||
return ret;
|
||||
}
|
||||
#endif /* ENABLE_CLI_LOCALTCPFWD */
|
||||
#endif /* DROPBEAR_CLI_LOCALTCPFWD */
|
||||
|
||||
#ifdef ENABLE_CLI_REMOTETCPFWD
|
||||
#if DROPBEAR_CLI_REMOTETCPFWD
|
||||
static void send_msg_global_request_remotetcp(const char *addr, int port) {
|
||||
|
||||
TRACE(("enter send_msg_global_request_remotetcp"))
|
||||
@@ -234,7 +233,7 @@ static int newtcpforwarded(struct Channel * channel) {
|
||||
char *origaddr = NULL;
|
||||
unsigned int origport;
|
||||
m_list_elem * iter = NULL;
|
||||
struct TCPFwdEntry *fwd;
|
||||
struct TCPFwdEntry *fwd = NULL;
|
||||
char portstring[NI_MAXSERV];
|
||||
int err = SSH_OPEN_ADMINISTRATIVELY_PROHIBITED;
|
||||
|
||||
@@ -265,7 +264,7 @@ static int newtcpforwarded(struct Channel * channel) {
|
||||
}
|
||||
|
||||
|
||||
if (iter == NULL) {
|
||||
if (iter == NULL || fwd == NULL) {
|
||||
/* We didn't request forwarding on that port */
|
||||
cleantext(origaddr);
|
||||
dropbear_log(LOG_INFO, "Server sent unrequested forward from \"%s:%d\"",
|
||||
@@ -274,7 +273,7 @@ static int newtcpforwarded(struct Channel * channel) {
|
||||
}
|
||||
|
||||
snprintf(portstring, sizeof(portstring), "%u", fwd->connectport);
|
||||
channel->conn_pending = connect_remote(fwd->connectaddr, portstring, channel_connect_done, channel);
|
||||
channel->conn_pending = connect_remote(fwd->connectaddr, portstring, channel_connect_done, channel, NULL, NULL);
|
||||
|
||||
channel->prio = DROPBEAR_CHANNEL_PRIO_UNKNOWABLE;
|
||||
|
||||
@@ -285,4 +284,4 @@ out:
|
||||
TRACE(("leave newtcpdirect: err %d", err))
|
||||
return err;
|
||||
}
|
||||
#endif /* ENABLE_CLI_REMOTETCPFWD */
|
||||
#endif /* DROPBEAR_CLI_REMOTETCPFWD */
|
||||
|
||||
158
common-algo.c
158
common-algo.c
@@ -53,27 +53,27 @@ static int void_start(int UNUSED(cipher), const unsigned char* UNUSED(IV),
|
||||
|
||||
/* Remember to add new ciphers/hashes to regciphers/reghashes too */
|
||||
|
||||
#ifdef DROPBEAR_AES256
|
||||
#if DROPBEAR_AES256
|
||||
static const struct dropbear_cipher dropbear_aes256 =
|
||||
{&aes_desc, 32, 16};
|
||||
#endif
|
||||
#ifdef DROPBEAR_AES128
|
||||
#if DROPBEAR_AES128
|
||||
static const struct dropbear_cipher dropbear_aes128 =
|
||||
{&aes_desc, 16, 16};
|
||||
#endif
|
||||
#ifdef DROPBEAR_BLOWFISH
|
||||
#if DROPBEAR_BLOWFISH
|
||||
static const struct dropbear_cipher dropbear_blowfish =
|
||||
{&blowfish_desc, 16, 8};
|
||||
#endif
|
||||
#ifdef DROPBEAR_TWOFISH256
|
||||
#if DROPBEAR_TWOFISH256
|
||||
static const struct dropbear_cipher dropbear_twofish256 =
|
||||
{&twofish_desc, 32, 16};
|
||||
#endif
|
||||
#ifdef DROPBEAR_TWOFISH128
|
||||
#if DROPBEAR_TWOFISH128
|
||||
static const struct dropbear_cipher dropbear_twofish128 =
|
||||
{&twofish_desc, 16, 16};
|
||||
#endif
|
||||
#ifdef DROPBEAR_3DES
|
||||
#if DROPBEAR_3DES
|
||||
static const struct dropbear_cipher dropbear_3des =
|
||||
{&des3_desc, 24, 8};
|
||||
#endif
|
||||
@@ -84,7 +84,7 @@ const struct dropbear_cipher dropbear_nocipher =
|
||||
|
||||
/* A few void* s are required to silence warnings
|
||||
* about the symmetric_CBC vs symmetric_CTR cipher_state pointer */
|
||||
#ifdef DROPBEAR_ENABLE_CBC_MODE
|
||||
#if DROPBEAR_ENABLE_CBC_MODE
|
||||
const struct dropbear_cipher_mode dropbear_mode_cbc =
|
||||
{(void*)cbc_start, (void*)cbc_encrypt, (void*)cbc_decrypt};
|
||||
#endif /* DROPBEAR_ENABLE_CBC_MODE */
|
||||
@@ -92,7 +92,7 @@ const struct dropbear_cipher_mode dropbear_mode_cbc =
|
||||
const struct dropbear_cipher_mode dropbear_mode_none =
|
||||
{void_start, void_cipher, void_cipher};
|
||||
|
||||
#ifdef DROPBEAR_ENABLE_CTR_MODE
|
||||
#if DROPBEAR_ENABLE_CTR_MODE
|
||||
/* a wrapper to make ctr_start and cbc_start look the same */
|
||||
static int dropbear_big_endian_ctr_start(int cipher,
|
||||
const unsigned char *IV,
|
||||
@@ -107,23 +107,23 @@ const struct dropbear_cipher_mode dropbear_mode_ctr =
|
||||
/* Mapping of ssh hashes to libtomcrypt hashes, including keysize etc.
|
||||
{&hash_desc, keysize, hashsize} */
|
||||
|
||||
#ifdef DROPBEAR_SHA1_HMAC
|
||||
#if DROPBEAR_SHA1_HMAC
|
||||
static const struct dropbear_hash dropbear_sha1 =
|
||||
{&sha1_desc, 20, 20};
|
||||
#endif
|
||||
#ifdef DROPBEAR_SHA1_96_HMAC
|
||||
#if DROPBEAR_SHA1_96_HMAC
|
||||
static const struct dropbear_hash dropbear_sha1_96 =
|
||||
{&sha1_desc, 20, 12};
|
||||
#endif
|
||||
#ifdef DROPBEAR_SHA2_256_HMAC
|
||||
#if DROPBEAR_SHA2_256_HMAC
|
||||
static const struct dropbear_hash dropbear_sha2_256 =
|
||||
{&sha256_desc, 32, 32};
|
||||
#endif
|
||||
#ifdef DROPBEAR_SHA2_512_HMAC
|
||||
#if DROPBEAR_SHA2_512_HMAC
|
||||
static const struct dropbear_hash dropbear_sha2_512 =
|
||||
{&sha512_desc, 64, 64};
|
||||
#endif
|
||||
#ifdef DROPBEAR_MD5_HMAC
|
||||
#if DROPBEAR_MD5_HMAC
|
||||
static const struct dropbear_hash dropbear_md5 =
|
||||
{&md5_desc, 16, 16};
|
||||
#endif
|
||||
@@ -137,72 +137,66 @@ const struct dropbear_hash dropbear_nohash =
|
||||
* that is also supported by the server will get used. */
|
||||
|
||||
algo_type sshciphers[] = {
|
||||
#ifdef DROPBEAR_ENABLE_CTR_MODE
|
||||
#ifdef DROPBEAR_AES128
|
||||
#if DROPBEAR_ENABLE_CTR_MODE
|
||||
#if DROPBEAR_AES128
|
||||
{"aes128-ctr", 0, &dropbear_aes128, 1, &dropbear_mode_ctr},
|
||||
#endif
|
||||
#ifdef DROPBEAR_AES256
|
||||
#if DROPBEAR_AES256
|
||||
{"aes256-ctr", 0, &dropbear_aes256, 1, &dropbear_mode_ctr},
|
||||
#endif
|
||||
#ifdef DROPBEAR_TWOFISH_CTR
|
||||
#if DROPBEAR_TWOFISH_CTR
|
||||
/* twofish ctr is conditional as it hasn't been tested for interoperability, see options.h */
|
||||
#ifdef DROPBEAR_TWOFISH256
|
||||
#if DROPBEAR_TWOFISH256
|
||||
{"twofish256-ctr", 0, &dropbear_twofish256, 1, &dropbear_mode_ctr},
|
||||
#endif
|
||||
#ifdef DROPBEAR_TWOFISH128
|
||||
#if DROPBEAR_TWOFISH128
|
||||
{"twofish128-ctr", 0, &dropbear_twofish128, 1, &dropbear_mode_ctr},
|
||||
#endif
|
||||
#endif /* DROPBEAR_TWOFISH_CTR */
|
||||
#endif /* DROPBEAR_ENABLE_CTR_MODE */
|
||||
|
||||
#ifdef DROPBEAR_ENABLE_CBC_MODE
|
||||
#ifdef DROPBEAR_AES128
|
||||
#if DROPBEAR_ENABLE_CBC_MODE
|
||||
#if DROPBEAR_AES128
|
||||
{"aes128-cbc", 0, &dropbear_aes128, 1, &dropbear_mode_cbc},
|
||||
#endif
|
||||
#ifdef DROPBEAR_AES256
|
||||
#if DROPBEAR_AES256
|
||||
{"aes256-cbc", 0, &dropbear_aes256, 1, &dropbear_mode_cbc},
|
||||
#endif
|
||||
#ifdef DROPBEAR_TWOFISH256
|
||||
#if DROPBEAR_TWOFISH256
|
||||
{"twofish256-cbc", 0, &dropbear_twofish256, 1, &dropbear_mode_cbc},
|
||||
{"twofish-cbc", 0, &dropbear_twofish256, 1, &dropbear_mode_cbc},
|
||||
#endif
|
||||
#ifdef DROPBEAR_TWOFISH128
|
||||
#if DROPBEAR_TWOFISH128
|
||||
{"twofish128-cbc", 0, &dropbear_twofish128, 1, &dropbear_mode_cbc},
|
||||
#endif
|
||||
#ifdef DROPBEAR_3DES
|
||||
#if DROPBEAR_3DES
|
||||
{"3des-ctr", 0, &dropbear_3des, 1, &dropbear_mode_ctr},
|
||||
#endif
|
||||
#ifdef DROPBEAR_3DES
|
||||
#if DROPBEAR_3DES
|
||||
{"3des-cbc", 0, &dropbear_3des, 1, &dropbear_mode_cbc},
|
||||
#endif
|
||||
#ifdef DROPBEAR_BLOWFISH
|
||||
#if DROPBEAR_BLOWFISH
|
||||
{"blowfish-cbc", 0, &dropbear_blowfish, 1, &dropbear_mode_cbc},
|
||||
#endif
|
||||
#endif /* DROPBEAR_ENABLE_CBC_MODE */
|
||||
#ifdef DROPBEAR_NONE_CIPHER
|
||||
{"none", 0, (void*)&dropbear_nocipher, 1, &dropbear_mode_none},
|
||||
#endif
|
||||
{NULL, 0, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
algo_type sshhashes[] = {
|
||||
#ifdef DROPBEAR_SHA1_96_HMAC
|
||||
#if DROPBEAR_SHA1_96_HMAC
|
||||
{"hmac-sha1-96", 0, &dropbear_sha1_96, 1, NULL},
|
||||
#endif
|
||||
#ifdef DROPBEAR_SHA1_HMAC
|
||||
#if DROPBEAR_SHA1_HMAC
|
||||
{"hmac-sha1", 0, &dropbear_sha1, 1, NULL},
|
||||
#endif
|
||||
#ifdef DROPBEAR_SHA2_256_HMAC
|
||||
#if DROPBEAR_SHA2_256_HMAC
|
||||
{"hmac-sha2-256", 0, &dropbear_sha2_256, 1, NULL},
|
||||
#endif
|
||||
#ifdef DROPBEAR_SHA2_512_HMAC
|
||||
#if DROPBEAR_SHA2_512_HMAC
|
||||
{"hmac-sha2-512", 0, &dropbear_sha2_512, 1, NULL},
|
||||
#endif
|
||||
#ifdef DROPBEAR_MD5_HMAC
|
||||
#if DROPBEAR_MD5_HMAC
|
||||
{"hmac-md5", 0, (void*)&dropbear_md5, 1, NULL},
|
||||
#endif
|
||||
#ifdef DROPBEAR_NONE_INTEGRITY
|
||||
{"none", 0, (void*)&dropbear_nohash, 1, NULL},
|
||||
#endif
|
||||
{NULL, 0, NULL, 0, NULL}
|
||||
};
|
||||
@@ -228,21 +222,21 @@ algo_type ssh_nocompress[] = {
|
||||
};
|
||||
|
||||
algo_type sshhostkey[] = {
|
||||
#ifdef DROPBEAR_ECDSA
|
||||
#ifdef DROPBEAR_ECC_256
|
||||
#if DROPBEAR_ECDSA
|
||||
#if DROPBEAR_ECC_256
|
||||
{"ecdsa-sha2-nistp256", DROPBEAR_SIGNKEY_ECDSA_NISTP256, NULL, 1, NULL},
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_384
|
||||
#if DROPBEAR_ECC_384
|
||||
{"ecdsa-sha2-nistp384", DROPBEAR_SIGNKEY_ECDSA_NISTP384, NULL, 1, NULL},
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_521
|
||||
#if DROPBEAR_ECC_521
|
||||
{"ecdsa-sha2-nistp521", DROPBEAR_SIGNKEY_ECDSA_NISTP521, NULL, 1, NULL},
|
||||
#endif
|
||||
#endif
|
||||
#ifdef DROPBEAR_RSA
|
||||
#if DROPBEAR_RSA
|
||||
{"ssh-rsa", DROPBEAR_SIGNKEY_RSA, NULL, 1, NULL},
|
||||
#endif
|
||||
#ifdef DROPBEAR_DSS
|
||||
#if DROPBEAR_DSS
|
||||
{"ssh-dss", DROPBEAR_SIGNKEY_DSS, NULL, 1, NULL},
|
||||
#endif
|
||||
{NULL, 0, NULL, 0, NULL}
|
||||
@@ -251,11 +245,11 @@ algo_type sshhostkey[] = {
|
||||
#if DROPBEAR_DH_GROUP1
|
||||
static const struct dropbear_kex kex_dh_group1 = {DROPBEAR_KEX_NORMAL_DH, dh_p_1, DH_P_1_LEN, NULL, &sha1_desc };
|
||||
#endif
|
||||
#if DROPBEAR_DH_GROUP14
|
||||
#if DROPBEAR_DH_GROUP14_SHA1
|
||||
static const struct dropbear_kex kex_dh_group14_sha1 = {DROPBEAR_KEX_NORMAL_DH, dh_p_14, DH_P_14_LEN, NULL, &sha1_desc };
|
||||
#if DROPBEAR_DH_GROUP14_256
|
||||
static const struct dropbear_kex kex_dh_group14_sha256 = {DROPBEAR_KEX_NORMAL_DH, dh_p_14, DH_P_14_LEN, NULL, &sha256_desc };
|
||||
#endif
|
||||
#if DROPBEAR_DH_GROUP14_SHA256
|
||||
static const struct dropbear_kex kex_dh_group14_sha256 = {DROPBEAR_KEX_NORMAL_DH, dh_p_14, DH_P_14_LEN, NULL, &sha256_desc };
|
||||
#endif
|
||||
#if DROPBEAR_DH_GROUP16
|
||||
static const struct dropbear_kex kex_dh_group16_sha512 = {DROPBEAR_KEX_NORMAL_DH, dh_p_16, DH_P_16_LEN, NULL, &sha512_desc };
|
||||
@@ -263,42 +257,43 @@ static const struct dropbear_kex kex_dh_group16_sha512 = {DROPBEAR_KEX_NORMAL_DH
|
||||
|
||||
/* These can't be const since dropbear_ecc_fill_dp() fills out
|
||||
ecc_curve at runtime */
|
||||
#ifdef DROPBEAR_ECDH
|
||||
#ifdef DROPBEAR_ECC_256
|
||||
#if DROPBEAR_ECDH
|
||||
#if DROPBEAR_ECC_256
|
||||
static const struct dropbear_kex kex_ecdh_nistp256 = {DROPBEAR_KEX_ECDH, NULL, 0, &ecc_curve_nistp256, &sha256_desc };
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_384
|
||||
#if DROPBEAR_ECC_384
|
||||
static const struct dropbear_kex kex_ecdh_nistp384 = {DROPBEAR_KEX_ECDH, NULL, 0, &ecc_curve_nistp384, &sha384_desc };
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_521
|
||||
#if DROPBEAR_ECC_521
|
||||
static const struct dropbear_kex kex_ecdh_nistp521 = {DROPBEAR_KEX_ECDH, NULL, 0, &ecc_curve_nistp521, &sha512_desc };
|
||||
#endif
|
||||
#endif /* DROPBEAR_ECDH */
|
||||
|
||||
#ifdef DROPBEAR_CURVE25519
|
||||
#if DROPBEAR_CURVE25519
|
||||
/* Referred to directly */
|
||||
static const struct dropbear_kex kex_curve25519 = {DROPBEAR_KEX_CURVE25519, NULL, 0, NULL, &sha256_desc };
|
||||
#endif
|
||||
|
||||
algo_type sshkex[] = {
|
||||
#ifdef DROPBEAR_CURVE25519
|
||||
#if DROPBEAR_CURVE25519
|
||||
{"curve25519-sha256", 0, &kex_curve25519, 1, NULL},
|
||||
{"curve25519-sha256@libssh.org", 0, &kex_curve25519, 1, NULL},
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECDH
|
||||
#ifdef DROPBEAR_ECC_521
|
||||
#if DROPBEAR_ECDH
|
||||
#if DROPBEAR_ECC_521
|
||||
{"ecdh-sha2-nistp521", 0, &kex_ecdh_nistp521, 1, NULL},
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_384
|
||||
#if DROPBEAR_ECC_384
|
||||
{"ecdh-sha2-nistp384", 0, &kex_ecdh_nistp384, 1, NULL},
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_256
|
||||
#if DROPBEAR_ECC_256
|
||||
{"ecdh-sha2-nistp256", 0, &kex_ecdh_nistp256, 1, NULL},
|
||||
#endif
|
||||
#endif
|
||||
#if DROPBEAR_DH_GROUP14
|
||||
#if DROPBEAR_DH_GROUP14_256
|
||||
#if DROPBEAR_DH_GROUP14_SHA256
|
||||
{"diffie-hellman-group14-sha256", 0, &kex_dh_group14_sha256, 1, NULL},
|
||||
#endif
|
||||
#if DROPBEAR_DH_GROUP14_SHA1
|
||||
{"diffie-hellman-group14-sha1", 0, &kex_dh_group14_sha1, 1, NULL},
|
||||
#endif
|
||||
#if DROPBEAR_DH_GROUP1
|
||||
@@ -307,7 +302,7 @@ algo_type sshkex[] = {
|
||||
#if DROPBEAR_DH_GROUP16
|
||||
{"diffie-hellman-group16-sha512", 0, &kex_dh_group16_sha512, 1, NULL},
|
||||
#endif
|
||||
#ifdef USE_KEXGUESS2
|
||||
#if DROPBEAR_KEXGUESS2
|
||||
{KEXGUESS2_ALGO_NAME, KEXGUESS2_ALGO_ID, NULL, 1, NULL},
|
||||
#endif
|
||||
{NULL, 0, NULL, 0, NULL}
|
||||
@@ -317,7 +312,7 @@ algo_type sshkex[] = {
|
||||
* against.
|
||||
* Returns DROPBEAR_SUCCESS if we have a match for algo, DROPBEAR_FAILURE
|
||||
* otherwise */
|
||||
int have_algo(char* algo, size_t algolen, algo_type algos[]) {
|
||||
int have_algo(const char* algo, size_t algolen, const algo_type algos[]) {
|
||||
|
||||
int i;
|
||||
|
||||
@@ -332,7 +327,7 @@ int have_algo(char* algo, size_t algolen, algo_type algos[]) {
|
||||
}
|
||||
|
||||
/* Output a comma separated list of algorithms to a buffer */
|
||||
void buf_put_algolist(buffer * buf, algo_type localalgos[]) {
|
||||
void buf_put_algolist(buffer * buf, const algo_type localalgos[]) {
|
||||
|
||||
unsigned int i, len;
|
||||
unsigned int donefirst = 0;
|
||||
@@ -349,6 +344,7 @@ void buf_put_algolist(buffer * buf, algo_type localalgos[]) {
|
||||
}
|
||||
}
|
||||
buf_putstring(buf, (const char*)algolist->data, algolist->len);
|
||||
TRACE(("algolist add '%*s'", algolist->len, algolist->data))
|
||||
buf_free(algolist);
|
||||
}
|
||||
|
||||
@@ -468,42 +464,10 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef DROPBEAR_NONE_CIPHER
|
||||
|
||||
void
|
||||
set_algo_usable(algo_type algos[], const char * algo_name, int usable)
|
||||
{
|
||||
algo_type *a;
|
||||
for (a = algos; a->name != NULL; a++)
|
||||
{
|
||||
if (strcmp(a->name, algo_name) == 0)
|
||||
{
|
||||
a->usable = usable;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
get_algo_usable(algo_type algos[], const char * algo_name)
|
||||
{
|
||||
algo_type *a;
|
||||
for (a = algos; a->name != NULL; a++)
|
||||
{
|
||||
if (strcmp(a->name, algo_name) == 0)
|
||||
{
|
||||
return a->usable;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* DROPBEAR_NONE_CIPHER */
|
||||
|
||||
#ifdef ENABLE_USER_ALGO_LIST
|
||||
#if DROPBEAR_USER_ALGO_LIST
|
||||
|
||||
char *
|
||||
algolist_string(algo_type algos[])
|
||||
algolist_string(const algo_type algos[])
|
||||
{
|
||||
char *ret_list;
|
||||
buffer *b = buf_new(200);
|
||||
@@ -577,4 +541,4 @@ check_user_algos(const char* user_algo_list, algo_type * algos,
|
||||
memcpy(algos, new_algos, sizeof(*new_algos) * (n+1));
|
||||
return n;
|
||||
}
|
||||
#endif /* ENABLE_USER_ALGO_LIST */
|
||||
#endif /* DROPBEAR_USER_ALGO_LIST */
|
||||
|
||||
@@ -32,25 +32,24 @@
|
||||
#include "circbuffer.h"
|
||||
#include "dbutil.h"
|
||||
#include "channel.h"
|
||||
#include "ssh.h"
|
||||
#include "listener.h"
|
||||
#include "runopts.h"
|
||||
#include "netio.h"
|
||||
|
||||
static void send_msg_channel_open_failure(unsigned int remotechan, int reason,
|
||||
const char *text, const char *lang);
|
||||
static void send_msg_channel_open_confirmation(struct Channel* channel,
|
||||
static void send_msg_channel_open_confirmation(const struct Channel* channel,
|
||||
unsigned int recvwindow,
|
||||
unsigned int recvmaxpacket);
|
||||
static int writechannel(struct Channel* channel, int fd, circbuffer *cbuf,
|
||||
const unsigned char *moredata, unsigned int *morelen);
|
||||
static void send_msg_channel_window_adjust(struct Channel *channel,
|
||||
static void send_msg_channel_window_adjust(const struct Channel *channel,
|
||||
unsigned int incr);
|
||||
static void send_msg_channel_data(struct Channel *channel, int isextended);
|
||||
static void send_msg_channel_eof(struct Channel *channel);
|
||||
static void send_msg_channel_close(struct Channel *channel);
|
||||
static void remove_channel(struct Channel *channel);
|
||||
static unsigned int write_pending(struct Channel * channel);
|
||||
static unsigned int write_pending(const struct Channel * channel);
|
||||
static void check_close(struct Channel *channel);
|
||||
static void close_chan_fd(struct Channel *channel, int fd, int how);
|
||||
|
||||
@@ -78,7 +77,7 @@ void chaninitialise(const struct ChanType *chantypes[]) {
|
||||
|
||||
ses.chantypes = chantypes;
|
||||
|
||||
#ifdef USING_LISTENERS
|
||||
#if DROPBEAR_LISTENERS
|
||||
listeners_initialise();
|
||||
#endif
|
||||
|
||||
@@ -199,7 +198,7 @@ struct Channel* getchannel() {
|
||||
}
|
||||
|
||||
/* Iterate through the channels, performing IO if available */
|
||||
void channelio(fd_set *readfds, fd_set *writefds) {
|
||||
void channelio(const fd_set *readfds, const fd_set *writefds) {
|
||||
|
||||
/* Listeners such as TCP, X11, agent-auth */
|
||||
struct Channel *channel;
|
||||
@@ -255,7 +254,7 @@ void channelio(fd_set *readfds, fd_set *writefds) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USING_LISTENERS
|
||||
#if DROPBEAR_LISTENERS
|
||||
handle_listeners(readfds);
|
||||
#endif
|
||||
}
|
||||
@@ -263,7 +262,7 @@ void channelio(fd_set *readfds, fd_set *writefds) {
|
||||
|
||||
/* Returns true if there is data remaining to be written to stdin or
|
||||
* stderr of a channel's endpoint. */
|
||||
static unsigned int write_pending(struct Channel * channel) {
|
||||
static unsigned int write_pending(const struct Channel * channel) {
|
||||
|
||||
if (channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0) {
|
||||
return 1;
|
||||
@@ -595,7 +594,7 @@ void setchannelfds(fd_set *readfds, fd_set *writefds, int allow_reads) {
|
||||
|
||||
} /* foreach channel */
|
||||
|
||||
#ifdef USING_LISTENERS
|
||||
#if DROPBEAR_LISTENERS
|
||||
set_listener_fds(readfds);
|
||||
#endif
|
||||
|
||||
@@ -904,7 +903,7 @@ void recv_msg_channel_window_adjust() {
|
||||
|
||||
/* Increment the incoming data window for a channel, and let the remote
|
||||
* end know */
|
||||
static void send_msg_channel_window_adjust(struct Channel* channel,
|
||||
static void send_msg_channel_window_adjust(const struct Channel* channel,
|
||||
unsigned int incr) {
|
||||
|
||||
TRACE(("sending window adjust %d", incr))
|
||||
@@ -1009,7 +1008,7 @@ cleanup:
|
||||
}
|
||||
|
||||
/* Send a failure message */
|
||||
void send_msg_channel_failure(struct Channel *channel) {
|
||||
void send_msg_channel_failure(const struct Channel *channel) {
|
||||
|
||||
TRACE(("enter send_msg_channel_failure"))
|
||||
CHECKCLEARTOWRITE();
|
||||
@@ -1022,7 +1021,7 @@ void send_msg_channel_failure(struct Channel *channel) {
|
||||
}
|
||||
|
||||
/* Send a success message */
|
||||
void send_msg_channel_success(struct Channel *channel) {
|
||||
void send_msg_channel_success(const struct Channel *channel) {
|
||||
|
||||
TRACE(("enter send_msg_channel_success"))
|
||||
CHECKCLEARTOWRITE();
|
||||
@@ -1054,7 +1053,7 @@ static void send_msg_channel_open_failure(unsigned int remotechan,
|
||||
|
||||
/* Confirm a channel open, and let the remote end know what number we've
|
||||
* allocated and the receive parameters */
|
||||
static void send_msg_channel_open_confirmation(struct Channel* channel,
|
||||
static void send_msg_channel_open_confirmation(const struct Channel* channel,
|
||||
unsigned int recvwindow,
|
||||
unsigned int recvmaxpacket) {
|
||||
|
||||
@@ -1114,7 +1113,7 @@ static void close_chan_fd(struct Channel *channel, int fd, int how) {
|
||||
}
|
||||
|
||||
|
||||
#if defined(USING_LISTENERS) || defined(DROPBEAR_CLIENT)
|
||||
#if (DROPBEAR_LISTENERS) || (DROPBEAR_CLIENT)
|
||||
/* Create a new channel, and start the open request. This is intended
|
||||
* for X11, agent, tcp forwarding, and should be filled with channel-specific
|
||||
* options, with the calling function calling encrypt_packet() after
|
||||
@@ -1210,7 +1209,7 @@ void recv_msg_channel_open_failure() {
|
||||
|
||||
remove_channel(channel);
|
||||
}
|
||||
#endif /* USING_LISTENERS */
|
||||
#endif /* DROPBEAR_LISTENERS */
|
||||
|
||||
void send_msg_request_success() {
|
||||
CHECKCLEARTOWRITE();
|
||||
@@ -1240,8 +1239,8 @@ struct Channel* get_any_ready_channel() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void start_send_channel_request(struct Channel *channel,
|
||||
char *type) {
|
||||
void start_send_channel_request(const struct Channel *channel,
|
||||
const char *type) {
|
||||
|
||||
CHECKCLEARTOWRITE();
|
||||
buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_REQUEST);
|
||||
|
||||
10
common-kex.c
10
common-kex.c
@@ -640,7 +640,7 @@ void kexdh_comb_key(struct kex_dh_param *param, mp_int *dh_pub_them,
|
||||
finish_kexhashbuf();
|
||||
}
|
||||
|
||||
#ifdef DROPBEAR_ECDH
|
||||
#if DROPBEAR_ECDH
|
||||
struct kex_ecdh_param *gen_kexecdh_param() {
|
||||
struct kex_ecdh_param *param = m_malloc(sizeof(*param));
|
||||
if (ecc_make_key_ex(NULL, dropbear_ltc_prng,
|
||||
@@ -692,7 +692,7 @@ void kexecdh_comb_key(struct kex_ecdh_param *param, buffer *pub_them,
|
||||
}
|
||||
#endif /* DROPBEAR_ECDH */
|
||||
|
||||
#ifdef DROPBEAR_CURVE25519
|
||||
#if DROPBEAR_CURVE25519
|
||||
struct kex_curve25519_param *gen_kexcurve25519_param () {
|
||||
/* Per http://cr.yp.to/ecdh.html */
|
||||
struct kex_curve25519_param *param = m_malloc(sizeof(*param));
|
||||
@@ -714,7 +714,7 @@ void free_kexcurve25519_param(struct kex_curve25519_param *param)
|
||||
m_free(param);
|
||||
}
|
||||
|
||||
void kexcurve25519_comb_key(struct kex_curve25519_param *param, buffer *buf_pub_them,
|
||||
void kexcurve25519_comb_key(const struct kex_curve25519_param *param, const buffer *buf_pub_them,
|
||||
sign_key *hostkey) {
|
||||
unsigned char out[CURVE25519_LEN];
|
||||
const unsigned char* Q_C = NULL;
|
||||
@@ -774,7 +774,7 @@ static void finish_kexhashbuf(void) {
|
||||
hash_desc->done(&hs, buf_getwriteptr(ses.hash, hash_desc->hashsize));
|
||||
buf_setlen(ses.hash, hash_desc->hashsize);
|
||||
|
||||
#if defined(DEBUG_KEXHASH) && defined(DEBUG_TRACE)
|
||||
#if defined(DEBUG_KEXHASH) && DEBUG_TRACE
|
||||
if (!debug_trace) {
|
||||
printhex("kexhashbuf", ses.kexhashbuf->data, ses.kexhashbuf->len);
|
||||
printhex("kexhash", ses.hash->data, ses.hash->len);
|
||||
@@ -814,7 +814,7 @@ static void read_kex_algos() {
|
||||
int allgood = 1; /* we AND this with each goodguess and see if its still
|
||||
true after */
|
||||
|
||||
#ifdef USE_KEXGUESS2
|
||||
#if DROPBEAR_KEXGUESS2
|
||||
enum kexguess2_used kexguess2 = KEXGUESS2_LOOK;
|
||||
#else
|
||||
enum kexguess2_used kexguess2 = KEXGUESS2_NO;
|
||||
|
||||
@@ -62,7 +62,7 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_USER_ALGO_LIST
|
||||
#if DROPBEAR_USER_ALGO_LIST
|
||||
void
|
||||
parse_ciphers_macs()
|
||||
{
|
||||
|
||||
@@ -43,18 +43,11 @@ static void read_session_identification(void);
|
||||
|
||||
struct sshsession ses; /* GLOBAL */
|
||||
|
||||
/* need to know if the session struct has been initialised, this way isn't the
|
||||
* cleanest, but works OK */
|
||||
int sessinitdone = 0; /* GLOBAL */
|
||||
|
||||
/* this is set when we get SIGINT or SIGTERM, the handler is in main.c */
|
||||
int exitflag = 0; /* GLOBAL */
|
||||
|
||||
/* called only at the start of a session, set up initial state */
|
||||
void common_session_init(int sock_in, int sock_out) {
|
||||
time_t now;
|
||||
|
||||
#ifdef DEBUG_TRACE
|
||||
#if DEBUG_TRACE
|
||||
debug_start_net();
|
||||
#endif
|
||||
|
||||
@@ -143,7 +136,7 @@ void common_session_init(int sock_in, int sock_out) {
|
||||
TRACE(("leave session_init"))
|
||||
}
|
||||
|
||||
void session_loop(void(*loophandler)()) {
|
||||
void session_loop(void(*loophandler)(void)) {
|
||||
|
||||
fd_set readfd, writefd;
|
||||
struct timeval timeout;
|
||||
@@ -162,7 +155,6 @@ void session_loop(void(*loophandler)()) {
|
||||
/* We get woken up when signal handlers write to this pipe.
|
||||
SIGCHLD in svr-chansession is the only one currently. */
|
||||
FD_SET(ses.signal_pipe[0], &readfd);
|
||||
ses.channel_signal_pending = 0;
|
||||
|
||||
/* set up for channels which can be read/written */
|
||||
setchannelfds(&readfd, &writefd, writequeue_has_space);
|
||||
@@ -190,7 +182,7 @@ void session_loop(void(*loophandler)()) {
|
||||
|
||||
val = select(ses.maxfd+1, &readfd, &writefd, NULL, &timeout);
|
||||
|
||||
if (exitflag) {
|
||||
if (ses.exitflag) {
|
||||
dropbear_exit("Terminated by signal");
|
||||
}
|
||||
|
||||
@@ -210,6 +202,7 @@ void session_loop(void(*loophandler)()) {
|
||||
/* We'll just empty out the pipe if required. We don't do
|
||||
any thing with the data, since the pipe's purpose is purely to
|
||||
wake up the select() above. */
|
||||
ses.channel_signal_pending = 0;
|
||||
if (FD_ISSET(ses.signal_pipe[0], &readfd)) {
|
||||
char x;
|
||||
TRACE(("signal pipe set"))
|
||||
@@ -244,6 +237,10 @@ void session_loop(void(*loophandler)()) {
|
||||
|
||||
handle_connect_fds(&writefd);
|
||||
|
||||
/* loop handler prior to channelio, in case the server loophandler closes
|
||||
channels on process exit */
|
||||
loophandler();
|
||||
|
||||
/* process pipes etc for the channels, ses.dataallowed == 0
|
||||
* during rekeying ) */
|
||||
channelio(&readfd, &writefd);
|
||||
@@ -255,11 +252,6 @@ void session_loop(void(*loophandler)()) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (loophandler) {
|
||||
loophandler();
|
||||
}
|
||||
|
||||
} /* for(;;) */
|
||||
|
||||
/* Not reached */
|
||||
@@ -280,8 +272,8 @@ void session_cleanup() {
|
||||
TRACE(("enter session_cleanup"))
|
||||
|
||||
/* we can't cleanup if we don't know the session state */
|
||||
if (!sessinitdone) {
|
||||
TRACE(("leave session_cleanup: !sessinitdone"))
|
||||
if (!ses.init_done) {
|
||||
TRACE(("leave session_cleanup: !ses.init_done"))
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -295,7 +287,7 @@ void session_cleanup() {
|
||||
}
|
||||
|
||||
/* After these are freed most functions will fail */
|
||||
#ifdef DROPBEAR_CLEANUP
|
||||
#if DROPBEAR_CLEANUP
|
||||
/* listeners call cleanup functions, this should occur before
|
||||
other session state is freed. */
|
||||
remove_all_listeners();
|
||||
|
||||
19
compat.c
19
compat.c
@@ -114,8 +114,8 @@ size_t strlcpy(char *dst, const char *src, size_t size) {
|
||||
#endif /* HAVE_STRLCPY */
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
/* taken from openbsd-compat for OpenSSH 3.6.1p1 */
|
||||
/* "$OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $"
|
||||
/* taken from openbsd-compat for OpenSSH 7.2p2 */
|
||||
/* "$OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $"
|
||||
*
|
||||
* Appends src to string dst of size siz (unlike strncat, siz is the
|
||||
* full size of dst, not space left). At most siz-1 characters
|
||||
@@ -123,15 +123,12 @@ size_t strlcpy(char *dst, const char *src, size_t size) {
|
||||
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
||||
* If retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcat(dst, src, siz)
|
||||
char *dst;
|
||||
const char *src;
|
||||
size_t siz;
|
||||
size_t
|
||||
strlcat(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
register char *d = dst;
|
||||
register const char *s = src;
|
||||
register size_t n = siz;
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||
@@ -177,7 +174,7 @@ int daemon(int nochdir, int noclose) {
|
||||
if (!nochdir)
|
||||
(void)chdir("/");
|
||||
|
||||
if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
|
||||
if (!noclose && (fd = open(DROPBEAR_PATH_DEVNULL, O_RDWR, 0)) != -1) {
|
||||
(void)dup2(fd, STDIN_FILENO);
|
||||
(void)dup2(fd, STDOUT_FILENO);
|
||||
(void)dup2(fd, STDERR_FILENO);
|
||||
|
||||
264
configure.ac
264
configure.ac
@@ -9,19 +9,112 @@ AC_PREREQ(2.59)
|
||||
AC_INIT
|
||||
AC_CONFIG_SRCDIR(buffer.c)
|
||||
|
||||
OLDCFLAGS=$CFLAGS
|
||||
# Checks for programs.
|
||||
AC_PROG_CC
|
||||
AC_PROG_MAKE_SET
|
||||
|
||||
if test -z "$LD" ; then
|
||||
LD=$CC
|
||||
fi
|
||||
AC_SUBST(LD)
|
||||
|
||||
AC_DEFUN(DB_TRYADDCFLAGS,
|
||||
[{
|
||||
OLDFLAGS="$CFLAGS"
|
||||
TESTFLAGS="$1"
|
||||
CFLAGS="$CFLAGS $TESTFLAGS"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
|
||||
[AC_MSG_NOTICE([Setting $TESTFLAGS])],
|
||||
[AC_MSG_NOTICE([Not setting $TESTFLAGS]); CFLAGS="$OLDFLAGS" ]
|
||||
)
|
||||
}])
|
||||
|
||||
# set compile flags prior to other tests
|
||||
if test -z "$OLDCFLAGS" && test "$GCC" = "yes"; then
|
||||
AC_MSG_NOTICE(No \$CFLAGS set... using "-Os -W -Wall" for GCC)
|
||||
CFLAGS="-Os -W -Wall -Wno-pointer-sign"
|
||||
CFLAGS="-Os -W -Wall"
|
||||
fi
|
||||
|
||||
AC_MSG_NOTICE([Checking if compiler '$CC' supports -Wno-pointer-sign])
|
||||
DB_TRYADDCFLAGS([-Wno-pointer-sign])
|
||||
|
||||
AC_MSG_NOTICE([Checking if compiler '$CC' supports -fno-strict-overflow])
|
||||
DB_TRYADDCFLAGS([-fno-strict-overflow])
|
||||
|
||||
STATIC=0
|
||||
AC_ARG_ENABLE(static,
|
||||
[ --enable-static Build static binaries],
|
||||
[
|
||||
if test "x$enableval" = "xyes"; then
|
||||
STATIC=1
|
||||
AC_MSG_NOTICE(Static Build)
|
||||
fi
|
||||
], [])
|
||||
AC_SUBST(STATIC)
|
||||
|
||||
hardenbuild=1
|
||||
AC_ARG_ENABLE(harden,
|
||||
[ --disable-harden Don't set hardened build flags],
|
||||
[
|
||||
if test "x$enableval" = "xno"; then
|
||||
hardenbuild=0
|
||||
AC_MSG_NOTICE(Disabling hardened build flags)
|
||||
fi
|
||||
], [])
|
||||
|
||||
if test "$hardenbuild" -eq 1; then
|
||||
AC_MSG_NOTICE(Checking for available hardened build flags:)
|
||||
# relocation flags don't make sense for static builds
|
||||
if test "$STATIC" -ne 1; then
|
||||
# pie
|
||||
DB_TRYADDCFLAGS([-fPIE])
|
||||
|
||||
OLDLDFLAGS="$LDFLAGS"
|
||||
TESTFLAGS="-Wl,-pie"
|
||||
LDFLAGS="$LDFLAGS $TESTFLAGS"
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
|
||||
[AC_MSG_NOTICE([Setting $TESTFLAGS])],
|
||||
[
|
||||
LDFLAGS="$OLDLDFLAGS"
|
||||
TESTFLAGS="-pie"
|
||||
LDFLAGS="$LDFLAGS $TESTFLAGS"
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
|
||||
[AC_MSG_NOTICE([Setting $TESTFLAGS])],
|
||||
[AC_MSG_NOTICE([Not setting $TESTFLAGS]); LDFLAGS="$OLDLDFLAGS" ]
|
||||
)
|
||||
]
|
||||
)
|
||||
# readonly elf relocation sections (relro)
|
||||
OLDLDFLAGS="$LDFLAGS"
|
||||
TESTFLAGS="-Wl,-z,now -Wl,-z,relro"
|
||||
LDFLAGS="$LDFLAGS $TESTFLAGS"
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
|
||||
[AC_MSG_NOTICE([Setting $TESTFLAGS])],
|
||||
[AC_MSG_NOTICE([Not setting $TESTFLAGS]); LDFLAGS="$OLDLDFLAGS" ]
|
||||
)
|
||||
fi # non-static
|
||||
# stack protector. -strong is good but only in gcc 4.9 or later
|
||||
OLDCFLAGS="$CFLAGS"
|
||||
TESTFLAGS="-fstack-protector-strong"
|
||||
CFLAGS="$CFLAGS $TESTFLAGS"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
|
||||
[AC_MSG_NOTICE([Setting $TESTFLAGS])],
|
||||
[
|
||||
CFLAGS="$OLDCFLAGS"
|
||||
TESTFLAGS="-fstack-protector --param=ssp-buffer-size=4"
|
||||
CFLAGS="$CFLAGS $TESTFLAGS"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
|
||||
[AC_MSG_NOTICE([Setting $TESTFLAGS])],
|
||||
[AC_MSG_NOTICE([Not setting $TESTFLAGS]); CFLAGS="$OLDCFLAGS" ]
|
||||
)
|
||||
]
|
||||
)
|
||||
# FORTIFY_SOURCE
|
||||
DB_TRYADDCFLAGS([-D_FORTIFY_SOURCE=2])
|
||||
|
||||
# Spectre v2 mitigations
|
||||
DB_TRYADDCFLAGS([-mfunction-return=thunk])
|
||||
DB_TRYADDCFLAGS([-mindirect-branch=thunk])
|
||||
|
||||
fi
|
||||
|
||||
# large file support is useful for scp
|
||||
@@ -45,8 +138,8 @@ case "$host" in
|
||||
sol2ver=`echo "$host"| sed -e 's/.*[[0-9]]\.//'`
|
||||
if test "$sol2ver" -ge 8; then
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(DISABLE_UTMP,,Disable utmp)
|
||||
AC_DEFINE(DISABLE_WTMP,,Disable wtmp)
|
||||
AC_DEFINE(DISABLE_UTMP,1,Disable utmp)
|
||||
AC_DEFINE(DISABLE_WTMP,1,Disable wtmp)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
@@ -55,18 +148,18 @@ case "$host" in
|
||||
;;
|
||||
|
||||
*-*-aix*)
|
||||
AC_DEFINE(AIX,,Using AIX)
|
||||
AC_DEFINE(AIX,1,Using AIX)
|
||||
# OpenSSH thinks it's broken. If it isn't, let me know.
|
||||
AC_DEFINE(BROKEN_GETADDRINFO,,Broken getaddrinfo)
|
||||
AC_DEFINE(BROKEN_GETADDRINFO,1,Broken getaddrinfo)
|
||||
;;
|
||||
|
||||
*-*-hpux*)
|
||||
LIBS="$LIBS -lsec"
|
||||
# It's probably broken.
|
||||
AC_DEFINE(BROKEN_GETADDRINFO,,Broken getaddrinfo)
|
||||
AC_DEFINE(BROKEN_GETADDRINFO,1,Broken getaddrinfo)
|
||||
;;
|
||||
*-dec-osf*)
|
||||
AC_DEFINE(BROKEN_GETADDRINFO,,Broken getaddrinfo)
|
||||
AC_DEFINE(BROKEN_GETADDRINFO,1,Broken getaddrinfo)
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -80,7 +173,7 @@ AC_CHECK_DECL(__UCLIBC__,
|
||||
[
|
||||
no_loginfunc_check=1
|
||||
AC_MSG_NOTICE([Using uClibc - login() and logout() probably don't work, so we won't use them.])
|
||||
],,,)
|
||||
],,)
|
||||
|
||||
dnl We test for crypt() specially. On Linux (and others?) it resides in libcrypt
|
||||
dnl but we don't want link all binaries to -lcrypt, just dropbear server.
|
||||
@@ -118,7 +211,7 @@ AC_ARG_ENABLE(zlib,
|
||||
[ --disable-zlib Don't include zlib support],
|
||||
[
|
||||
if test "x$enableval" = "xno"; then
|
||||
AC_DEFINE(DISABLE_ZLIB,, Use zlib)
|
||||
AC_DEFINE(DISABLE_ZLIB,1,Use zlib)
|
||||
AC_MSG_NOTICE(Disabling zlib)
|
||||
else
|
||||
AC_CHECK_LIB(z, deflate, , AC_MSG_ERROR([*** zlib missing - install first or check config.log ***]))
|
||||
@@ -152,20 +245,20 @@ AC_ARG_WITH(pam,
|
||||
|
||||
|
||||
AC_ARG_ENABLE(pam,
|
||||
[ --enable-pam Try to include PAM support],
|
||||
[ --enable-pam Try to include PAM support],
|
||||
[
|
||||
if test "x$enableval" = "xyes"; then
|
||||
AC_CHECK_LIB(pam, pam_authenticate, , AC_MSG_ERROR([*** PAM missing - install first or check config.log ***]))
|
||||
AC_MSG_NOTICE(Enabling PAM)
|
||||
AC_CHECK_FUNCS(pam_fail_delay)
|
||||
else
|
||||
AC_DEFINE(DISABLE_PAM,, Use PAM)
|
||||
AC_DEFINE(DISABLE_PAM,1,Use PAM)
|
||||
AC_MSG_NOTICE(Disabling PAM)
|
||||
fi
|
||||
],
|
||||
[
|
||||
# disable it by default
|
||||
AC_DEFINE(DISABLE_PAM,, Use PAM)
|
||||
AC_DEFINE(DISABLE_PAM,1,Use PAM)
|
||||
AC_MSG_NOTICE(Disabling PAM)
|
||||
]
|
||||
)
|
||||
@@ -177,21 +270,26 @@ AC_ARG_ENABLE(openpty,
|
||||
AC_MSG_NOTICE(Not using openpty)
|
||||
else
|
||||
AC_MSG_NOTICE(Using openpty if available)
|
||||
AC_SEARCH_LIBS(openpty, util, [AC_DEFINE(HAVE_OPENPTY,,Have openpty() function)])
|
||||
AC_SEARCH_LIBS(openpty, util, [dropbear_cv_func_have_openpty=yes])
|
||||
fi
|
||||
],
|
||||
[
|
||||
AC_MSG_NOTICE(Using openpty if available)
|
||||
AC_SEARCH_LIBS(openpty, util, [AC_DEFINE(HAVE_OPENPTY)])
|
||||
AC_SEARCH_LIBS(openpty, util, [dropbear_cv_func_have_openpty=yes])
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
if test "x$dropbear_cv_func_have_openpty" = "xyes"; then
|
||||
AC_DEFINE(HAVE_OPENPTY,,Have openpty() function)
|
||||
no_ptc_check=yes
|
||||
no_ptmx_check=yes
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(syslog,
|
||||
[ --disable-syslog Don't include syslog support],
|
||||
[
|
||||
if test "x$enableval" = "xno"; then
|
||||
AC_DEFINE(DISABLE_SYSLOG,, Using syslog)
|
||||
AC_DEFINE(DISABLE_SYSLOG,1,Using syslog)
|
||||
AC_MSG_NOTICE(Disabling syslog)
|
||||
else
|
||||
AC_MSG_NOTICE(Enabling syslog)
|
||||
@@ -222,7 +320,11 @@ AC_ARG_ENABLE(shadow,
|
||||
# Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
AC_HEADER_SYS_WAIT
|
||||
AC_CHECK_HEADERS([fcntl.h limits.h netinet/in.h netinet/tcp.h stdlib.h string.h sys/socket.h sys/time.h termios.h unistd.h crypt.h pty.h ioctl.h libutil.h libgen.h inttypes.h stropts.h utmp.h utmpx.h lastlog.h paths.h util.h netdb.h security/pam_appl.h pam/pam_appl.h netinet/in_systm.h sys/uio.h])
|
||||
AC_CHECK_HEADERS([netinet/in.h netinet/tcp.h \
|
||||
crypt.h \
|
||||
pty.h libutil.h libgen.h inttypes.h stropts.h utmp.h \
|
||||
utmpx.h lastlog.h paths.h util.h netdb.h security/pam_appl.h \
|
||||
pam/pam_appl.h netinet/in_systm.h sys/uio.h linux/pkt_sched.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_CONST
|
||||
@@ -295,7 +397,7 @@ AC_CACHE_CHECK([for struct sockaddr_in6], ac_cv_have_struct_sockaddr_in6, [
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_have_struct_sockaddr_in6" = "xyes" ; then
|
||||
AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6,,Have struct sockaddr_in6)
|
||||
AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6,1,Have struct sockaddr_in6)
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([for struct in6_addr], ac_cv_have_struct_in6_addr, [
|
||||
@@ -309,7 +411,7 @@ AC_CACHE_CHECK([for struct in6_addr], ac_cv_have_struct_in6_addr, [
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_have_struct_in6_addr" = "xyes" ; then
|
||||
AC_DEFINE(HAVE_STRUCT_IN6_ADDR,,Have struct in6_addr)
|
||||
AC_DEFINE(HAVE_STRUCT_IN6_ADDR,1,Have struct in6_addr)
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([for struct addrinfo], ac_cv_have_struct_addrinfo, [
|
||||
@@ -324,7 +426,7 @@ AC_CACHE_CHECK([for struct addrinfo], ac_cv_have_struct_addrinfo, [
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_have_struct_addrinfo" = "xyes" ; then
|
||||
AC_DEFINE(HAVE_STRUCT_ADDRINFO,,Have struct addrinfo)
|
||||
AC_DEFINE(HAVE_STRUCT_ADDRINFO,1,Have struct addrinfo)
|
||||
fi
|
||||
|
||||
|
||||
@@ -377,7 +479,6 @@ AC_CHECK_FUNCS(mach_absolute_time)
|
||||
|
||||
AC_CHECK_FUNCS(explicit_bzero memset_s)
|
||||
|
||||
|
||||
AC_ARG_ENABLE(bundled-libtom,
|
||||
[ --enable-bundled-libtom Force using bundled libtomcrypt/libtommath even if a system version exists.
|
||||
--disable-bundled-libtom Force using system libtomcrypt/libtommath, fail if it does not exist.
|
||||
@@ -388,21 +489,21 @@ AC_ARG_ENABLE(bundled-libtom,
|
||||
AC_MSG_NOTICE(Forcing bundled libtom*)
|
||||
else
|
||||
BUNDLED_LIBTOM=0
|
||||
AC_CHECK_LIB(tommath, mp_exptmod, LIBTOM_LIBS="$LIBTOM_LIBS -ltommath",
|
||||
AC_CHECK_LIB(tommath, mp_exptmod, LIBTOM_LIBS="-ltommath $LIBTOM_LIBS",
|
||||
[AC_MSG_ERROR([Missing system libtommath and --disable-bundled-libtom was specified])] )
|
||||
AC_CHECK_LIB(tomcrypt, register_cipher, LIBTOM_LIBS="$LIBTOM_LIBS -ltomcrypt",
|
||||
AC_CHECK_LIB(tomcrypt, register_cipher, LIBTOM_LIBS="-ltomcrypt $LIBTOM_LIBS",
|
||||
[AC_MSG_ERROR([Missing system libtomcrypt and --disable-bundled-libtom was specified])] )
|
||||
fi
|
||||
],
|
||||
[
|
||||
BUNDLED_LIBTOM=0
|
||||
AC_CHECK_LIB(tommath, mp_exptmod, LIBTOM_LIBS="$LIBTOM_LIBS -ltommath", BUNDLED_LIBTOM=1)
|
||||
AC_CHECK_LIB(tomcrypt, register_cipher, LIBTOM_LIBS="$LIBTOM_LIBS -ltomcrypt", BUNDLED_LIBTOM=1)
|
||||
AC_CHECK_LIB(tommath, mp_exptmod, LIBTOM_LIBS="-ltommath $LIBTOM_LIBS", BUNDLED_LIBTOM=1)
|
||||
AC_CHECK_LIB(tomcrypt, register_cipher, LIBTOM_LIBS="-ltomcrypt $LIBTOM_LIBS", BUNDLED_LIBTOM=1)
|
||||
]
|
||||
)
|
||||
|
||||
if test $BUNDLED_LIBTOM = 1 ; then
|
||||
AC_DEFINE(BUNDLED_LIBTOM,,Use bundled libtom)
|
||||
AC_DEFINE(BUNDLED_LIBTOM,1,Use bundled libtom)
|
||||
fi
|
||||
|
||||
AC_SUBST(LIBTOM_LIBS)
|
||||
@@ -413,36 +514,64 @@ dnl Added from OpenSSH 3.6.1p2's configure.ac
|
||||
dnl allow user to disable some login recording features
|
||||
AC_ARG_ENABLE(lastlog,
|
||||
[ --disable-lastlog Disable use of lastlog even if detected [no]],
|
||||
[ AC_DEFINE(DISABLE_LASTLOG,,Disable use of lastlog()) ]
|
||||
[
|
||||
if test "x$enableval" = "xno" ; then
|
||||
AC_DEFINE(DISABLE_LASTLOG,1,Disable use of lastlog())
|
||||
fi
|
||||
]
|
||||
)
|
||||
AC_ARG_ENABLE(utmp,
|
||||
[ --disable-utmp Disable use of utmp even if detected [no]],
|
||||
[ AC_DEFINE(DISABLE_UTMP,,Disable use of utmp) ]
|
||||
[
|
||||
if test "x$enableval" = "xno" ; then
|
||||
AC_DEFINE(DISABLE_UTMP,1,Disable use of utmp)
|
||||
fi
|
||||
]
|
||||
)
|
||||
AC_ARG_ENABLE(utmpx,
|
||||
[ --disable-utmpx Disable use of utmpx even if detected [no]],
|
||||
[ AC_DEFINE(DISABLE_UTMPX,,Disable use of utmpx) ]
|
||||
[
|
||||
if test "x$enableval" = "xno" ; then
|
||||
AC_DEFINE(DISABLE_UTMPX,1,Disable use of utmpx)
|
||||
fi
|
||||
]
|
||||
)
|
||||
AC_ARG_ENABLE(wtmp,
|
||||
[ --disable-wtmp Disable use of wtmp even if detected [no]],
|
||||
[ AC_DEFINE(DISABLE_WTMP,,Disable use of wtmp) ]
|
||||
[
|
||||
if test "x$enableval" = "xno" ; then
|
||||
AC_DEFINE(DISABLE_WTMP,1,Disable use of wtmp)
|
||||
fi
|
||||
]
|
||||
)
|
||||
AC_ARG_ENABLE(wtmpx,
|
||||
[ --disable-wtmpx Disable use of wtmpx even if detected [no]],
|
||||
[ AC_DEFINE(DISABLE_WTMPX,,Disable use of wtmpx) ]
|
||||
[
|
||||
if test "x$enableval" = "xno" ; then
|
||||
AC_DEFINE(DISABLE_WTMPX,1,Disable use of wtmpx)
|
||||
fi
|
||||
]
|
||||
)
|
||||
AC_ARG_ENABLE(loginfunc,
|
||||
[ --disable-loginfunc Disable use of login() etc. [no]],
|
||||
[ no_loginfunc_check=1
|
||||
AC_MSG_NOTICE(Not using login() etc) ]
|
||||
AC_MSG_NOTICE([Not using login() etc]) ]
|
||||
)
|
||||
AC_ARG_ENABLE(pututline,
|
||||
[ --disable-pututline Disable use of pututline() etc. ([uw]tmp) [no]],
|
||||
[ AC_DEFINE(DISABLE_PUTUTLINE,,Disable use of pututline()) ]
|
||||
[
|
||||
if test "x$enableval" = "xno" ; then
|
||||
AC_DEFINE(DISABLE_PUTUTLINE,1,Disable use of pututline())
|
||||
fi
|
||||
]
|
||||
)
|
||||
AC_ARG_ENABLE(pututxline,
|
||||
[ --disable-pututxline Disable use of pututxline() etc. ([uw]tmpx) [no]],
|
||||
[ AC_DEFINE(DISABLE_PUTUTXLINE,,Disable use of pututxline()) ]
|
||||
[
|
||||
if test "x$enableval" = "xno" ; then
|
||||
AC_DEFINE(DISABLE_PUTUTXLINE,1,Disable use of pututxline())
|
||||
fi
|
||||
]
|
||||
)
|
||||
AC_ARG_WITH(lastlog,
|
||||
[ --with-lastlog=FILE|DIR specify lastlog location [common locations]],
|
||||
@@ -457,7 +586,7 @@ AC_ARG_WITH(lastlog,
|
||||
|
||||
if test -z "$no_loginfunc_check"; then
|
||||
dnl Checks for libutil functions (login(), logout() etc, not openpty() )
|
||||
AC_SEARCH_LIBS(login, util bsd, [AC_DEFINE(HAVE_LOGIN,,Have login() function)])
|
||||
AC_SEARCH_LIBS(login, util bsd, [AC_DEFINE(HAVE_LOGIN,1,[Have login() function])])
|
||||
AC_CHECK_FUNCS(logout updwtmp logwtmp)
|
||||
fi
|
||||
|
||||
@@ -645,7 +774,9 @@ fi
|
||||
AC_PROG_GCC_TRADITIONAL
|
||||
AC_FUNC_MEMCMP
|
||||
AC_FUNC_SELECT_ARGTYPES
|
||||
AC_CHECK_FUNCS([dup2 getpass getspnam getusershell memset putenv select socket strdup clearenv strlcpy strlcat daemon basename _getpty getaddrinfo freeaddrinfo getnameinfo fork writev])
|
||||
AC_CHECK_FUNCS([getpass getspnam getusershell putenv])
|
||||
AC_CHECK_FUNCS([clearenv strlcpy strlcat daemon basename _getpty getaddrinfo ])
|
||||
AC_CHECK_FUNCS([freeaddrinfo getnameinfo fork writev getgrouplist])
|
||||
|
||||
AC_SEARCH_LIBS(basename, gen, AC_DEFINE(HAVE_BASENAME))
|
||||
|
||||
@@ -653,7 +784,7 @@ AC_SEARCH_LIBS(basename, gen, AC_DEFINE(HAVE_BASENAME))
|
||||
if test -z "$no_ptmx_check" ; then
|
||||
if test x"$cross_compiling" = x"no" ; then
|
||||
if test -e /dev/ptmx ; then
|
||||
AC_DEFINE(USE_DEV_PTMX,,Use /dev/ptmx)
|
||||
AC_DEFINE(USE_DEV_PTMX,1,Use /dev/ptmx)
|
||||
fi
|
||||
else
|
||||
AC_MSG_NOTICE([Not checking for /dev/ptmx, we're cross-compiling])
|
||||
@@ -663,7 +794,7 @@ fi
|
||||
if test -z "$no_ptc_check" ; then
|
||||
if test x"$cross_compiling" = x"no" ; then
|
||||
if test -e /dev/ptc ; then
|
||||
AC_DEFINE(HAVE_DEV_PTS_AND_PTC,,Use /dev/ptc & /dev/pts)
|
||||
AC_DEFINE(HAVE_DEV_PTS_AND_PTC,1,Use /dev/ptc & /dev/pts)
|
||||
fi
|
||||
else
|
||||
AC_MSG_NOTICE([Not checking for /dev/ptc & /dev/pts since we're cross-compiling])
|
||||
@@ -672,60 +803,11 @@ fi
|
||||
|
||||
AC_EXEEXT
|
||||
|
||||
# XXX there must be a nicer way to do this
|
||||
if test $BUNDLED_LIBTOM = 1 ; then
|
||||
AS_MKDIR_P(libtomcrypt/src/ciphers/aes)
|
||||
AS_MKDIR_P(libtomcrypt/src/ciphers/safer)
|
||||
AS_MKDIR_P(libtomcrypt/src/ciphers/twofish)
|
||||
AS_MKDIR_P(libtomcrypt/src/encauth/ccm)
|
||||
AS_MKDIR_P(libtomcrypt/src/encauth/eax)
|
||||
AS_MKDIR_P(libtomcrypt/src/encauth/gcm)
|
||||
AS_MKDIR_P(libtomcrypt/src/encauth/ocb)
|
||||
AS_MKDIR_P(libtomcrypt/src/hashes)
|
||||
AS_MKDIR_P(libtomcrypt/src/hashes/chc)
|
||||
AS_MKDIR_P(libtomcrypt/src/hashes/helper)
|
||||
AS_MKDIR_P(libtomcrypt/src/hashes/sha2)
|
||||
AS_MKDIR_P(libtomcrypt/src/hashes/whirl)
|
||||
AS_MKDIR_P(libtomcrypt/src/mac/hmac)
|
||||
AS_MKDIR_P(libtomcrypt/src/mac/omac)
|
||||
AS_MKDIR_P(libtomcrypt/src/mac/pelican)
|
||||
AS_MKDIR_P(libtomcrypt/src/mac/pmac)
|
||||
AS_MKDIR_P(libtomcrypt/src/mac/f9)
|
||||
AS_MKDIR_P(libtomcrypt/src/mac/xcbc)
|
||||
AS_MKDIR_P(libtomcrypt/src/math/fp)
|
||||
AS_MKDIR_P(libtomcrypt/src/misc/base64)
|
||||
AS_MKDIR_P(libtomcrypt/src/misc/crypt)
|
||||
AS_MKDIR_P(libtomcrypt/src/misc/mpi)
|
||||
AS_MKDIR_P(libtomcrypt/src/misc/pkcs5)
|
||||
AS_MKDIR_P(libtomcrypt/src/modes/cbc)
|
||||
AS_MKDIR_P(libtomcrypt/src/modes/cfb)
|
||||
AS_MKDIR_P(libtomcrypt/src/modes/ctr)
|
||||
AS_MKDIR_P(libtomcrypt/src/modes/ecb)
|
||||
AS_MKDIR_P(libtomcrypt/src/modes/ofb)
|
||||
AS_MKDIR_P(libtomcrypt/src/modes/f8)
|
||||
AS_MKDIR_P(libtomcrypt/src/modes/lrw)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/bit)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/boolean)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/choice)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/ia5)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/integer)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/object_identifier)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/octet)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/printable_string)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/sequence)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/set)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/short_integer)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/utctime)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/asn1/der/utf8)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/dh)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/dsa)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/ecc)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/katja)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/pkcs1)
|
||||
AS_MKDIR_P(libtomcrypt/src/pk/rsa)
|
||||
AS_MKDIR_P(libtomcrypt/src/prngs)
|
||||
(cd $srcdir; find libtomcrypt -type d) | xargs mkdir -pv
|
||||
LIBTOM_FILES="libtomcrypt/Makefile libtommath/Makefile"
|
||||
fi
|
||||
|
||||
AC_CONFIG_HEADER(config.h)
|
||||
AC_CONFIG_FILES(Makefile $LIBTOM_FILES)
|
||||
AC_OUTPUT
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "ltc_prng.h"
|
||||
#include "ecc.h"
|
||||
|
||||
#ifdef DROPBEAR_LTC_PRNG
|
||||
#if DROPBEAR_LTC_PRNG
|
||||
int dropbear_ltc_prng = -1;
|
||||
#endif
|
||||
|
||||
@@ -14,16 +14,16 @@
|
||||
void crypto_init() {
|
||||
|
||||
const struct ltc_cipher_descriptor *regciphers[] = {
|
||||
#ifdef DROPBEAR_AES
|
||||
#if DROPBEAR_AES
|
||||
&aes_desc,
|
||||
#endif
|
||||
#ifdef DROPBEAR_BLOWFISH
|
||||
#if DROPBEAR_BLOWFISH
|
||||
&blowfish_desc,
|
||||
#endif
|
||||
#ifdef DROPBEAR_TWOFISH
|
||||
#if DROPBEAR_TWOFISH
|
||||
&twofish_desc,
|
||||
#endif
|
||||
#ifdef DROPBEAR_3DES
|
||||
#if DROPBEAR_3DES
|
||||
&des3_desc,
|
||||
#endif
|
||||
NULL
|
||||
@@ -32,16 +32,16 @@ void crypto_init() {
|
||||
const struct ltc_hash_descriptor *reghashes[] = {
|
||||
/* we need sha1 for hostkey stuff regardless */
|
||||
&sha1_desc,
|
||||
#ifdef DROPBEAR_MD5_HMAC
|
||||
#if DROPBEAR_MD5_HMAC
|
||||
&md5_desc,
|
||||
#endif
|
||||
#ifdef DROPBEAR_SHA256
|
||||
#if DROPBEAR_SHA256
|
||||
&sha256_desc,
|
||||
#endif
|
||||
#ifdef DROPBEAR_SHA384
|
||||
#if DROPBEAR_SHA384
|
||||
&sha384_desc,
|
||||
#endif
|
||||
#ifdef DROPBEAR_SHA512
|
||||
#if DROPBEAR_SHA512
|
||||
&sha512_desc,
|
||||
#endif
|
||||
NULL
|
||||
@@ -60,14 +60,14 @@ void crypto_init() {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DROPBEAR_LTC_PRNG
|
||||
#if DROPBEAR_LTC_PRNG
|
||||
dropbear_ltc_prng = register_prng(&dropbear_prng_desc);
|
||||
if (dropbear_ltc_prng == -1) {
|
||||
dropbear_exit("Error registering crypto");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DROPBEAR_ECC
|
||||
#if DROPBEAR_ECC
|
||||
ltc_mp = ltm_desc;
|
||||
dropbear_ecc_fill_dp();
|
||||
#endif
|
||||
|
||||
@@ -43,8 +43,7 @@
|
||||
*
|
||||
* This is, almost, a clean room reimplementation from the curve25519 paper. It
|
||||
* uses many of the tricks described therein. Only the crecip function is taken
|
||||
* from the sample implementation.
|
||||
*/
|
||||
* from the sample implementation. */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
@@ -63,25 +62,23 @@ typedef int64_t limb;
|
||||
* significant first. The value of the field element is:
|
||||
* x[0] + 2^26·x[1] + x^51·x[2] + 2^102·x[3] + ...
|
||||
*
|
||||
* i.e. the limbs are 26, 25, 26, 25, ... bits wide.
|
||||
*/
|
||||
* i.e. the limbs are 26, 25, 26, 25, ... bits wide. */
|
||||
|
||||
/* Sum two numbers: output += in */
|
||||
static void fsum(limb *output, const limb *in) {
|
||||
unsigned i;
|
||||
for (i = 0; i < 10; i += 2) {
|
||||
output[0+i] = (output[0+i] + in[0+i]);
|
||||
output[1+i] = (output[1+i] + in[1+i]);
|
||||
output[0+i] = output[0+i] + in[0+i];
|
||||
output[1+i] = output[1+i] + in[1+i];
|
||||
}
|
||||
}
|
||||
|
||||
/* Find the difference of two numbers: output = in - output
|
||||
* (note the order of the arguments!)
|
||||
*/
|
||||
* (note the order of the arguments!). */
|
||||
static void fdifference(limb *output, const limb *in) {
|
||||
unsigned i;
|
||||
for (i = 0; i < 10; ++i) {
|
||||
output[i] = (in[i] - output[i]);
|
||||
output[i] = in[i] - output[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +94,8 @@ static void fscalar_product(limb *output, const limb *in, const limb scalar) {
|
||||
*
|
||||
* output must be distinct to both inputs. The inputs are reduced coefficient
|
||||
* form, the output is not.
|
||||
*/
|
||||
*
|
||||
* output[x] <= 14 * the largest product of the input limbs. */
|
||||
static void fproduct(limb *output, const limb *in2, const limb *in) {
|
||||
output[0] = ((limb) ((s32) in2[0])) * ((s32) in[0]);
|
||||
output[1] = ((limb) ((s32) in2[0])) * ((s32) in[1]) +
|
||||
@@ -201,9 +199,15 @@ static void fproduct(limb *output, const limb *in2, const limb *in) {
|
||||
output[18] = 2 * ((limb) ((s32) in2[9])) * ((s32) in[9]);
|
||||
}
|
||||
|
||||
/* Reduce a long form to a short form by taking the input mod 2^255 - 19. */
|
||||
/* Reduce a long form to a short form by taking the input mod 2^255 - 19.
|
||||
*
|
||||
* On entry: |output[i]| < 14*2^54
|
||||
* On exit: |output[0..8]| < 280*2^54 */
|
||||
static void freduce_degree(limb *output) {
|
||||
/* Each of these shifts and adds ends up multiplying the value by 19. */
|
||||
/* Each of these shifts and adds ends up multiplying the value by 19.
|
||||
*
|
||||
* For output[0..8], the absolute entry value is < 14*2^54 and we add, at
|
||||
* most, 19*14*2^54 thus, on exit, |output[0..8]| < 280*2^54. */
|
||||
output[8] += output[18] << 4;
|
||||
output[8] += output[18] << 1;
|
||||
output[8] += output[18];
|
||||
@@ -237,11 +241,13 @@ static void freduce_degree(limb *output) {
|
||||
#error "This code only works on a two's complement system"
|
||||
#endif
|
||||
|
||||
/* return v / 2^26, using only shifts and adds. */
|
||||
/* return v / 2^26, using only shifts and adds.
|
||||
*
|
||||
* On entry: v can take any value. */
|
||||
static inline limb
|
||||
div_by_2_26(const limb v)
|
||||
{
|
||||
/* High word of v; no shift needed*/
|
||||
/* High word of v; no shift needed. */
|
||||
const uint32_t highword = (uint32_t) (((uint64_t) v) >> 32);
|
||||
/* Set to all 1s if v was negative; else set to 0s. */
|
||||
const int32_t sign = ((int32_t) highword) >> 31;
|
||||
@@ -251,7 +257,9 @@ div_by_2_26(const limb v)
|
||||
return (v + roundoff) >> 26;
|
||||
}
|
||||
|
||||
/* return v / (2^25), using only shifts and adds. */
|
||||
/* return v / (2^25), using only shifts and adds.
|
||||
*
|
||||
* On entry: v can take any value. */
|
||||
static inline limb
|
||||
div_by_2_25(const limb v)
|
||||
{
|
||||
@@ -265,17 +273,9 @@ div_by_2_25(const limb v)
|
||||
return (v + roundoff) >> 25;
|
||||
}
|
||||
|
||||
static inline s32
|
||||
div_s32_by_2_25(const s32 v)
|
||||
{
|
||||
const s32 roundoff = ((uint32_t)(v >> 31)) >> 7;
|
||||
return (v + roundoff) >> 25;
|
||||
}
|
||||
|
||||
/* Reduce all coefficients of the short form input so that |x| < 2^26.
|
||||
*
|
||||
* On entry: |output[i]| < 2^62
|
||||
*/
|
||||
* On entry: |output[i]| < 280*2^54 */
|
||||
static void freduce_coefficients(limb *output) {
|
||||
unsigned i;
|
||||
|
||||
@@ -283,56 +283,65 @@ static void freduce_coefficients(limb *output) {
|
||||
|
||||
for (i = 0; i < 10; i += 2) {
|
||||
limb over = div_by_2_26(output[i]);
|
||||
/* The entry condition (that |output[i]| < 280*2^54) means that over is, at
|
||||
* most, 280*2^28 in the first iteration of this loop. This is added to the
|
||||
* next limb and we can approximate the resulting bound of that limb by
|
||||
* 281*2^54. */
|
||||
output[i] -= over << 26;
|
||||
output[i+1] += over;
|
||||
|
||||
/* For the first iteration, |output[i+1]| < 281*2^54, thus |over| <
|
||||
* 281*2^29. When this is added to the next limb, the resulting bound can
|
||||
* be approximated as 281*2^54.
|
||||
*
|
||||
* For subsequent iterations of the loop, 281*2^54 remains a conservative
|
||||
* bound and no overflow occurs. */
|
||||
over = div_by_2_25(output[i+1]);
|
||||
output[i+1] -= over << 25;
|
||||
output[i+2] += over;
|
||||
}
|
||||
/* Now |output[10]| < 2 ^ 38 and all other coefficients are reduced. */
|
||||
/* Now |output[10]| < 281*2^29 and all other coefficients are reduced. */
|
||||
output[0] += output[10] << 4;
|
||||
output[0] += output[10] << 1;
|
||||
output[0] += output[10];
|
||||
|
||||
output[10] = 0;
|
||||
|
||||
/* Now output[1..9] are reduced, and |output[0]| < 2^26 + 19 * 2^38
|
||||
* So |over| will be no more than 77825 */
|
||||
/* Now output[1..9] are reduced, and |output[0]| < 2^26 + 19*281*2^29
|
||||
* So |over| will be no more than 2^16. */
|
||||
{
|
||||
limb over = div_by_2_26(output[0]);
|
||||
output[0] -= over << 26;
|
||||
output[1] += over;
|
||||
}
|
||||
|
||||
/* Now output[0,2..9] are reduced, and |output[1]| < 2^25 + 77825
|
||||
* So |over| will be no more than 1. */
|
||||
{
|
||||
/* output[1] fits in 32 bits, so we can use div_s32_by_2_25 here. */
|
||||
s32 over32 = div_s32_by_2_25((s32) output[1]);
|
||||
output[1] -= over32 << 25;
|
||||
output[2] += over32;
|
||||
}
|
||||
|
||||
/* Finally, output[0,1,3..9] are reduced, and output[2] is "nearly reduced":
|
||||
* we have |output[2]| <= 2^26. This is good enough for all of our math,
|
||||
* but it will require an extra freduce_coefficients before fcontract. */
|
||||
/* Now output[0,2..9] are reduced, and |output[1]| < 2^25 + 2^16 < 2^26. The
|
||||
* bound on |output[1]| is sufficient to meet our needs. */
|
||||
}
|
||||
|
||||
/* A helpful wrapper around fproduct: output = in * in2.
|
||||
*
|
||||
* output must be distinct to both inputs. The output is reduced degree and
|
||||
* reduced coefficient.
|
||||
*/
|
||||
* On entry: |in[i]| < 2^27 and |in2[i]| < 2^27.
|
||||
*
|
||||
* output must be distinct to both inputs. The output is reduced degree
|
||||
* (indeed, one need only provide storage for 10 limbs) and |output[i]| < 2^26. */
|
||||
static void
|
||||
fmul(limb *output, const limb *in, const limb *in2) {
|
||||
limb t[19];
|
||||
fproduct(t, in, in2);
|
||||
/* |t[i]| < 14*2^54 */
|
||||
freduce_degree(t);
|
||||
freduce_coefficients(t);
|
||||
/* |t[i]| < 2^26 */
|
||||
memcpy(output, t, sizeof(limb) * 10);
|
||||
}
|
||||
|
||||
/* Square a number: output = in**2
|
||||
*
|
||||
* output must be distinct from the input. The inputs are reduced coefficient
|
||||
* form, the output is not.
|
||||
*
|
||||
* output[x] <= 14 * the largest product of the input limbs. */
|
||||
static void fsquare_inner(limb *output, const limb *in) {
|
||||
output[0] = ((limb) ((s32) in[0])) * ((s32) in[0]);
|
||||
output[1] = 2 * ((limb) ((s32) in[0])) * ((s32) in[1]);
|
||||
@@ -391,12 +400,23 @@ static void fsquare_inner(limb *output, const limb *in) {
|
||||
output[18] = 2 * ((limb) ((s32) in[9])) * ((s32) in[9]);
|
||||
}
|
||||
|
||||
/* fsquare sets output = in^2.
|
||||
*
|
||||
* On entry: The |in| argument is in reduced coefficients form and |in[i]| <
|
||||
* 2^27.
|
||||
*
|
||||
* On exit: The |output| argument is in reduced coefficients form (indeed, one
|
||||
* need only provide storage for 10 limbs) and |out[i]| < 2^26. */
|
||||
static void
|
||||
fsquare(limb *output, const limb *in) {
|
||||
limb t[19];
|
||||
fsquare_inner(t, in);
|
||||
/* |t[i]| < 14*2^54 because the largest product of two limbs will be <
|
||||
* 2^(27+27) and fsquare_inner adds together, at most, 14 of those
|
||||
* products. */
|
||||
freduce_degree(t);
|
||||
freduce_coefficients(t);
|
||||
/* |t[i]| < 2^26 */
|
||||
memcpy(output, t, sizeof(limb) * 10);
|
||||
}
|
||||
|
||||
@@ -417,7 +437,7 @@ fexpand(limb *output, const u8 *input) {
|
||||
F(6, 19, 1, 0x3ffffff);
|
||||
F(7, 22, 3, 0x1ffffff);
|
||||
F(8, 25, 4, 0x3ffffff);
|
||||
F(9, 28, 6, 0x3ffffff);
|
||||
F(9, 28, 6, 0x1ffffff);
|
||||
#undef F
|
||||
}
|
||||
|
||||
@@ -425,60 +445,143 @@ fexpand(limb *output, const u8 *input) {
|
||||
#error "This code only works when >> does sign-extension on negative numbers"
|
||||
#endif
|
||||
|
||||
/* s32_eq returns 0xffffffff iff a == b and zero otherwise. */
|
||||
static s32 s32_eq(s32 a, s32 b) {
|
||||
a = ~(a ^ b);
|
||||
a &= a << 16;
|
||||
a &= a << 8;
|
||||
a &= a << 4;
|
||||
a &= a << 2;
|
||||
a &= a << 1;
|
||||
return a >> 31;
|
||||
}
|
||||
|
||||
/* s32_gte returns 0xffffffff if a >= b and zero otherwise, where a and b are
|
||||
* both non-negative. */
|
||||
static s32 s32_gte(s32 a, s32 b) {
|
||||
a -= b;
|
||||
/* a >= 0 iff a >= b. */
|
||||
return ~(a >> 31);
|
||||
}
|
||||
|
||||
/* Take a fully reduced polynomial form number and contract it into a
|
||||
* little-endian, 32-byte array
|
||||
*/
|
||||
* little-endian, 32-byte array.
|
||||
*
|
||||
* On entry: |input_limbs[i]| < 2^26 */
|
||||
static void
|
||||
fcontract(u8 *output, limb *input) {
|
||||
fcontract(u8 *output, limb *input_limbs) {
|
||||
int i;
|
||||
int j;
|
||||
s32 input[10];
|
||||
s32 mask;
|
||||
|
||||
/* |input_limbs[i]| < 2^26, so it's valid to convert to an s32. */
|
||||
for (i = 0; i < 10; i++) {
|
||||
input[i] = input_limbs[i];
|
||||
}
|
||||
|
||||
for (j = 0; j < 2; ++j) {
|
||||
for (i = 0; i < 9; ++i) {
|
||||
if ((i & 1) == 1) {
|
||||
/* This calculation is a time-invariant way to make input[i] positive
|
||||
by borrowing from the next-larger limb.
|
||||
*/
|
||||
const s32 mask = (s32)(input[i]) >> 31;
|
||||
const s32 carry = -(((s32)(input[i]) & mask) >> 25);
|
||||
input[i] = (s32)(input[i]) + (carry << 25);
|
||||
input[i+1] = (s32)(input[i+1]) - carry;
|
||||
/* This calculation is a time-invariant way to make input[i]
|
||||
* non-negative by borrowing from the next-larger limb. */
|
||||
const s32 mask = input[i] >> 31;
|
||||
const s32 carry = -((input[i] & mask) >> 25);
|
||||
input[i] = input[i] + (carry << 25);
|
||||
input[i+1] = input[i+1] - carry;
|
||||
} else {
|
||||
const s32 mask = (s32)(input[i]) >> 31;
|
||||
const s32 carry = -(((s32)(input[i]) & mask) >> 26);
|
||||
input[i] = (s32)(input[i]) + (carry << 26);
|
||||
input[i+1] = (s32)(input[i+1]) - carry;
|
||||
const s32 mask = input[i] >> 31;
|
||||
const s32 carry = -((input[i] & mask) >> 26);
|
||||
input[i] = input[i] + (carry << 26);
|
||||
input[i+1] = input[i+1] - carry;
|
||||
}
|
||||
}
|
||||
|
||||
/* There's no greater limb for input[9] to borrow from, but we can multiply
|
||||
* by 19 and borrow from input[0], which is valid mod 2^255-19. */
|
||||
{
|
||||
const s32 mask = (s32)(input[9]) >> 31;
|
||||
const s32 carry = -(((s32)(input[9]) & mask) >> 25);
|
||||
input[9] = (s32)(input[9]) + (carry << 25);
|
||||
input[0] = (s32)(input[0]) - (carry * 19);
|
||||
const s32 mask = input[9] >> 31;
|
||||
const s32 carry = -((input[9] & mask) >> 25);
|
||||
input[9] = input[9] + (carry << 25);
|
||||
input[0] = input[0] - (carry * 19);
|
||||
}
|
||||
|
||||
/* After the first iteration, input[1..9] are non-negative and fit within
|
||||
* 25 or 26 bits, depending on position. However, input[0] may be
|
||||
* negative. */
|
||||
}
|
||||
|
||||
/* The first borrow-propagation pass above ended with every limb
|
||||
except (possibly) input[0] non-negative.
|
||||
|
||||
Since each input limb except input[0] is decreased by at most 1
|
||||
by a borrow-propagation pass, the second borrow-propagation pass
|
||||
could only have wrapped around to decrease input[0] again if the
|
||||
first pass left input[0] negative *and* input[1] through input[9]
|
||||
were all zero. In that case, input[1] is now 2^25 - 1, and this
|
||||
last borrow-propagation step will leave input[1] non-negative.
|
||||
*/
|
||||
If input[0] was negative after the first pass, then it was because of a
|
||||
carry from input[9]. On entry, input[9] < 2^26 so the carry was, at most,
|
||||
one, since (2**26-1) >> 25 = 1. Thus input[0] >= -19.
|
||||
|
||||
In the second pass, each limb is decreased by at most one. Thus the second
|
||||
borrow-propagation pass could only have wrapped around to decrease
|
||||
input[0] again if the first pass left input[0] negative *and* input[1]
|
||||
through input[9] were all zero. In that case, input[1] is now 2^25 - 1,
|
||||
and this last borrow-propagation step will leave input[1] non-negative. */
|
||||
{
|
||||
const s32 mask = (s32)(input[0]) >> 31;
|
||||
const s32 carry = -(((s32)(input[0]) & mask) >> 26);
|
||||
input[0] = (s32)(input[0]) + (carry << 26);
|
||||
input[1] = (s32)(input[1]) - carry;
|
||||
const s32 mask = input[0] >> 31;
|
||||
const s32 carry = -((input[0] & mask) >> 26);
|
||||
input[0] = input[0] + (carry << 26);
|
||||
input[1] = input[1] - carry;
|
||||
}
|
||||
|
||||
/* Both passes through the above loop, plus the last 0-to-1 step, are
|
||||
necessary: if input[9] is -1 and input[0] through input[8] are 0,
|
||||
negative values will remain in the array until the end.
|
||||
*/
|
||||
/* All input[i] are now non-negative. However, there might be values between
|
||||
* 2^25 and 2^26 in a limb which is, nominally, 25 bits wide. */
|
||||
for (j = 0; j < 2; j++) {
|
||||
for (i = 0; i < 9; i++) {
|
||||
if ((i & 1) == 1) {
|
||||
const s32 carry = input[i] >> 25;
|
||||
input[i] &= 0x1ffffff;
|
||||
input[i+1] += carry;
|
||||
} else {
|
||||
const s32 carry = input[i] >> 26;
|
||||
input[i] &= 0x3ffffff;
|
||||
input[i+1] += carry;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const s32 carry = input[9] >> 25;
|
||||
input[9] &= 0x1ffffff;
|
||||
input[0] += 19*carry;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the first carry-chain pass, just above, ended up with a carry from
|
||||
* input[9], and that caused input[0] to be out-of-bounds, then input[0] was
|
||||
* < 2^26 + 2*19, because the carry was, at most, two.
|
||||
*
|
||||
* If the second pass carried from input[9] again then input[0] is < 2*19 and
|
||||
* the input[9] -> input[0] carry didn't push input[0] out of bounds. */
|
||||
|
||||
/* It still remains the case that input might be between 2^255-19 and 2^255.
|
||||
* In this case, input[1..9] must take their maximum value and input[0] must
|
||||
* be >= (2^255-19) & 0x3ffffff, which is 0x3ffffed. */
|
||||
mask = s32_gte(input[0], 0x3ffffed);
|
||||
for (i = 1; i < 10; i++) {
|
||||
if ((i & 1) == 1) {
|
||||
mask &= s32_eq(input[i], 0x1ffffff);
|
||||
} else {
|
||||
mask &= s32_eq(input[i], 0x3ffffff);
|
||||
}
|
||||
}
|
||||
|
||||
/* mask is either 0xffffffff (if input >= 2^255-19) and zero otherwise. Thus
|
||||
* this conditionally subtracts 2^255-19. */
|
||||
input[0] -= mask & 0x3ffffed;
|
||||
|
||||
for (i = 1; i < 10; i++) {
|
||||
if ((i & 1) == 1) {
|
||||
input[i] -= mask & 0x1ffffff;
|
||||
} else {
|
||||
input[i] -= mask & 0x3ffffff;
|
||||
}
|
||||
}
|
||||
|
||||
input[1] <<= 2;
|
||||
input[2] <<= 3;
|
||||
@@ -516,7 +619,9 @@ fcontract(u8 *output, limb *input) {
|
||||
* x z: short form, destroyed
|
||||
* xprime zprime: short form, destroyed
|
||||
* qmqp: short form, preserved
|
||||
*/
|
||||
*
|
||||
* On entry and exit, the absolute value of the limbs of all inputs and outputs
|
||||
* are < 2^26. */
|
||||
static void fmonty(limb *x2, limb *z2, /* output 2Q */
|
||||
limb *x3, limb *z3, /* output Q + Q' */
|
||||
limb *x, limb *z, /* input Q */
|
||||
@@ -527,43 +632,69 @@ static void fmonty(limb *x2, limb *z2, /* output 2Q */
|
||||
|
||||
memcpy(origx, x, 10 * sizeof(limb));
|
||||
fsum(x, z);
|
||||
/* |x[i]| < 2^27 */
|
||||
fdifference(z, origx); /* does x - z */
|
||||
/* |z[i]| < 2^27 */
|
||||
|
||||
memcpy(origxprime, xprime, sizeof(limb) * 10);
|
||||
fsum(xprime, zprime);
|
||||
/* |xprime[i]| < 2^27 */
|
||||
fdifference(zprime, origxprime);
|
||||
/* |zprime[i]| < 2^27 */
|
||||
fproduct(xxprime, xprime, z);
|
||||
/* |xxprime[i]| < 14*2^54: the largest product of two limbs will be <
|
||||
* 2^(27+27) and fproduct adds together, at most, 14 of those products.
|
||||
* (Approximating that to 2^58 doesn't work out.) */
|
||||
fproduct(zzprime, x, zprime);
|
||||
/* |zzprime[i]| < 14*2^54 */
|
||||
freduce_degree(xxprime);
|
||||
freduce_coefficients(xxprime);
|
||||
/* |xxprime[i]| < 2^26 */
|
||||
freduce_degree(zzprime);
|
||||
freduce_coefficients(zzprime);
|
||||
/* |zzprime[i]| < 2^26 */
|
||||
memcpy(origxprime, xxprime, sizeof(limb) * 10);
|
||||
fsum(xxprime, zzprime);
|
||||
/* |xxprime[i]| < 2^27 */
|
||||
fdifference(zzprime, origxprime);
|
||||
/* |zzprime[i]| < 2^27 */
|
||||
fsquare(xxxprime, xxprime);
|
||||
/* |xxxprime[i]| < 2^26 */
|
||||
fsquare(zzzprime, zzprime);
|
||||
/* |zzzprime[i]| < 2^26 */
|
||||
fproduct(zzprime, zzzprime, qmqp);
|
||||
/* |zzprime[i]| < 14*2^52 */
|
||||
freduce_degree(zzprime);
|
||||
freduce_coefficients(zzprime);
|
||||
/* |zzprime[i]| < 2^26 */
|
||||
memcpy(x3, xxxprime, sizeof(limb) * 10);
|
||||
memcpy(z3, zzprime, sizeof(limb) * 10);
|
||||
|
||||
fsquare(xx, x);
|
||||
/* |xx[i]| < 2^26 */
|
||||
fsquare(zz, z);
|
||||
/* |zz[i]| < 2^26 */
|
||||
fproduct(x2, xx, zz);
|
||||
/* |x2[i]| < 14*2^52 */
|
||||
freduce_degree(x2);
|
||||
freduce_coefficients(x2);
|
||||
/* |x2[i]| < 2^26 */
|
||||
fdifference(zz, xx); /* does zz = xx - zz */
|
||||
/* |zz[i]| < 2^27 */
|
||||
memset(zzz + 10, 0, sizeof(limb) * 9);
|
||||
fscalar_product(zzz, zz, 121665);
|
||||
/* |zzz[i]| < 2^(27+17) */
|
||||
/* No need to call freduce_degree here:
|
||||
fscalar_product doesn't increase the degree of its input. */
|
||||
freduce_coefficients(zzz);
|
||||
/* |zzz[i]| < 2^26 */
|
||||
fsum(zzz, xx);
|
||||
/* |zzz[i]| < 2^27 */
|
||||
fproduct(z2, zz, zzz);
|
||||
/* |z2[i]| < 14*2^(26+27) */
|
||||
freduce_degree(z2);
|
||||
freduce_coefficients(z2);
|
||||
/* |z2|i| < 2^26 */
|
||||
}
|
||||
|
||||
/* Conditionally swap two reduced-form limb arrays if 'iswap' is 1, but leave
|
||||
@@ -574,8 +705,7 @@ static void fmonty(limb *x2, limb *z2, /* output 2Q */
|
||||
* wrong results. Also, the two limb arrays must be in reduced-coefficient,
|
||||
* reduced-degree form: the values in a[10..19] or b[10..19] aren't swapped,
|
||||
* and all all values in a[0..9],b[0..9] must have magnitude less than
|
||||
* INT32_MAX.
|
||||
*/
|
||||
* INT32_MAX. */
|
||||
static void
|
||||
swap_conditional(limb a[19], limb b[19], limb iswap) {
|
||||
unsigned i;
|
||||
@@ -592,8 +722,7 @@ swap_conditional(limb a[19], limb b[19], limb iswap) {
|
||||
*
|
||||
* resultx/resultz: the x coordinate of the resulting curve point (short form)
|
||||
* n: a little endian, 32-byte number
|
||||
* q: a point of the curve (short form)
|
||||
*/
|
||||
* q: a point of the curve (short form) */
|
||||
static void
|
||||
cmult(limb *resultx, limb *resultz, const u8 *n, const limb *q) {
|
||||
limb a[19] = {0}, b[19] = {1}, c[19] = {1}, d[19] = {0};
|
||||
@@ -711,8 +840,6 @@ crecip(limb *out, const limb *z) {
|
||||
/* 2^255 - 21 */ fmul(out,t1,z11);
|
||||
}
|
||||
|
||||
int curve25519_donna(u8 *, const u8 *, const u8 *);
|
||||
|
||||
int
|
||||
curve25519_donna(u8 *mypublic, const u8 *secret, const u8 *basepoint) {
|
||||
limb bp[10], x[10], z[11], zmone[10];
|
||||
@@ -728,7 +855,6 @@ curve25519_donna(u8 *mypublic, const u8 *secret, const u8 *basepoint) {
|
||||
cmult(x, z, e, bp);
|
||||
crecip(zmone, z);
|
||||
fmul(z, x, zmone);
|
||||
freduce_coefficients(z);
|
||||
fcontract(mypublic, z);
|
||||
return 0;
|
||||
}
|
||||
|
||||
17
dbclient.1
17
dbclient.1
@@ -111,11 +111,22 @@ if 0 disables keepalives. If no response is received for 3 consecutive keepalive
|
||||
.B \-I \fIidle_timeout
|
||||
Disconnect the session if no traffic is transmitted or received for \fIidle_timeout\fR seconds.
|
||||
.TP
|
||||
|
||||
.\" TODO: how to avoid a line break between these two -J arguments?
|
||||
.B \-J \fIproxy_command
|
||||
.TP
|
||||
.B \-J \fI&fd
|
||||
.br
|
||||
Use the standard input/output of the program \fIproxy_command\fR rather than using
|
||||
a normal TCP connection. A hostname should be still be provided, as this is used for
|
||||
comparing saved hostkeys. This command will be executed as "exec proxy_command ..." with the
|
||||
default shell.
|
||||
|
||||
The second form &fd will make dbclient use the numeric file descriptor as a socket. This
|
||||
can be used for more complex tunnelling scenarios. Example usage with socat is
|
||||
|
||||
socat EXEC:'dbclient -J &38 ev',fdin=38,fdout=38 TCP4:host.example.com:22
|
||||
|
||||
.TP
|
||||
.B \-B \fIendhost:endport
|
||||
"Netcat-alike" mode, where Dropbear will connect to the given host, then create a
|
||||
@@ -133,8 +144,8 @@ Can be used to give options in the format used by OpenSSH config file. This is
|
||||
useful for specifying options for which there is no separate command-line flag.
|
||||
For full details of the options listed below, and their possible values, see
|
||||
ssh_config(5).
|
||||
The following options have currently been implemented:
|
||||
|
||||
For now following options have been implemented:
|
||||
.RS
|
||||
.TP
|
||||
.B ExitOnForwardFailure
|
||||
@@ -147,6 +158,10 @@ Send dbclient log messages to syslog in addition to stderr.
|
||||
.B \-s
|
||||
The specified command will be requested as a subsystem, used for sftp. Dropbear doesn't implement sftp itself but the OpenSSH sftp client can be used eg \fIsftp -S dbclient user@host\fR
|
||||
.TP
|
||||
.B \-b \fI[address][:port]
|
||||
Bind to a specific local address when connecting to the remote host. This can be used to choose from
|
||||
multiple outgoing interfaces. Either address or port (or both) can be given.
|
||||
.TP
|
||||
.B \-V
|
||||
Print the version
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
/* This header defines some things that are also used by libtomcrypt/math.
|
||||
We avoid including normal include.h since that can result in conflicting
|
||||
definitinos - only include config.h */
|
||||
definitions - only include config.h */
|
||||
#include "config.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
10
dbrandom.c
10
dbrandom.c
@@ -59,7 +59,7 @@ process_file(hash_state *hs, const char *filename,
|
||||
unsigned int readcount;
|
||||
int ret = DROPBEAR_FAILURE;
|
||||
|
||||
#ifdef DROPBEAR_PRNGD_SOCKET
|
||||
#if DROPBEAR_USE_PRNGD
|
||||
if (prngd)
|
||||
{
|
||||
readfd = connect_unix(filename);
|
||||
@@ -107,7 +107,7 @@ process_file(hash_state *hs, const char *filename,
|
||||
wantread = MIN(sizeof(readbuf), len-readcount);
|
||||
}
|
||||
|
||||
#ifdef DROPBEAR_PRNGD_SOCKET
|
||||
#if DROPBEAR_USE_PRNGD
|
||||
if (prngd)
|
||||
{
|
||||
char egdcmd[2];
|
||||
@@ -141,7 +141,7 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void addrandom(unsigned char * buf, unsigned int len)
|
||||
void addrandom(const unsigned char * buf, unsigned int len)
|
||||
{
|
||||
hash_state hs;
|
||||
|
||||
@@ -157,7 +157,7 @@ void addrandom(unsigned char * buf, unsigned int len)
|
||||
|
||||
static void write_urandom()
|
||||
{
|
||||
#ifndef DROPBEAR_PRNGD_SOCKET
|
||||
#if !DROPBEAR_USE_PRNGD
|
||||
/* This is opportunistic, don't worry about failure */
|
||||
unsigned char buf[INIT_SEED_SIZE];
|
||||
FILE *f = fopen(DROPBEAR_URANDOM_DEV, "w");
|
||||
@@ -185,7 +185,7 @@ void seedrandom() {
|
||||
/* existing state */
|
||||
sha1_process(&hs, (void*)hashpool, sizeof(hashpool));
|
||||
|
||||
#ifdef DROPBEAR_PRNGD_SOCKET
|
||||
#if DROPBEAR_USE_PRNGD
|
||||
if (process_file(&hs, DROPBEAR_PRNGD_SOCKET, INIT_SEED_SIZE, 1)
|
||||
!= DROPBEAR_SUCCESS) {
|
||||
dropbear_exit("Failure reading random device %s",
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
void seedrandom(void);
|
||||
void genrandom(unsigned char* buf, unsigned int len);
|
||||
void addrandom(unsigned char * buf, unsigned int len);
|
||||
void addrandom(const unsigned char * buf, unsigned int len);
|
||||
void gen_random_mpint(mp_int *max, mp_int *rand);
|
||||
|
||||
#endif /* DROPBEAR_RANDOM_H_ */
|
||||
|
||||
37
dbutil.c
37
dbutil.c
@@ -79,7 +79,7 @@ void (*_dropbear_exit)(int exitcode, const char* format, va_list param) ATTRIB_N
|
||||
void (*_dropbear_log)(int priority, const char* format, va_list param)
|
||||
= generic_dropbear_log;
|
||||
|
||||
#ifdef DEBUG_TRACE
|
||||
#if DEBUG_TRACE
|
||||
int debug_trace = 0;
|
||||
#endif
|
||||
|
||||
@@ -149,7 +149,7 @@ void dropbear_log(int priority, const char* format, ...) {
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG_TRACE
|
||||
#if DEBUG_TRACE
|
||||
|
||||
static double debug_start_time = -1;
|
||||
|
||||
@@ -214,7 +214,7 @@ void dropbear_trace2(const char* format, ...) {
|
||||
#endif /* DEBUG_TRACE */
|
||||
|
||||
/* Connect to a given unix socket. The socket is blocking */
|
||||
#ifdef ENABLE_CONNECT_UNIX
|
||||
#if ENABLE_CONNECT_UNIX
|
||||
int connect_unix(const char* path) {
|
||||
struct sockaddr_un addr;
|
||||
int fd = -1;
|
||||
@@ -241,7 +241,7 @@ int connect_unix(const char* path) {
|
||||
* it will be run after the child has fork()ed, and is passed exec_data.
|
||||
* If ret_errfd == NULL then stderr will not be captured.
|
||||
* ret_pid can be passed as NULL to discard the pid. */
|
||||
int spawn_command(void(*exec_fn)(void *user_data), void *exec_data,
|
||||
int spawn_command(void(*exec_fn)(const void *user_data), const void *exec_data,
|
||||
int *ret_writefd, int *ret_readfd, int *ret_errfd, pid_t *ret_pid) {
|
||||
int infds[2];
|
||||
int outfds[2];
|
||||
@@ -262,7 +262,7 @@ int spawn_command(void(*exec_fn)(void *user_data), void *exec_data,
|
||||
return DROPBEAR_FAILURE;
|
||||
}
|
||||
|
||||
#ifdef USE_VFORK
|
||||
#if DROPBEAR_VFORK
|
||||
pid = vfork();
|
||||
#else
|
||||
pid = fork();
|
||||
@@ -371,7 +371,7 @@ void run_shell_command(const char* cmd, unsigned int maxfd, char* usershell) {
|
||||
execv(usershell, argv);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_TRACE
|
||||
#if DEBUG_TRACE
|
||||
void printhex(const char * label, const unsigned char * buf, int len) {
|
||||
|
||||
int i;
|
||||
@@ -465,7 +465,7 @@ out:
|
||||
* authkeys file.
|
||||
* Will return DROPBEAR_SUCCESS if data is read, or DROPBEAR_FAILURE on EOF.*/
|
||||
/* Only used for ~/.ssh/known_hosts and ~/.ssh/authorized_keys */
|
||||
#if defined(DROPBEAR_CLIENT) || defined(ENABLE_SVR_PUBKEY_AUTH)
|
||||
#if DROPBEAR_CLIENT || DROPBEAR_SVR_PUBKEY_AUTH
|
||||
int buf_getline(buffer * line, FILE * authfile) {
|
||||
|
||||
int c = EOF;
|
||||
@@ -506,7 +506,7 @@ out:
|
||||
void m_close(int fd) {
|
||||
int val;
|
||||
|
||||
if (fd == -1) {
|
||||
if (fd < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -634,6 +634,10 @@ reach userspace include headers */
|
||||
#ifndef CLOCK_MONOTONIC_COARSE
|
||||
#define CLOCK_MONOTONIC_COARSE 6
|
||||
#endif
|
||||
/* Some old toolchains know SYS_clock_gettime but not CLOCK_MONOTONIC */
|
||||
#ifndef CLOCK_MONOTONIC
|
||||
#define CLOCK_MONOTONIC 1
|
||||
#endif
|
||||
static clockid_t get_linux_clock_source() {
|
||||
struct timespec ts;
|
||||
if (syscall(SYS_clock_gettime, CLOCK_MONOTONIC_COARSE, &ts) == 0) {
|
||||
@@ -681,4 +685,21 @@ time_t monotonic_now() {
|
||||
return time(NULL);
|
||||
}
|
||||
|
||||
void fsync_parent_dir(const char* fn) {
|
||||
#ifdef HAVE_LIBGEN_H
|
||||
char *fn_dir = m_strdup(fn);
|
||||
char *dir = dirname(fn_dir);
|
||||
int dirfd = open(dir, O_RDONLY);
|
||||
|
||||
if (dirfd != -1) {
|
||||
if (fsync(dirfd) != 0) {
|
||||
TRACE(("fsync of directory %s failed: %s", dir, strerror(errno)))
|
||||
}
|
||||
m_close(dirfd);
|
||||
} else {
|
||||
TRACE(("error opening directory %s for fsync: %s", dir, strerror(errno)))
|
||||
}
|
||||
|
||||
free(fn_dir);
|
||||
#endif
|
||||
}
|
||||
|
||||
8
dbutil.h
8
dbutil.h
@@ -45,7 +45,7 @@ void dropbear_log(int priority, const char* format, ...) ATTRIB_PRINTF(2,3) ;
|
||||
|
||||
void fail_assert(const char* expr, const char* file, int line) ATTRIB_NORETURN;
|
||||
|
||||
#ifdef DEBUG_TRACE
|
||||
#if DEBUG_TRACE
|
||||
void dropbear_trace(const char* format, ...) ATTRIB_PRINTF(1,2);
|
||||
void dropbear_trace2(const char* format, ...) ATTRIB_PRINTF(1,2);
|
||||
void printhex(const char * label, const unsigned char * buf, int len);
|
||||
@@ -56,10 +56,10 @@ extern int debug_trace;
|
||||
|
||||
char * stripcontrol(const char * text);
|
||||
|
||||
int spawn_command(void(*exec_fn)(void *user_data), void *exec_data,
|
||||
int spawn_command(void(*exec_fn)(const void *user_data), const void *exec_data,
|
||||
int *writefd, int *readfd, int *errfd, pid_t *pid);
|
||||
void run_shell_command(const char* cmd, unsigned int maxfd, char* usershell);
|
||||
#ifdef ENABLE_CONNECT_UNIX
|
||||
#if ENABLE_CONNECT_UNIX
|
||||
int connect_unix(const char* addr);
|
||||
#endif
|
||||
int buf_readfile(buffer* buf, const char* filename);
|
||||
@@ -89,4 +89,6 @@ time_t monotonic_now(void);
|
||||
|
||||
char * expand_homedir_path(const char *inpath);
|
||||
|
||||
void fsync_parent_dir(const char* fn);
|
||||
|
||||
#endif /* DROPBEAR_DBUTIL_H_ */
|
||||
|
||||
12
debian/changelog
vendored
12
debian/changelog
vendored
@@ -1,3 +1,15 @@
|
||||
dropbear (2018.76-0.1) unstable; urgency=low
|
||||
|
||||
* New upstream release.
|
||||
|
||||
-- Matt Johnston <matt@ucc.asn.au> Tue, 27 Feb 2018 22:51:57 +0800
|
||||
|
||||
dropbear (2017.75-0.1) unstable; urgency=low
|
||||
|
||||
* New upstream release.
|
||||
|
||||
-- Matt Johnston <matt@ucc.asn.au> Thu, 18 May 2017 22:51:57 +0800
|
||||
|
||||
dropbear (2016.74-0.1) unstable; urgency=low
|
||||
|
||||
* New upstream release.
|
||||
|
||||
1
debian/dropbear.docs
vendored
1
debian/dropbear.docs
vendored
@@ -1,4 +1,3 @@
|
||||
README
|
||||
TODO
|
||||
debian/README.runit
|
||||
debian/README.Debian.diet
|
||||
|
||||
10
debug.h
10
debug.h
@@ -33,14 +33,6 @@
|
||||
* etc. Don't use this normally, it might cause problems */
|
||||
/* #define DEBUG_VALGRIND */
|
||||
|
||||
/* Define this to compile in trace debugging printf()s.
|
||||
* You'll need to run programs with "-v" to turn this on.
|
||||
*
|
||||
* Caution: Don't use this in an unfriendly environment (ie unfirewalled),
|
||||
* since the printing may not sanitise strings etc. This will add a reasonable
|
||||
* amount to your executable size. */
|
||||
/*#define DEBUG_TRACE*/
|
||||
|
||||
/* All functions writing to the cleartext payload buffer call
|
||||
* CHECKCLEARTOWRITE() before writing. This is only really useful if you're
|
||||
* attempting to track down a problem */
|
||||
@@ -61,7 +53,7 @@
|
||||
/*#define DEBUG_RSA*/
|
||||
|
||||
/* you don't need to touch this block */
|
||||
#ifdef DEBUG_TRACE
|
||||
#if DEBUG_TRACE
|
||||
#define TRACE(X) dropbear_trace X;
|
||||
#define TRACE2(X) dropbear_trace2 X;
|
||||
#else /*DEBUG_TRACE*/
|
||||
|
||||
295
default_options.h
Normal file
295
default_options.h
Normal file
@@ -0,0 +1,295 @@
|
||||
#ifndef DROPBEAR_DEFAULT_OPTIONS_H_
|
||||
#define DROPBEAR_DEFAULT_OPTIONS_H_
|
||||
/*
|
||||
> > > Read This < < <
|
||||
|
||||
default_options.h documents compile-time options, and provides default values.
|
||||
|
||||
Local customisation should be added to localoptions.h which is
|
||||
used if it exists. Options defined there will override any options in this
|
||||
file.
|
||||
|
||||
Options can also be defined with -DDROPBEAR_XXX=[0,1] in Makefile CFLAGS
|
||||
|
||||
IMPORTANT: Some options will require "make clean" after changes */
|
||||
|
||||
#define DROPBEAR_DEFPORT "22"
|
||||
|
||||
/* Listen on all interfaces */
|
||||
#define DROPBEAR_DEFADDRESS ""
|
||||
|
||||
/* Default hostkey paths - these can be specified on the command line */
|
||||
#define DSS_PRIV_FILENAME "/etc/dropbear/dropbear_dss_host_key"
|
||||
#define RSA_PRIV_FILENAME "/etc/dropbear/dropbear_rsa_host_key"
|
||||
#define ECDSA_PRIV_FILENAME "/etc/dropbear/dropbear_ecdsa_host_key"
|
||||
|
||||
/* Set NON_INETD_MODE if you require daemon functionality (ie Dropbear listens
|
||||
* on chosen ports and keeps accepting connections. This is the default.
|
||||
*
|
||||
* Set INETD_MODE if you want to be able to run Dropbear with inetd (or
|
||||
* similar), where it will use stdin/stdout for connections, and each process
|
||||
* lasts for a single connection. Dropbear should be invoked with the -i flag
|
||||
* for inetd, and can only accept IPv4 connections.
|
||||
*
|
||||
* Both of these flags can be defined at once, don't compile without at least
|
||||
* one of them. */
|
||||
#define NON_INETD_MODE 1
|
||||
#define INETD_MODE 1
|
||||
|
||||
/* Include verbose debug output, enabled with -v at runtime.
|
||||
* This will add a reasonable amount to your executable size. */
|
||||
#define DEBUG_TRACE 0
|
||||
|
||||
/* Set this if you want to use the DROPBEAR_SMALL_CODE option. This can save
|
||||
* several kB in binary size however will make the symmetrical ciphers and hashes
|
||||
* slower, perhaps by 50%. Recommended for small systems that aren't doing
|
||||
* much traffic. */
|
||||
#define DROPBEAR_SMALL_CODE 1
|
||||
|
||||
/* Enable X11 Forwarding - server only */
|
||||
#define DROPBEAR_X11FWD 1
|
||||
|
||||
/* Enable TCP Fowarding */
|
||||
/* 'Local' is "-L" style (client listening port forwarded via server)
|
||||
* 'Remote' is "-R" style (server listening port forwarded via client) */
|
||||
#define DROPBEAR_CLI_LOCALTCPFWD 1
|
||||
#define DROPBEAR_CLI_REMOTETCPFWD 1
|
||||
|
||||
#define DROPBEAR_SVR_LOCALTCPFWD 1
|
||||
#define DROPBEAR_SVR_REMOTETCPFWD 1
|
||||
|
||||
/* Enable Authentication Agent Forwarding */
|
||||
#define DROPBEAR_SVR_AGENTFWD 1
|
||||
#define DROPBEAR_CLI_AGENTFWD 1
|
||||
|
||||
/* Note: Both DROPBEAR_CLI_PROXYCMD and DROPBEAR_CLI_NETCAT must be set to
|
||||
* allow multihop dbclient connections */
|
||||
|
||||
/* Allow using -J <proxycommand> to run the connection through a
|
||||
pipe to a program, rather the normal TCP connection */
|
||||
#define DROPBEAR_CLI_PROXYCMD 1
|
||||
|
||||
/* Enable "Netcat mode" option. This will forward standard input/output
|
||||
* to a remote TCP-forwarded connection */
|
||||
#define DROPBEAR_CLI_NETCAT 1
|
||||
|
||||
/* Whether to support "-c" and "-m" flags to choose ciphers/MACs at runtime */
|
||||
#define DROPBEAR_USER_ALGO_LIST 1
|
||||
|
||||
/* Encryption - at least one required.
|
||||
* AES128 should be enabled, some very old implementations might only
|
||||
* support 3DES.
|
||||
* Including both AES keysize variants (128 and 256) will result in
|
||||
* a minimal size increase */
|
||||
#define DROPBEAR_AES128 1
|
||||
#define DROPBEAR_3DES 1
|
||||
#define DROPBEAR_AES256 1
|
||||
#define DROPBEAR_TWOFISH256 0
|
||||
#define DROPBEAR_TWOFISH128 0
|
||||
/* Compiling in Blowfish will add ~6kB to runtime heap memory usage */
|
||||
#define DROPBEAR_BLOWFISH 0
|
||||
|
||||
/* Enable CBC mode for ciphers. This has security issues though
|
||||
* is the most compatible with older SSH implementations */
|
||||
#define DROPBEAR_ENABLE_CBC_MODE 1
|
||||
|
||||
/* Enable "Counter Mode" for ciphers. This is more secure than
|
||||
* CBC mode against certain attacks. It is recommended for security
|
||||
* and forwards compatibility */
|
||||
#define DROPBEAR_ENABLE_CTR_MODE 1
|
||||
|
||||
/* Message integrity. sha2-256 is recommended as a default,
|
||||
sha1 for compatibility */
|
||||
#define DROPBEAR_SHA1_HMAC 1
|
||||
#define DROPBEAR_SHA1_96_HMAC 1
|
||||
#define DROPBEAR_SHA2_256_HMAC 1
|
||||
|
||||
/* Hostkey/public key algorithms - at least one required, these are used
|
||||
* for hostkey as well as for verifying signatures with pubkey auth.
|
||||
* Removing either of these won't save very much space.
|
||||
* RSA is recommended
|
||||
* DSS may be necessary to connect to some systems though
|
||||
is not recommended for new keys */
|
||||
#define DROPBEAR_RSA 1
|
||||
#define DROPBEAR_DSS 1
|
||||
/* ECDSA is significantly faster than RSA or DSS. Compiling in ECC
|
||||
* code (either ECDSA or ECDH) increases binary size - around 30kB
|
||||
* on x86-64 */
|
||||
#define DROPBEAR_ECDSA 1
|
||||
|
||||
/* RSA must be >=1024 */
|
||||
#define DROPBEAR_DEFAULT_RSA_SIZE 2048
|
||||
/* DSS is always 1024 */
|
||||
/* ECDSA defaults to largest size configured, usually 521 */
|
||||
|
||||
/* Add runtime flag "-R" to generate hostkeys as-needed when the first
|
||||
connection using that key type occurs.
|
||||
This avoids the need to otherwise run "dropbearkey" and avoids some problems
|
||||
with badly seeded /dev/urandom when systems first boot. */
|
||||
#define DROPBEAR_DELAY_HOSTKEY 1
|
||||
|
||||
|
||||
/* Key exchange algorithm.
|
||||
|
||||
* group14_sha1 - 2048 bit, sha1
|
||||
* group14_sha256 - 2048 bit, sha2-256
|
||||
* group16 - 4096 bit, sha2-512
|
||||
* group1 - 1024 bit, sha1
|
||||
* curve25519 - elliptic curve DH
|
||||
* ecdh - NIST elliptic curve DH (256, 384, 521)
|
||||
*
|
||||
* group1 is too small for security though is necessary if you need
|
||||
compatibility with some implementations such as Dropbear versions < 0.53
|
||||
* group14 is supported by most implementations.
|
||||
* group16 provides a greater strength level but is slower and increases binary size
|
||||
* curve25519 and ecdh algorithms are faster than non-elliptic curve methods
|
||||
* curve25519 increases binary size by ~8kB on x86-64
|
||||
* including either ECDH or ECDSA increases binary size by ~30kB on x86-64
|
||||
|
||||
* Small systems should generally include either curve25519 or ecdh for performance.
|
||||
* curve25519 is less widely supported but is faster
|
||||
*/
|
||||
#define DROPBEAR_DH_GROUP14_SHA1 1
|
||||
#define DROPBEAR_DH_GROUP14_SHA256 1
|
||||
#define DROPBEAR_DH_GROUP16 0
|
||||
#define DROPBEAR_CURVE25519 1
|
||||
#define DROPBEAR_ECDH 1
|
||||
#define DROPBEAR_DH_GROUP1 1
|
||||
|
||||
/* When group1 is enabled it will only be allowed by Dropbear client
|
||||
not as a server, due to concerns over its strength. Set to 0 to allow
|
||||
group1 in Dropbear server too */
|
||||
#define DROPBEAR_DH_GROUP1_CLIENTONLY 1
|
||||
|
||||
/* Control the memory/performance/compression tradeoff for zlib.
|
||||
* Set windowBits=8 for least memory usage, see your system's
|
||||
* zlib.h for full details.
|
||||
* Default settings (windowBits=15) will use 256kB for compression
|
||||
* windowBits=8 will use 129kB for compression.
|
||||
* Both modes will use ~35kB for decompression (using windowBits=15 for
|
||||
* interoperability) */
|
||||
#define DROPBEAR_ZLIB_WINDOW_BITS 15
|
||||
|
||||
/* Whether to do reverse DNS lookups. */
|
||||
#define DO_HOST_LOOKUP 0
|
||||
|
||||
/* Whether to print the message of the day (MOTD). */
|
||||
#define DO_MOTD 0
|
||||
#define MOTD_FILENAME "/etc/motd"
|
||||
|
||||
/* Authentication Types - at least one required.
|
||||
RFC Draft requires pubkey auth, and recommends password */
|
||||
#define DROPBEAR_SVR_PASSWORD_AUTH 1
|
||||
|
||||
/* Note: PAM auth is quite simple and only works for PAM modules which just do
|
||||
* a simple "Login: " "Password: " (you can edit the strings in svr-authpam.c).
|
||||
* It's useful for systems like OS X where standard password crypts don't work
|
||||
* but there's an interface via a PAM module. It won't work for more complex
|
||||
* PAM challenge/response.
|
||||
* You can't enable both PASSWORD and PAM. */
|
||||
#define DROPBEAR_SVR_PAM_AUTH 0
|
||||
|
||||
/* ~/.ssh/authorized_keys authentication */
|
||||
#define DROPBEAR_SVR_PUBKEY_AUTH 1
|
||||
|
||||
/* Whether to take public key options in
|
||||
* authorized_keys file into account */
|
||||
#define DROPBEAR_SVR_PUBKEY_OPTIONS 1
|
||||
|
||||
/* Client authentication options */
|
||||
#define DROPBEAR_CLI_PASSWORD_AUTH 1
|
||||
#define DROPBEAR_CLI_PUBKEY_AUTH 1
|
||||
|
||||
/* A default argument for dbclient -i <privatekey>.
|
||||
Homedir is prepended unless path begins with / */
|
||||
#define DROPBEAR_DEFAULT_CLI_AUTHKEY ".ssh/id_dropbear"
|
||||
|
||||
/* Allow specifying the password for dbclient via the DROPBEAR_PASSWORD
|
||||
* environment variable. */
|
||||
#define DROPBEAR_USE_PASSWORD_ENV 1
|
||||
|
||||
/* Define this (as well as DROPBEAR_CLI_PASSWORD_AUTH) to allow the use of
|
||||
* a helper program for the ssh client. The helper program should be
|
||||
* specified in the SSH_ASKPASS environment variable, and dbclient
|
||||
* should be run with DISPLAY set and no tty. The program should
|
||||
* return the password on standard output */
|
||||
#define DROPBEAR_CLI_ASKPASS_HELPER 0
|
||||
|
||||
/* Save a network roundtrip by sendng a real auth request immediately after
|
||||
* sending a query for the available methods. This is not yet enabled by default
|
||||
since it could cause problems with non-compliant servers */
|
||||
#define DROPBEAR_CLI_IMMEDIATE_AUTH 0
|
||||
|
||||
/* Set this to use PRNGD or EGD instead of /dev/urandom */
|
||||
#define DROPBEAR_USE_PRNGD 0
|
||||
#define DROPBEAR_PRNGD_SOCKET "/var/run/dropbear-rng"
|
||||
|
||||
/* Specify the number of clients we will allow to be connected but
|
||||
* not yet authenticated. After this limit, connections are rejected */
|
||||
/* The first setting is per-IP, to avoid denial of service */
|
||||
#define MAX_UNAUTH_PER_IP 5
|
||||
|
||||
/* And then a global limit to avoid chewing memory if connections
|
||||
* come from many IPs */
|
||||
#define MAX_UNAUTH_CLIENTS 30
|
||||
|
||||
/* Default maximum number of failed authentication tries (server option) */
|
||||
/* -T server option overrides */
|
||||
#define MAX_AUTH_TRIES 10
|
||||
|
||||
/* The default file to store the daemon's process ID, for shutdown
|
||||
scripts etc. This can be overridden with the -P flag */
|
||||
#define DROPBEAR_PIDFILE "/var/run/dropbear.pid"
|
||||
|
||||
/* The command to invoke for xauth when using X11 forwarding.
|
||||
* "-q" for quiet */
|
||||
#define XAUTH_COMMAND "/usr/bin/xauth -q"
|
||||
|
||||
|
||||
/* if you want to enable running an sftp server (such as the one included with
|
||||
* OpenSSH), set the path below and set DROPBEAR_SFTPSERVER.
|
||||
* The sftp-server program is not provided by Dropbear itself */
|
||||
#define DROPBEAR_SFTPSERVER 1
|
||||
#define SFTPSERVER_PATH "/usr/libexec/sftp-server"
|
||||
|
||||
/* This is used by the scp binary when used as a client binary. If you're
|
||||
* not using the Dropbear client, you'll need to change it */
|
||||
#define DROPBEAR_PATH_SSH_PROGRAM "/usr/bin/dbclient"
|
||||
|
||||
/* Whether to log commands executed by a client. This only logs the
|
||||
* (single) command sent to the server, not what a user did in a
|
||||
* shell/sftp session etc. */
|
||||
#define LOG_COMMANDS 0
|
||||
|
||||
/* Window size limits. These tend to be a trade-off between memory
|
||||
usage and network performance: */
|
||||
/* Size of the network receive window. This amount of memory is allocated
|
||||
as a per-channel receive buffer. Increasing this value can make a
|
||||
significant difference to network performance. 24kB was empirically
|
||||
chosen for a 100mbit ethernet network. The value can be altered at
|
||||
runtime with the -W argument. */
|
||||
#define DEFAULT_RECV_WINDOW 24576
|
||||
/* Maximum size of a received SSH data packet - this _MUST_ be >= 32768
|
||||
in order to interoperate with other implementations */
|
||||
#define RECV_MAX_PAYLOAD_LEN 32768
|
||||
/* Maximum size of a transmitted data packet - this can be any value,
|
||||
though increasing it may not make a significant difference. */
|
||||
#define TRANS_MAX_PAYLOAD_LEN 16384
|
||||
|
||||
/* Ensure that data is transmitted every KEEPALIVE seconds. This can
|
||||
be overridden at runtime with -K. 0 disables keepalives */
|
||||
#define DEFAULT_KEEPALIVE 0
|
||||
|
||||
/* If this many KEEPALIVES are sent with no packets received from the
|
||||
other side, exit. Not run-time configurable - if you have a need
|
||||
for runtime configuration please mail the Dropbear list */
|
||||
#define DEFAULT_KEEPALIVE_LIMIT 3
|
||||
|
||||
/* Ensure that data is received within IDLE_TIMEOUT seconds. This can
|
||||
be overridden at runtime with -I. 0 disables idle timeouts */
|
||||
#define DEFAULT_IDLE_TIMEOUT 0
|
||||
|
||||
/* The default path. This will often get replaced by the shell */
|
||||
#define DEFAULT_PATH "/usr/bin:/bin"
|
||||
|
||||
#endif /* DROPBEAR_DEFAULT_OPTIONS_H_ */
|
||||
14
dropbear.8
14
dropbear.8
@@ -91,6 +91,13 @@ if 0 disables keepalives. If no response is received for 3 consecutive keepalive
|
||||
.B \-I \fIidle_timeout
|
||||
Disconnect the session if no traffic is transmitted or received for \fIidle_timeout\fR seconds.
|
||||
.TP
|
||||
.B \-T \fImax_authentication_attempts
|
||||
Set the number of authentication attempts allowed per connection. If unspecified the default is 10 (MAX_AUTH_TRIES)
|
||||
.TP
|
||||
.B \-c \fIforced_command
|
||||
Disregard the command provided by the user and always run \fIforced_command\fR. This also
|
||||
overrides any authorized_keys command= option.
|
||||
.TP
|
||||
.B \-V
|
||||
Print the version
|
||||
|
||||
@@ -129,6 +136,7 @@ same functionality with other means even if no-pty is set.
|
||||
.TP
|
||||
.B command=\fR"\fIforced_command\fR"
|
||||
Disregard the command provided by the user and always run \fIforced_command\fR.
|
||||
The -c command line option overrides this.
|
||||
|
||||
The authorized_keys file and its containing ~/.ssh directory must only be
|
||||
writable by the user, otherwise Dropbear will not allow a login using public
|
||||
@@ -140,8 +148,10 @@ Host Key Files
|
||||
Host key files are read at startup from a standard location, by default
|
||||
/etc/dropbear/dropbear_dss_host_key, /etc/dropbear/dropbear_rsa_host_key, and
|
||||
/etc/dropbear/dropbear_ecdsa_host_key
|
||||
or specified on the commandline with -r. These are of the form generated
|
||||
by dropbearkey. The -R option can be used to automatically generate keys
|
||||
|
||||
If the -r command line option is specified the default files are not loaded.
|
||||
Host key files are of the form generated by dropbearkey.
|
||||
The -R option can be used to automatically generate keys
|
||||
in the default location - keys will be generated after startup when the first
|
||||
connection is established. This had the benefit that the system /dev/urandom
|
||||
random number source has a better chance of being securely seeded.
|
||||
|
||||
@@ -53,8 +53,8 @@ static void printhelp(char * progname) {
|
||||
progname);
|
||||
}
|
||||
|
||||
#if defined(DBMULTI_dropbearconvert) || !defined(DROPBEAR_MULTI)
|
||||
#if defined(DBMULTI_dropbearconvert) && defined(DROPBEAR_MULTI)
|
||||
#if defined(DBMULTI_dropbearconvert) || !DROPBEAR_MULTI
|
||||
#if defined(DBMULTI_dropbearconvert) && DROPBEAR_MULTI
|
||||
int dropbearconvert_main(int argc, char ** argv) {
|
||||
#else
|
||||
int main(int argc, char ** argv) {
|
||||
@@ -67,7 +67,7 @@ int main(int argc, char ** argv) {
|
||||
crypto_init();
|
||||
seedrandom();
|
||||
|
||||
#ifdef DEBUG_TRACE
|
||||
#if DEBUG_TRACE
|
||||
/* It's hard for it to get in the way _too_ much */
|
||||
debug_trace = 1;
|
||||
#endif
|
||||
|
||||
@@ -67,36 +67,36 @@ static void printhelp(char * progname) {
|
||||
|
||||
fprintf(stderr, "Usage: %s -t <type> -f <filename> [-s bits]\n"
|
||||
"-t type Type of key to generate. One of:\n"
|
||||
#ifdef DROPBEAR_RSA
|
||||
#if DROPBEAR_RSA
|
||||
" rsa\n"
|
||||
#endif
|
||||
#ifdef DROPBEAR_DSS
|
||||
#if DROPBEAR_DSS
|
||||
" dss\n"
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECDSA
|
||||
#if DROPBEAR_ECDSA
|
||||
" ecdsa\n"
|
||||
#endif
|
||||
"-f filename Use filename for the secret key.\n"
|
||||
" ~/.ssh/id_dropbear is recommended for client keys.\n"
|
||||
"-s bits Key size in bits, should be a multiple of 8 (optional)\n"
|
||||
#ifdef DROPBEAR_DSS
|
||||
#if DROPBEAR_DSS
|
||||
" DSS has a fixed size of 1024 bits\n"
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECDSA
|
||||
#if DROPBEAR_ECDSA
|
||||
" ECDSA has sizes "
|
||||
#ifdef DROPBEAR_ECC_256
|
||||
#if DROPBEAR_ECC_256
|
||||
"256 "
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_384
|
||||
#if DROPBEAR_ECC_384
|
||||
"384 "
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_521
|
||||
#if DROPBEAR_ECC_521
|
||||
"521 "
|
||||
#endif
|
||||
"\n"
|
||||
#endif
|
||||
"-y Just print the publickey and fingerprint for the\n private key in <filename>.\n"
|
||||
#ifdef DEBUG_TRACE
|
||||
#if DEBUG_TRACE
|
||||
"-v verbose\n"
|
||||
#endif
|
||||
,progname);
|
||||
@@ -106,7 +106,7 @@ static void printhelp(char * progname) {
|
||||
static void check_signkey_bits(enum signkey_type type, int bits)
|
||||
{
|
||||
switch (type) {
|
||||
#ifdef DROPBEAR_RSA
|
||||
#if DROPBEAR_RSA
|
||||
case DROPBEAR_SIGNKEY_RSA:
|
||||
if (bits < 512 || bits > 4096 || (bits % 8 != 0)) {
|
||||
dropbear_exit("Bits must satisfy 512 <= bits <= 4096, and be a"
|
||||
@@ -126,20 +126,20 @@ static void check_signkey_bits(enum signkey_type type, int bits)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(DBMULTI_dropbearkey) || !defined(DROPBEAR_MULTI)
|
||||
#if defined(DBMULTI_dropbearkey) && defined(DROPBEAR_MULTI)
|
||||
#if defined(DBMULTI_dropbearkey) || !DROPBEAR_MULTI
|
||||
#if defined(DBMULTI_dropbearkey) && DROPBEAR_MULTI
|
||||
int dropbearkey_main(int argc, char ** argv) {
|
||||
#else
|
||||
int main(int argc, char ** argv) {
|
||||
#endif
|
||||
|
||||
int i;
|
||||
char ** next = 0;
|
||||
char ** next = NULL;
|
||||
char * filename = NULL;
|
||||
enum signkey_type keytype = DROPBEAR_SIGNKEY_NONE;
|
||||
char * typetext = NULL;
|
||||
char * sizetext = NULL;
|
||||
unsigned int bits = 0;
|
||||
unsigned int bits = 0, genbits;
|
||||
int printpub = 0;
|
||||
|
||||
crypto_init();
|
||||
@@ -174,7 +174,7 @@ int main(int argc, char ** argv) {
|
||||
printhelp(argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
break;
|
||||
#ifdef DEBUG_TRACE
|
||||
#if DEBUG_TRACE
|
||||
case 'v':
|
||||
debug_trace = 1;
|
||||
break;
|
||||
@@ -206,19 +206,19 @@ int main(int argc, char ** argv) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
#ifdef DROPBEAR_RSA
|
||||
#if DROPBEAR_RSA
|
||||
if (strcmp(typetext, "rsa") == 0)
|
||||
{
|
||||
keytype = DROPBEAR_SIGNKEY_RSA;
|
||||
}
|
||||
#endif
|
||||
#ifdef DROPBEAR_DSS
|
||||
#if DROPBEAR_DSS
|
||||
if (strcmp(typetext, "dss") == 0)
|
||||
{
|
||||
keytype = DROPBEAR_SIGNKEY_DSS;
|
||||
}
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECDSA
|
||||
#if DROPBEAR_ECDSA
|
||||
if (strcmp(typetext, "ecdsa") == 0)
|
||||
{
|
||||
keytype = DROPBEAR_SIGNKEY_ECDSA_KEYGEN;
|
||||
@@ -240,8 +240,9 @@ int main(int argc, char ** argv) {
|
||||
check_signkey_bits(keytype, bits);;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Generating key, this may take a while...\n");
|
||||
if (signkey_generate(keytype, bits, filename) == DROPBEAR_FAILURE)
|
||||
genbits = signkey_generate_get_bits(keytype, bits);
|
||||
fprintf(stderr, "Generating %u bit %s key, this may take a while...\n", genbits, typetext);
|
||||
if (signkey_generate(keytype, bits, filename, 0) == DROPBEAR_FAILURE)
|
||||
{
|
||||
dropbear_exit("Failed to generate key.\n");
|
||||
}
|
||||
|
||||
68
dss.c
68
dss.c
@@ -37,13 +37,14 @@
|
||||
* See FIPS186 or the Handbook of Applied Cryptography for details of the
|
||||
* algorithm */
|
||||
|
||||
#ifdef DROPBEAR_DSS
|
||||
#if DROPBEAR_DSS
|
||||
|
||||
/* Load a dss key from a buffer, initialising the values.
|
||||
* The key will have the same format as buf_put_dss_key.
|
||||
* These should be freed with dss_key_free.
|
||||
* Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
|
||||
int buf_get_dss_pub_key(buffer* buf, dropbear_dss_key *key) {
|
||||
int ret = DROPBEAR_FAILURE;
|
||||
|
||||
TRACE(("enter buf_get_dss_pub_key"))
|
||||
dropbear_assert(key != NULL);
|
||||
@@ -56,17 +57,29 @@ int buf_get_dss_pub_key(buffer* buf, dropbear_dss_key *key) {
|
||||
|| buf_getmpint(buf, key->g) == DROPBEAR_FAILURE
|
||||
|| buf_getmpint(buf, key->y) == DROPBEAR_FAILURE) {
|
||||
TRACE(("leave buf_get_dss_pub_key: failed reading mpints"))
|
||||
return DROPBEAR_FAILURE;
|
||||
ret = DROPBEAR_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (mp_count_bits(key->p) < MIN_DSS_KEYLEN) {
|
||||
dropbear_log(LOG_WARNING, "DSS key too short");
|
||||
TRACE(("leave buf_get_dss_pub_key: short key"))
|
||||
return DROPBEAR_FAILURE;
|
||||
if (mp_count_bits(key->p) != DSS_P_BITS) {
|
||||
dropbear_log(LOG_WARNING, "Bad DSS p");
|
||||
ret = DROPBEAR_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (mp_count_bits(key->q) != DSS_Q_BITS) {
|
||||
dropbear_log(LOG_WARNING, "Bad DSS q");
|
||||
ret = DROPBEAR_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = DROPBEAR_SUCCESS;
|
||||
TRACE(("leave buf_get_dss_pub_key: success"))
|
||||
return DROPBEAR_SUCCESS;
|
||||
out:
|
||||
if (ret == DROPBEAR_FAILURE) {
|
||||
m_mp_free_multi(&key->p, &key->q, &key->g, &key->y, NULL);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Same as buf_get_dss_pub_key, but reads a private "x" key at the end.
|
||||
@@ -86,7 +99,7 @@ int buf_get_dss_priv_key(buffer* buf, dropbear_dss_key *key) {
|
||||
m_mp_alloc_init_multi(&key->x, NULL);
|
||||
ret = buf_getmpint(buf, key->x);
|
||||
if (ret == DROPBEAR_FAILURE) {
|
||||
m_free(key->x);
|
||||
m_mp_free_multi(&key->x, NULL);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -101,26 +114,7 @@ void dss_key_free(dropbear_dss_key *key) {
|
||||
TRACE2(("enter dsa_key_free: key == NULL"))
|
||||
return;
|
||||
}
|
||||
if (key->p) {
|
||||
mp_clear(key->p);
|
||||
m_free(key->p);
|
||||
}
|
||||
if (key->q) {
|
||||
mp_clear(key->q);
|
||||
m_free(key->q);
|
||||
}
|
||||
if (key->g) {
|
||||
mp_clear(key->g);
|
||||
m_free(key->g);
|
||||
}
|
||||
if (key->y) {
|
||||
mp_clear(key->y);
|
||||
m_free(key->y);
|
||||
}
|
||||
if (key->x) {
|
||||
mp_clear(key->x);
|
||||
m_free(key->x);
|
||||
}
|
||||
m_mp_free_multi(&key->p, &key->q, &key->g, &key->y, &key->x, NULL);
|
||||
m_free(key);
|
||||
TRACE2(("leave dsa_key_free"))
|
||||
}
|
||||
@@ -133,7 +127,7 @@ void dss_key_free(dropbear_dss_key *key) {
|
||||
* mpint g
|
||||
* mpint y
|
||||
*/
|
||||
void buf_put_dss_pub_key(buffer* buf, dropbear_dss_key *key) {
|
||||
void buf_put_dss_pub_key(buffer* buf, const dropbear_dss_key *key) {
|
||||
|
||||
dropbear_assert(key != NULL);
|
||||
buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN);
|
||||
@@ -145,7 +139,7 @@ void buf_put_dss_pub_key(buffer* buf, dropbear_dss_key *key) {
|
||||
}
|
||||
|
||||
/* Same as buf_put_dss_pub_key, but with the private "x" key appended */
|
||||
void buf_put_dss_priv_key(buffer* buf, dropbear_dss_key *key) {
|
||||
void buf_put_dss_priv_key(buffer* buf, const dropbear_dss_key *key) {
|
||||
|
||||
dropbear_assert(key != NULL);
|
||||
buf_put_dss_pub_key(buf, key);
|
||||
@@ -153,10 +147,10 @@ void buf_put_dss_priv_key(buffer* buf, dropbear_dss_key *key) {
|
||||
|
||||
}
|
||||
|
||||
#ifdef DROPBEAR_SIGNKEY_VERIFY
|
||||
#if DROPBEAR_SIGNKEY_VERIFY
|
||||
/* Verify a DSS signature (in buf) made on data by the key given.
|
||||
* returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
|
||||
int buf_dss_verify(buffer* buf, dropbear_dss_key *key, buffer *data_buf) {
|
||||
int buf_dss_verify(buffer* buf, const dropbear_dss_key *key, const buffer *data_buf) {
|
||||
unsigned char msghash[SHA1_HASH_SIZE];
|
||||
hash_state hs;
|
||||
int ret = DROPBEAR_FAILURE;
|
||||
@@ -192,6 +186,10 @@ int buf_dss_verify(buffer* buf, dropbear_dss_key *key, buffer *data_buf) {
|
||||
TRACE(("verify failed, s' >= q"))
|
||||
goto out;
|
||||
}
|
||||
if (mp_cmp_d(&val1, 0) != MP_GT) {
|
||||
TRACE(("verify failed, s' <= 0"))
|
||||
goto out;
|
||||
}
|
||||
/* let val2 = w = (s')^-1 mod q*/
|
||||
if (mp_invmod(&val1, key->q, &val2) != MP_OKAY) {
|
||||
goto out;
|
||||
@@ -213,6 +211,10 @@ int buf_dss_verify(buffer* buf, dropbear_dss_key *key, buffer *data_buf) {
|
||||
TRACE(("verify failed, r' >= q"))
|
||||
goto out;
|
||||
}
|
||||
if (mp_cmp_d(&val1, 0) != MP_GT) {
|
||||
TRACE(("verify failed, r' <= 0"))
|
||||
goto out;
|
||||
}
|
||||
/* let val4 = u2 = ((r')w) mod q */
|
||||
if (mp_mulmod(&val1, &val2, key->q, &val4) != MP_OKAY) {
|
||||
goto out;
|
||||
@@ -253,7 +255,7 @@ out:
|
||||
|
||||
/* Sign the data presented with key, writing the signature contents
|
||||
* to the buffer */
|
||||
void buf_put_dss_sign(buffer* buf, dropbear_dss_key *key, buffer *data_buf) {
|
||||
void buf_put_dss_sign(buffer* buf, const dropbear_dss_key *key, const buffer *data_buf) {
|
||||
unsigned char msghash[SHA1_HASH_SIZE];
|
||||
unsigned int writelen;
|
||||
unsigned int i;
|
||||
|
||||
15
dss.h
15
dss.h
@@ -28,7 +28,7 @@
|
||||
#include "includes.h"
|
||||
#include "buffer.h"
|
||||
|
||||
#ifdef DROPBEAR_DSS
|
||||
#if DROPBEAR_DSS
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -41,14 +41,17 @@ typedef struct {
|
||||
|
||||
} dropbear_dss_key;
|
||||
|
||||
void buf_put_dss_sign(buffer* buf, dropbear_dss_key *key, buffer *data_buf);
|
||||
#ifdef DROPBEAR_SIGNKEY_VERIFY
|
||||
int buf_dss_verify(buffer* buf, dropbear_dss_key *key, buffer *data_buf);
|
||||
#define DSS_P_BITS 1024
|
||||
#define DSS_Q_BITS 160
|
||||
|
||||
void buf_put_dss_sign(buffer* buf, const dropbear_dss_key *key, const buffer *data_buf);
|
||||
#if DROPBEAR_SIGNKEY_VERIFY
|
||||
int buf_dss_verify(buffer* buf, const dropbear_dss_key *key, const buffer *data_buf);
|
||||
#endif
|
||||
int buf_get_dss_pub_key(buffer* buf, dropbear_dss_key *key);
|
||||
int buf_get_dss_priv_key(buffer* buf, dropbear_dss_key *key);
|
||||
void buf_put_dss_pub_key(buffer* buf, dropbear_dss_key *key);
|
||||
void buf_put_dss_priv_key(buffer* buf, dropbear_dss_key *key);
|
||||
void buf_put_dss_pub_key(buffer* buf, const dropbear_dss_key *key);
|
||||
void buf_put_dss_priv_key(buffer* buf, const dropbear_dss_key *key);
|
||||
void dss_key_free(dropbear_dss_key *key);
|
||||
|
||||
#endif /* DROPBEAR_DSS */
|
||||
|
||||
56
ecc.c
56
ecc.c
@@ -1,13 +1,12 @@
|
||||
#include "includes.h"
|
||||
#include "options.h"
|
||||
#include "ecc.h"
|
||||
#include "dbutil.h"
|
||||
#include "bignum.h"
|
||||
|
||||
#ifdef DROPBEAR_ECC
|
||||
#if DROPBEAR_ECC
|
||||
|
||||
/* .dp members are filled out by dropbear_ecc_fill_dp() at startup */
|
||||
#ifdef DROPBEAR_ECC_256
|
||||
#if DROPBEAR_ECC_256
|
||||
struct dropbear_ecc_curve ecc_curve_nistp256 = {
|
||||
32, /* .ltc_size */
|
||||
NULL, /* .dp */
|
||||
@@ -15,7 +14,7 @@ struct dropbear_ecc_curve ecc_curve_nistp256 = {
|
||||
"nistp256" /* .name */
|
||||
};
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_384
|
||||
#if DROPBEAR_ECC_384
|
||||
struct dropbear_ecc_curve ecc_curve_nistp384 = {
|
||||
48, /* .ltc_size */
|
||||
NULL, /* .dp */
|
||||
@@ -23,7 +22,7 @@ struct dropbear_ecc_curve ecc_curve_nistp384 = {
|
||||
"nistp384" /* .name */
|
||||
};
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_521
|
||||
#if DROPBEAR_ECC_521
|
||||
struct dropbear_ecc_curve ecc_curve_nistp521 = {
|
||||
66, /* .ltc_size */
|
||||
NULL, /* .dp */
|
||||
@@ -33,13 +32,13 @@ struct dropbear_ecc_curve ecc_curve_nistp521 = {
|
||||
#endif
|
||||
|
||||
struct dropbear_ecc_curve *dropbear_ecc_curves[] = {
|
||||
#ifdef DROPBEAR_ECC_256
|
||||
#if DROPBEAR_ECC_256
|
||||
&ecc_curve_nistp256,
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_384
|
||||
#if DROPBEAR_ECC_384
|
||||
&ecc_curve_nistp384,
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_521
|
||||
#if DROPBEAR_ECC_521
|
||||
&ecc_curve_nistp521,
|
||||
#endif
|
||||
NULL
|
||||
@@ -82,7 +81,7 @@ ecc_key * new_ecc_key(void) {
|
||||
|
||||
/* Copied from libtomcrypt ecc_import.c (version there is static), modified
|
||||
for different mp_int pointer without LTC_SOURCE */
|
||||
static int ecc_is_point(ecc_key *key)
|
||||
static int ecc_is_point(const ecc_key *key)
|
||||
{
|
||||
mp_int *prime, *b, *t1, *t2;
|
||||
int err;
|
||||
@@ -213,7 +212,7 @@ ecc_key * buf_get_ecc_raw_pubkey(buffer *buf, const struct dropbear_ecc_curve *c
|
||||
|
||||
/* a modified version of libtomcrypt's "ecc_shared_secret" to output
|
||||
a mp_int instead. */
|
||||
mp_int * dropbear_ecc_shared_secret(ecc_key *public_key, ecc_key *private_key)
|
||||
mp_int * dropbear_ecc_shared_secret(ecc_key *public_key, const ecc_key *private_key)
|
||||
{
|
||||
ecc_point *result = NULL;
|
||||
mp_int *prime = NULL, *shared_secret = NULL;
|
||||
@@ -221,46 +220,41 @@ mp_int * dropbear_ecc_shared_secret(ecc_key *public_key, ecc_key *private_key)
|
||||
|
||||
/* type valid? */
|
||||
if (private_key->type != PK_PRIVATE) {
|
||||
goto done;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (private_key->dp != public_key->dp) {
|
||||
goto done;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* make new point */
|
||||
result = ltc_ecc_new_point();
|
||||
if (result == NULL) {
|
||||
goto done;
|
||||
goto out;
|
||||
}
|
||||
|
||||
prime = m_malloc(sizeof(*prime));
|
||||
m_mp_init(prime);
|
||||
|
||||
if (mp_read_radix(prime, (char *)private_key->dp->prime, 16) != CRYPT_OK) {
|
||||
goto done;
|
||||
goto out;
|
||||
}
|
||||
if (ltc_mp.ecc_ptmul(private_key->k, &public_key->pubkey, result, prime, 1) != CRYPT_OK) {
|
||||
goto done;
|
||||
goto out;
|
||||
}
|
||||
|
||||
shared_secret = m_malloc(sizeof(*shared_secret));
|
||||
m_mp_init(shared_secret);
|
||||
if (mp_copy(result->x, shared_secret) != CRYPT_OK) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
mp_clear(prime);
|
||||
m_free(prime);
|
||||
ltc_ecc_del_point(result);
|
||||
|
||||
err = DROPBEAR_SUCCESS;
|
||||
done:
|
||||
if (err == DROPBEAR_SUCCESS) {
|
||||
shared_secret = m_malloc(sizeof(*shared_secret));
|
||||
m_mp_init(shared_secret);
|
||||
mp_copy(result->x, shared_secret);
|
||||
}
|
||||
|
||||
if (prime) {
|
||||
mp_clear(prime);
|
||||
m_free(prime);
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
ltc_ecc_del_point(result);
|
||||
}
|
||||
|
||||
out:
|
||||
if (err == DROPBEAR_FAILURE) {
|
||||
dropbear_exit("ECC error");
|
||||
}
|
||||
|
||||
5
ecc.h
5
ecc.h
@@ -2,11 +2,10 @@
|
||||
#define DROPBEAR_DROPBEAR_ECC_H
|
||||
|
||||
#include "includes.h"
|
||||
#include "options.h"
|
||||
|
||||
#include "buffer.h"
|
||||
|
||||
#ifdef DROPBEAR_ECC
|
||||
#if DROPBEAR_ECC
|
||||
|
||||
struct dropbear_ecc_curve {
|
||||
int ltc_size; /* to match the byte sizes in ltc_ecc_sets[] */
|
||||
@@ -29,7 +28,7 @@ void buf_put_ecc_raw_pubkey_string(buffer *buf, ecc_key *key);
|
||||
ecc_key * buf_get_ecc_raw_pubkey(buffer *buf, const struct dropbear_ecc_curve *curve);
|
||||
int buf_get_ecc_privkey_string(buffer *buf, ecc_key *key);
|
||||
|
||||
mp_int * dropbear_ecc_shared_secret(ecc_key *pub_key, ecc_key *priv_key);
|
||||
mp_int * dropbear_ecc_shared_secret(ecc_key *pub_key, const ecc_key *priv_key);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
27
ecdsa.c
27
ecdsa.c
@@ -1,4 +1,3 @@
|
||||
#include "options.h"
|
||||
#include "includes.h"
|
||||
#include "dbutil.h"
|
||||
#include "crypto_desc.h"
|
||||
@@ -6,7 +5,7 @@
|
||||
#include "ecdsa.h"
|
||||
#include "signkey.h"
|
||||
|
||||
#ifdef DROPBEAR_ECDSA
|
||||
#if DROPBEAR_ECDSA
|
||||
|
||||
int signkey_is_ecdsa(enum signkey_type type)
|
||||
{
|
||||
@@ -15,18 +14,18 @@ int signkey_is_ecdsa(enum signkey_type type)
|
||||
|| type == DROPBEAR_SIGNKEY_ECDSA_NISTP521;
|
||||
}
|
||||
|
||||
enum signkey_type ecdsa_signkey_type(ecc_key * key) {
|
||||
#ifdef DROPBEAR_ECC_256
|
||||
enum signkey_type ecdsa_signkey_type(const ecc_key * key) {
|
||||
#if DROPBEAR_ECC_256
|
||||
if (key->dp == ecc_curve_nistp256.dp) {
|
||||
return DROPBEAR_SIGNKEY_ECDSA_NISTP256;
|
||||
}
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_384
|
||||
#if DROPBEAR_ECC_384
|
||||
if (key->dp == ecc_curve_nistp384.dp) {
|
||||
return DROPBEAR_SIGNKEY_ECDSA_NISTP384;
|
||||
}
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_521
|
||||
#if DROPBEAR_ECC_521
|
||||
if (key->dp == ecc_curve_nistp521.dp) {
|
||||
return DROPBEAR_SIGNKEY_ECDSA_NISTP521;
|
||||
}
|
||||
@@ -38,17 +37,17 @@ ecc_key *gen_ecdsa_priv_key(unsigned int bit_size) {
|
||||
const ltc_ecc_set_type *dp = NULL; /* curve domain parameters */
|
||||
ecc_key *new_key = NULL;
|
||||
switch (bit_size) {
|
||||
#ifdef DROPBEAR_ECC_256
|
||||
#if DROPBEAR_ECC_256
|
||||
case 256:
|
||||
dp = ecc_curve_nistp256.dp;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_384
|
||||
#if DROPBEAR_ECC_384
|
||||
case 384:
|
||||
dp = ecc_curve_nistp384.dp;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_521
|
||||
#if DROPBEAR_ECC_521
|
||||
case 521:
|
||||
dp = ecc_curve_nistp521.dp;
|
||||
break;
|
||||
@@ -56,13 +55,13 @@ ecc_key *gen_ecdsa_priv_key(unsigned int bit_size) {
|
||||
}
|
||||
if (!dp) {
|
||||
dropbear_exit("Key size %d isn't valid. Try "
|
||||
#ifdef DROPBEAR_ECC_256
|
||||
#if DROPBEAR_ECC_256
|
||||
"256 "
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_384
|
||||
#if DROPBEAR_ECC_384
|
||||
"384 "
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECC_521
|
||||
#if DROPBEAR_ECC_521
|
||||
"521 "
|
||||
#endif
|
||||
, bit_size);
|
||||
@@ -154,7 +153,7 @@ void buf_put_ecdsa_priv_key(buffer *buf, ecc_key *key) {
|
||||
buf_putmpint(buf, key->k);
|
||||
}
|
||||
|
||||
void buf_put_ecdsa_sign(buffer *buf, ecc_key *key, buffer *data_buf) {
|
||||
void buf_put_ecdsa_sign(buffer *buf, const ecc_key *key, const buffer *data_buf) {
|
||||
/* Based on libtomcrypt's ecc_sign_hash but without the asn1 */
|
||||
int err = DROPBEAR_FAILURE;
|
||||
struct dropbear_ecc_curve *curve = NULL;
|
||||
@@ -272,7 +271,7 @@ out:
|
||||
}
|
||||
|
||||
|
||||
int buf_ecdsa_verify(buffer *buf, ecc_key *key, buffer *data_buf) {
|
||||
int buf_ecdsa_verify(buffer *buf, const ecc_key *key, const buffer *data_buf) {
|
||||
/* Based on libtomcrypt's ecc_verify_hash but without the asn1 */
|
||||
int ret = DROPBEAR_FAILURE;
|
||||
hash_state hs;
|
||||
|
||||
21
ecdsa.h
21
ecdsa.h
@@ -5,15 +5,16 @@
|
||||
#include "buffer.h"
|
||||
#include "signkey.h"
|
||||
|
||||
#ifdef DROPBEAR_ECDSA
|
||||
#if DROPBEAR_ECDSA
|
||||
|
||||
/* Prefer the larger size - it's fast anyway */
|
||||
#if defined(DROPBEAR_ECC_521)
|
||||
#define ECDSA_DEFAULT_SIZE 521
|
||||
#elif defined(DROPBEAR_ECC_384)
|
||||
#define ECDSA_DEFAULT_SIZE 384
|
||||
#elif defined(DROPBEAR_ECC_256)
|
||||
/* prefer 256 or 384 since those are SHOULD for
|
||||
draft-ietf-curdle-ssh-kex-sha2.txt */
|
||||
#if DROPBEAR_ECC_256
|
||||
#define ECDSA_DEFAULT_SIZE 256
|
||||
#elif DROPBEAR_ECC_384
|
||||
#define ECDSA_DEFAULT_SIZE 384
|
||||
#elif DROPBEAR_ECC_521
|
||||
#define ECDSA_DEFAULT_SIZE 521
|
||||
#else
|
||||
#define ECDSA_DEFAULT_SIZE 0
|
||||
#endif
|
||||
@@ -23,10 +24,10 @@ ecc_key *buf_get_ecdsa_pub_key(buffer* buf);
|
||||
ecc_key *buf_get_ecdsa_priv_key(buffer *buf);
|
||||
void buf_put_ecdsa_pub_key(buffer *buf, ecc_key *key);
|
||||
void buf_put_ecdsa_priv_key(buffer *buf, ecc_key *key);
|
||||
enum signkey_type ecdsa_signkey_type(ecc_key * key);
|
||||
enum signkey_type ecdsa_signkey_type(const ecc_key * key);
|
||||
|
||||
void buf_put_ecdsa_sign(buffer *buf, ecc_key *key, buffer *data_buf);
|
||||
int buf_ecdsa_verify(buffer *buf, ecc_key *key, buffer *data_buf);
|
||||
void buf_put_ecdsa_sign(buffer *buf, const ecc_key *key, const buffer *data_buf);
|
||||
int buf_ecdsa_verify(buffer *buf, const ecc_key *key, const buffer *data_buf);
|
||||
/* Returns 1 on success */
|
||||
int signkey_is_ecdsa(enum signkey_type type);
|
||||
|
||||
|
||||
22
gendss.c
22
gendss.c
@@ -35,13 +35,13 @@
|
||||
|
||||
/* This is just a test */
|
||||
|
||||
#ifdef DROPBEAR_DSS
|
||||
#if DROPBEAR_DSS
|
||||
|
||||
static void getq(dropbear_dss_key *key);
|
||||
static void getp(dropbear_dss_key *key, unsigned int size);
|
||||
static void getg(dropbear_dss_key *key);
|
||||
static void getx(dropbear_dss_key *key);
|
||||
static void gety(dropbear_dss_key *key);
|
||||
static void getq(const dropbear_dss_key *key);
|
||||
static void getp(const dropbear_dss_key *key, unsigned int size);
|
||||
static void getg(const dropbear_dss_key *key);
|
||||
static void getx(const dropbear_dss_key *key);
|
||||
static void gety(const dropbear_dss_key *key);
|
||||
|
||||
dropbear_dss_key * gen_dss_priv_key(unsigned int size) {
|
||||
|
||||
@@ -65,7 +65,7 @@ dropbear_dss_key * gen_dss_priv_key(unsigned int size) {
|
||||
|
||||
}
|
||||
|
||||
static void getq(dropbear_dss_key *key) {
|
||||
static void getq(const dropbear_dss_key *key) {
|
||||
|
||||
unsigned char buf[QSIZE];
|
||||
|
||||
@@ -83,7 +83,7 @@ static void getq(dropbear_dss_key *key) {
|
||||
}
|
||||
}
|
||||
|
||||
static void getp(dropbear_dss_key *key, unsigned int size) {
|
||||
static void getp(const dropbear_dss_key *key, unsigned int size) {
|
||||
|
||||
DEF_MP_INT(tempX);
|
||||
DEF_MP_INT(tempC);
|
||||
@@ -142,7 +142,7 @@ static void getp(dropbear_dss_key *key, unsigned int size) {
|
||||
m_free(buf);
|
||||
}
|
||||
|
||||
static void getg(dropbear_dss_key * key) {
|
||||
static void getg(const dropbear_dss_key * key) {
|
||||
|
||||
DEF_MP_INT(div);
|
||||
DEF_MP_INT(h);
|
||||
@@ -179,12 +179,12 @@ static void getg(dropbear_dss_key * key) {
|
||||
mp_clear_multi(&div, &h, &val, NULL);
|
||||
}
|
||||
|
||||
static void getx(dropbear_dss_key *key) {
|
||||
static void getx(const dropbear_dss_key *key) {
|
||||
|
||||
gen_random_mpint(key->q, key->x);
|
||||
}
|
||||
|
||||
static void gety(dropbear_dss_key *key) {
|
||||
static void gety(const dropbear_dss_key *key) {
|
||||
|
||||
if (mp_exptmod(key->g, key->x, key->p, key->y) != MP_OKAY) {
|
||||
fprintf(stderr, "DSS key generation failed\n");
|
||||
|
||||
2
gendss.h
2
gendss.h
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "dss.h"
|
||||
|
||||
#ifdef DROPBEAR_DSS
|
||||
#if DROPBEAR_DSS
|
||||
|
||||
dropbear_dss_key * gen_dss_priv_key(unsigned int size);
|
||||
|
||||
|
||||
2
genrsa.c
2
genrsa.c
@@ -31,7 +31,7 @@
|
||||
|
||||
#define RSA_E 65537
|
||||
|
||||
#ifdef DROPBEAR_RSA
|
||||
#if DROPBEAR_RSA
|
||||
|
||||
static void getrsaprime(mp_int* prime, mp_int *primeminus,
|
||||
mp_int* rsa_e, unsigned int size_bytes);
|
||||
|
||||
2
genrsa.h
2
genrsa.h
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "rsa.h"
|
||||
|
||||
#ifdef DROPBEAR_RSA
|
||||
#if DROPBEAR_RSA
|
||||
|
||||
dropbear_rsa_key * gen_rsa_priv_key(unsigned int size);
|
||||
|
||||
|
||||
72
gensignkey.c
72
gensignkey.c
@@ -7,9 +7,6 @@
|
||||
#include "signkey.h"
|
||||
#include "dbrandom.h"
|
||||
|
||||
#define RSA_DEFAULT_SIZE 2048
|
||||
#define DSS_DEFAULT_SIZE 1024
|
||||
|
||||
/* Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
|
||||
static int buf_writefile(buffer * buf, const char * filename) {
|
||||
int ret = DROPBEAR_FAILURE;
|
||||
@@ -53,15 +50,16 @@ out:
|
||||
static int get_default_bits(enum signkey_type keytype)
|
||||
{
|
||||
switch (keytype) {
|
||||
#ifdef DROPBEAR_RSA
|
||||
#if DROPBEAR_RSA
|
||||
case DROPBEAR_SIGNKEY_RSA:
|
||||
return RSA_DEFAULT_SIZE;
|
||||
return DROPBEAR_DEFAULT_RSA_SIZE;
|
||||
#endif
|
||||
#ifdef DROPBEAR_DSS
|
||||
#if DROPBEAR_DSS
|
||||
case DROPBEAR_SIGNKEY_DSS:
|
||||
return DSS_DEFAULT_SIZE;
|
||||
/* DSS for SSH only defines 1024 bits */
|
||||
return 1024;
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECDSA
|
||||
#if DROPBEAR_ECDSA
|
||||
case DROPBEAR_SIGNKEY_ECDSA_KEYGEN:
|
||||
return ECDSA_DEFAULT_SIZE;
|
||||
case DROPBEAR_SIGNKEY_ECDSA_NISTP521:
|
||||
@@ -76,15 +74,22 @@ static int get_default_bits(enum signkey_type keytype)
|
||||
}
|
||||
}
|
||||
|
||||
int signkey_generate(enum signkey_type keytype, int bits, const char* filename)
|
||||
{
|
||||
sign_key * key = NULL;
|
||||
buffer *buf = NULL;
|
||||
int ret = DROPBEAR_FAILURE;
|
||||
int signkey_generate_get_bits(enum signkey_type keytype, int bits) {
|
||||
if (bits == 0)
|
||||
{
|
||||
bits = get_default_bits(keytype);
|
||||
}
|
||||
return bits;
|
||||
}
|
||||
|
||||
/* if skip_exist is set it will silently return if the key file exists */
|
||||
int signkey_generate(enum signkey_type keytype, int bits, const char* filename, int skip_exist)
|
||||
{
|
||||
sign_key * key = NULL;
|
||||
buffer *buf = NULL;
|
||||
char *fn_temp = NULL;
|
||||
int ret = DROPBEAR_FAILURE;
|
||||
bits = signkey_generate_get_bits(keytype, bits);
|
||||
|
||||
/* now we can generate the key */
|
||||
key = new_sign_key();
|
||||
@@ -92,17 +97,17 @@ int signkey_generate(enum signkey_type keytype, int bits, const char* filename)
|
||||
seedrandom();
|
||||
|
||||
switch(keytype) {
|
||||
#ifdef DROPBEAR_RSA
|
||||
#if DROPBEAR_RSA
|
||||
case DROPBEAR_SIGNKEY_RSA:
|
||||
key->rsakey = gen_rsa_priv_key(bits);
|
||||
break;
|
||||
#endif
|
||||
#ifdef DROPBEAR_DSS
|
||||
#if DROPBEAR_DSS
|
||||
case DROPBEAR_SIGNKEY_DSS:
|
||||
key->dsskey = gen_dss_priv_key(bits);
|
||||
break;
|
||||
#endif
|
||||
#ifdef DROPBEAR_ECDSA
|
||||
#if DROPBEAR_ECDSA
|
||||
case DROPBEAR_SIGNKEY_ECDSA_KEYGEN:
|
||||
case DROPBEAR_SIGNKEY_ECDSA_NISTP521:
|
||||
case DROPBEAR_SIGNKEY_ECDSA_NISTP384:
|
||||
@@ -126,10 +131,37 @@ int signkey_generate(enum signkey_type keytype, int bits, const char* filename)
|
||||
sign_key_free(key);
|
||||
key = NULL;
|
||||
buf_setpos(buf, 0);
|
||||
ret = buf_writefile(buf, filename);
|
||||
|
||||
buf_burn(buf);
|
||||
buf_free(buf);
|
||||
buf = NULL;
|
||||
fn_temp = m_malloc(strlen(filename) + 30);
|
||||
snprintf(fn_temp, strlen(filename)+30, "%s.tmp%d", filename, getpid());
|
||||
ret = buf_writefile(buf, fn_temp);
|
||||
|
||||
if (ret == DROPBEAR_FAILURE) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (link(fn_temp, filename) < 0) {
|
||||
/* If generating keys on connection (skipexist) it's OK to get EEXIST
|
||||
- we probably just lost a race with another connection to generate the key */
|
||||
if (!(skip_exist && errno == EEXIST)) {
|
||||
dropbear_log(LOG_ERR, "Failed moving key file to %s: %s", filename,
|
||||
strerror(errno));
|
||||
/* XXX fallback to non-atomic copy for some filesystems? */
|
||||
ret = DROPBEAR_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if (buf) {
|
||||
buf_burn(buf);
|
||||
buf_free(buf);
|
||||
}
|
||||
|
||||
if (fn_temp) {
|
||||
unlink(fn_temp);
|
||||
m_free(fn_temp);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "signkey.h"
|
||||
|
||||
int signkey_generate(enum signkey_type type, int bits, const char* filename);
|
||||
int signkey_generate(enum signkey_type type, int bits, const char* filename, int skip_exist);
|
||||
int signkey_generate_get_bits(enum signkey_type keytype, int bits);
|
||||
|
||||
#endif
|
||||
|
||||
7
ifndef_wrapper.sh
Executable file
7
ifndef_wrapper.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Wrap all "#define X Y" with a #ifndef X...#endif"
|
||||
|
||||
sed -E 's/^( *#define ([^ ]+) .*)/#ifndef \2\
|
||||
\1\
|
||||
#endif/'
|
||||
@@ -26,7 +26,6 @@
|
||||
#define DROPBEAR_INCLUDES_H_
|
||||
|
||||
|
||||
#include "config.h"
|
||||
#include "options.h"
|
||||
#include "debug.h"
|
||||
|
||||
@@ -156,7 +155,7 @@ typedef unsigned int u_int32_t;
|
||||
typedef u_int32_t uint32_t;
|
||||
#endif /* HAVE_UINT32_T */
|
||||
|
||||
#ifdef SO_PRIORITY
|
||||
#ifdef HAVE_LINUX_PKT_SCHED_H
|
||||
#include <linux/types.h>
|
||||
#include <linux/pkt_sched.h>
|
||||
#endif
|
||||
|
||||
10
kex.h
10
kex.h
@@ -40,17 +40,17 @@ void free_kexdh_param(struct kex_dh_param *param);
|
||||
void kexdh_comb_key(struct kex_dh_param *param, mp_int *dh_pub_them,
|
||||
sign_key *hostkey);
|
||||
|
||||
#ifdef DROPBEAR_ECDH
|
||||
#if DROPBEAR_ECDH
|
||||
struct kex_ecdh_param *gen_kexecdh_param(void);
|
||||
void free_kexecdh_param(struct kex_ecdh_param *param);
|
||||
void kexecdh_comb_key(struct kex_ecdh_param *param, buffer *pub_them,
|
||||
sign_key *hostkey);
|
||||
#endif
|
||||
|
||||
#ifdef DROPBEAR_CURVE25519
|
||||
#if DROPBEAR_CURVE25519
|
||||
struct kex_curve25519_param *gen_kexcurve25519_param(void);
|
||||
void free_kexcurve25519_param(struct kex_curve25519_param *param);
|
||||
void kexcurve25519_comb_key(struct kex_curve25519_param *param, buffer *pub_them,
|
||||
void kexcurve25519_comb_key(const struct kex_curve25519_param *param, const buffer *pub_them,
|
||||
sign_key *hostkey);
|
||||
#endif
|
||||
|
||||
@@ -88,13 +88,13 @@ struct kex_dh_param {
|
||||
mp_int priv; /* x */
|
||||
};
|
||||
|
||||
#ifdef DROPBEAR_ECDH
|
||||
#if DROPBEAR_ECDH
|
||||
struct kex_ecdh_param {
|
||||
ecc_key key;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef DROPBEAR_CURVE25519
|
||||
#if DROPBEAR_CURVE25519
|
||||
#define CURVE25519_LEN 32
|
||||
struct kex_curve25519_param {
|
||||
unsigned char priv[CURVE25519_LEN];
|
||||
|
||||
1242
keyimport.c
1242
keyimport.c
File diff suppressed because it is too large
Load Diff
@@ -34,9 +34,9 @@ enum {
|
||||
KEYFILE_SSHCOM
|
||||
};
|
||||
|
||||
int import_write(const char *filename, sign_key *key, char *passphrase,
|
||||
int import_write(const char *filename, sign_key *key, const char *passphrase,
|
||||
int filetype);
|
||||
sign_key *import_read(const char *filename, char *passphrase, int filetype);
|
||||
sign_key *import_read(const char *filename, const char *passphrase, int filetype);
|
||||
int import_encrypted(const char* filename, int filetype);
|
||||
|
||||
#endif /* DROPBEAR_KEYIMPORT_H_ */
|
||||
|
||||
135
libtomcrypt/.travis.yml
Normal file
135
libtomcrypt/.travis.yml
Normal file
@@ -0,0 +1,135 @@
|
||||
dist: trusty
|
||||
sudo: required
|
||||
|
||||
language: c
|
||||
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
packages:
|
||||
- clang-3.8
|
||||
|
||||
install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install libtommath-dev
|
||||
|
||||
before_script:
|
||||
- gem install coveralls-lcov
|
||||
- curl http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.11.orig.tar.gz | tar xz
|
||||
- export PATH=$PATH:`pwd`/lcov-1.11/bin
|
||||
- curl -s https://packagecloud.io/install/repositories/libtom/packages/script.deb.sh | sudo bash
|
||||
- sudo apt-get install libtfm-dev=0.13-5
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
- /^release\/.*$/
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
script:
|
||||
- bash "${BUILDSCRIPT}" "${BUILDNAME}" "${BUILDOPTIONS}" "makefile V=1" "-DUSE_LTM -DLTM_DESC" "-ltommath"
|
||||
- bash "${BUILDSCRIPT}" "${BUILDNAME}" "${BUILDOPTIONS}" "makefile.shared V=1" "-DUSE_TFM -DTFM_DESC" "-ltfm"
|
||||
env:
|
||||
- |
|
||||
BUILDSCRIPT="check_source.sh"
|
||||
BUILDNAME="CHECK_SOURCES"
|
||||
BUILDOPTIONS=" "
|
||||
- |
|
||||
BUILDSCRIPT="scan_build.sh"
|
||||
BUILDNAME="SCAN_BUILD"
|
||||
BUILDOPTIONS=" "
|
||||
- |
|
||||
BUILDSCRIPT="coverage.sh"
|
||||
BUILDNAME="COVERAGE"
|
||||
BUILDOPTIONS=" "
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="STOCK"
|
||||
BUILDOPTIONS=" "
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="EASY"
|
||||
BUILDOPTIONS="-DLTC_EASY"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="SMALL"
|
||||
BUILDOPTIONS="-DLTC_SMALL_CODE"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="NOTABLES"
|
||||
BUILDOPTIONS="-DLTC_NO_TABLES"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="SMALL+NOTABLES"
|
||||
BUILDOPTIONS="-DLTC_SMALL_CODE -DLTC_NO_TABLES"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="CLEANSTACK"
|
||||
BUILDOPTIONS="-DLTC_CLEAN_STACK"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="CLEANSTACK+SMALL"
|
||||
BUILDOPTIONS="-DLTC_SMALL_CODE -DLTC_CLEAN_STACK"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="CLEANSTACK+NOTABLES"
|
||||
BUILDOPTIONS="-DLTC_NO_TABLES -DLTC_CLEAN_STACK"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="CLEANSTACK+NOTABLES+SMALL"
|
||||
BUILDOPTIONS="-DLTC_NO_TABLES -DLTC_CLEAN_STACK -DLTC_SMALL_CODE"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="NO_FAST"
|
||||
BUILDOPTIONS="-DLTC_NO_FAST"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="NO_FAST+NOTABLES"
|
||||
BUILDOPTIONS="-DLTC_NO_FAST -DLTC_NO_TABLES"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="NO_ASM"
|
||||
BUILDOPTIONS="-DLTC_NO_ASM"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="NO_TIMING_RESISTANCE"
|
||||
BUILDOPTIONS="-DLTC_NO_ECC_TIMING_RESISTANT -DLTC_NO_RSA_BLINDING"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="CLEANSTACK+NOTABLES+SMALL+NO_ASM+NO_TIMING_RESISTANCE"
|
||||
BUILDOPTIONS="-DLTC_CLEAN_STACK -DLTC_NO_TABLES -DLTC_SMALL_CODE -DLTC_NO_ECC_TIMING_RESISTANT -DLTC_NO_RSA_BLINDING"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="PTHREAD"
|
||||
BUILDOPTIONS="-DLTC_PTHREAD"
|
||||
- |
|
||||
BUILDSCRIPT="run.sh"
|
||||
BUILDNAME="CLEANSTACK+NOTABLES+SMALL+NO_ASM+NO_TIMING_RESISTANCE+PTHREAD"
|
||||
BUILDOPTIONS="-DLTC_CLEAN_STACK -DLTC_NO_TABLES -DLTC_SMALL_CODE -DLTC_NO_ECC_TIMING_RESISTANT -DLTC_NO_RSA_BLINDING -DLTC_PTHREAD"
|
||||
- |
|
||||
BUILDSCRIPT="testbuild.sh"
|
||||
BUILDNAME="NOTEST"
|
||||
BUILDOPTIONS="-DLTC_NO_TEST"
|
||||
- |
|
||||
BUILDSCRIPT="testbuild.sh"
|
||||
BUILDNAME="NOFILE"
|
||||
BUILDOPTIONS="-DLTC_NO_FILE"
|
||||
|
||||
after_failure:
|
||||
- cat test_std.txt
|
||||
- cat test_err.txt
|
||||
- cat tv.txt
|
||||
|
||||
after_script:
|
||||
- cat gcc_1.txt
|
||||
- cat gcc_2.txt
|
||||
|
||||
notifications:
|
||||
irc: "chat.freenode.net#libtom-notifications"
|
||||
@@ -23,7 +23,7 @@ PROJECT_NAME = LibTomCrypt
|
||||
# This could be handy for archiving the generated documentation or
|
||||
# if some version control system is used.
|
||||
|
||||
PROJECT_NUMBER = 1.16
|
||||
PROJECT_NUMBER = 1.17
|
||||
|
||||
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
|
||||
# base path where the generated documentation will be put.
|
||||
|
||||
@@ -1,5 +1,29 @@
|
||||
LibTomCrypt is licensed under DUAL licensing terms.
|
||||
|
||||
Choose and use the license of your needs.
|
||||
|
||||
[LICENSE #1]
|
||||
|
||||
LibTomCrypt is public domain. As should all quality software be.
|
||||
|
||||
Tom St Denis
|
||||
|
||||
[/LICENSE #1]
|
||||
|
||||
[LICENSE #2]
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
|
||||
[/LICENSE #2]
|
||||
|
||||
@@ -1,155 +1,134 @@
|
||||
# MAKEFILE for linux GCC
|
||||
# MAKEFILE that is intended to be compatible with any kind of make (GNU make, BSD make, ...)
|
||||
# works on: Linux, *BSD, Cygwin, AIX, HP-UX and hopefully other UNIX systems
|
||||
#
|
||||
# Tom St Denis
|
||||
# Modified by Clay Culver
|
||||
# Please do not use here neither any special make syntax nor any unusual tools/utilities!
|
||||
#
|
||||
# BEWARE: variables OBJECTS, TOBJECTS, HEADERS, VERSION are updated via ./updatemakes.sh
|
||||
|
||||
# The version
|
||||
VERSION=1.16
|
||||
### USAGE:
|
||||
#
|
||||
# make -f makefile.unix all
|
||||
# ./test
|
||||
# make -f makefile.unix install
|
||||
#
|
||||
#Or:
|
||||
#
|
||||
# make -f makefile.unix CFLAGS="-O3 -DUSE_LTM -DLTM_DESC -I/path/to/libtommath" EXTRALIBS=/path/to/libtommath/libtommath.a all
|
||||
# ./test
|
||||
# make -f makefile.unix PREFIX=/opt/libtom install
|
||||
#
|
||||
#Or if you are using Intel C compiler you might need something like:
|
||||
#
|
||||
# make -f makefile.unix CC=icc AR=xiar CFLAGS="-fast -DUSE_LTM -DLTM_DESC -I/path/to/libtommath" EXTRALIBS=/path/to/libtommath/libtommath.a all
|
||||
#
|
||||
|
||||
# Dropbear can build out of tree
|
||||
VPATH=@srcdir@
|
||||
srcdir=@srcdir@
|
||||
|
||||
# Compiler and Linker Names
|
||||
#CC=gcc
|
||||
#LD=ld
|
||||
#The following can be overridden from command line e.g. "make -f makefile.unix CC=gcc ARFLAGS=rcs"
|
||||
DESTDIR =
|
||||
PREFIX = /usr/local
|
||||
LIBPATH = $(PREFIX)/lib
|
||||
INCPATH = $(PREFIX)/include
|
||||
DATAPATH = $(PREFIX)/share/doc/libtomcrypt/pdf
|
||||
BINPATH = $(PREFIX)/bin
|
||||
# Dropbear passes paths from parent makefile
|
||||
#CC = cc
|
||||
#AR = ar
|
||||
ARFLAGS = r
|
||||
#RANLIB = ranlib
|
||||
#CFLAGS = -O2 -DUSE_LTM -DLTM_DESC -I../libtommath
|
||||
EXTRALIBS = ../libtommath/libtommath.a
|
||||
|
||||
# Archiver [makes .a files]
|
||||
#AR=ar
|
||||
#ARFLAGS=r
|
||||
#Compilation flags
|
||||
LTC_CFLAGS = -Isrc/headers/ -I$(srcdir)/src/headers/ -I../ -I$(srcdir)/../ -DLTC_SOURCE -I../libtommath/ -I$(srcdir)/../libtommath/ $(CFLAGS)
|
||||
LTC_LDFLAGS = $(LDFLAGS) $(EXTRALIBS)
|
||||
VERSION=1.18.1
|
||||
|
||||
# Compilation flags. Note the += does not write over the user's CFLAGS!
|
||||
# The rest of the flags come from the parent Dropbear makefile
|
||||
CFLAGS += -c -I$(srcdir)/src/headers/ -I$(srcdir)/../ -DLTC_SOURCE -I$(srcdir)/../libtommath/
|
||||
#Libraries to be created (this makefile builds only static libraries)
|
||||
LIBMAIN_S =libtomcrypt.a
|
||||
|
||||
# additional warnings (newer GCC 3.4 and higher)
|
||||
ifdef GCC_34
|
||||
CFLAGS += -Wsystem-headers -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wmissing-prototypes \
|
||||
-Wmissing-declarations -Wpointer-arith
|
||||
endif
|
||||
|
||||
ifndef IGNORE_SPEED
|
||||
|
||||
# optimize for SPEED
|
||||
#CFLAGS += -O3 -funroll-loops
|
||||
|
||||
# add -fomit-frame-pointer. hinders debugging!
|
||||
#CFLAGS += -fomit-frame-pointer
|
||||
|
||||
# optimize for SIZE
|
||||
#CFLAGS += -Os -DLTC_SMALL_CODE
|
||||
|
||||
endif
|
||||
|
||||
# older GCCs can't handle the "rotate with immediate" ROLc/RORc/etc macros
|
||||
# define this to help
|
||||
#CFLAGS += -DLTC_NO_ROLC
|
||||
|
||||
# compile for DEBUGING (required for ccmalloc checking!!!)
|
||||
#CFLAGS += -g3 -DLTC_NO_ASM
|
||||
|
||||
#Output filenames for various targets.
|
||||
ifndef LIBNAME
|
||||
LIBNAME=libtomcrypt.a
|
||||
endif
|
||||
ifndef LIBTEST
|
||||
LIBTEST=libtomcrypt_prof.a
|
||||
endif
|
||||
LIBTEST_S=$(LIBTEST)
|
||||
|
||||
HASH=hashsum
|
||||
CRYPT=encrypt
|
||||
SMALL=small
|
||||
PROF=x86_prof
|
||||
TV=tv_gen
|
||||
MULTI=multi
|
||||
TIMING=timing
|
||||
TEST=test
|
||||
|
||||
#LIBPATH-The directory for libtomcrypt to be installed to.
|
||||
#INCPATH-The directory to install the header files for libtomcrypt.
|
||||
#DATAPATH-The directory to install the pdf docs.
|
||||
ifndef DESTDIR
|
||||
DESTDIR=
|
||||
endif
|
||||
|
||||
ifndef LIBPATH
|
||||
LIBPATH=/usr/lib
|
||||
endif
|
||||
ifndef INCPATH
|
||||
INCPATH=/usr/include
|
||||
endif
|
||||
ifndef DATAPATH
|
||||
DATAPATH=/usr/share/doc/libtomcrypt/pdf
|
||||
endif
|
||||
|
||||
#Who do we install as?
|
||||
ifdef INSTALL_USER
|
||||
USER=$(INSTALL_USER)
|
||||
else
|
||||
USER=root
|
||||
endif
|
||||
|
||||
ifdef INSTALL_GROUP
|
||||
GROUP=$(INSTALL_GROUP)
|
||||
else
|
||||
GROUP=wheel
|
||||
endif
|
||||
|
||||
#List of objects to compile.
|
||||
#START_INS
|
||||
OBJECTS=src/ciphers/aes/aes_enc.o src/ciphers/aes/aes.o src/ciphers/anubis.o src/ciphers/blowfish.o \
|
||||
src/ciphers/cast5.o src/ciphers/des.o src/ciphers/kasumi.o src/ciphers/khazad.o src/ciphers/kseed.o \
|
||||
src/ciphers/noekeon.o src/ciphers/rc2.o src/ciphers/rc5.o src/ciphers/rc6.o src/ciphers/safer/safer.o \
|
||||
src/ciphers/safer/safer_tab.o src/ciphers/safer/saferp.o src/ciphers/skipjack.o \
|
||||
src/ciphers/twofish/twofish.o src/ciphers/xtea.o src/encauth/ccm/ccm_memory.o \
|
||||
src/encauth/ccm/ccm_test.o src/encauth/eax/eax_addheader.o src/encauth/eax/eax_decrypt.o \
|
||||
src/encauth/eax/eax_decrypt_verify_memory.o src/encauth/eax/eax_done.o src/encauth/eax/eax_encrypt.o \
|
||||
src/encauth/eax/eax_encrypt_authenticate_memory.o src/encauth/eax/eax_init.o \
|
||||
src/encauth/eax/eax_test.o src/encauth/gcm/gcm_add_aad.o src/encauth/gcm/gcm_add_iv.o \
|
||||
src/encauth/gcm/gcm_done.o src/encauth/gcm/gcm_gf_mult.o src/encauth/gcm/gcm_init.o \
|
||||
src/encauth/gcm/gcm_memory.o src/encauth/gcm/gcm_mult_h.o src/encauth/gcm/gcm_process.o \
|
||||
src/encauth/gcm/gcm_reset.o src/encauth/gcm/gcm_test.o src/encauth/ocb/ocb_decrypt.o \
|
||||
src/encauth/ocb/ocb_decrypt_verify_memory.o src/encauth/ocb/ocb_done_decrypt.o \
|
||||
src/encauth/ocb/ocb_done_encrypt.o src/encauth/ocb/ocb_encrypt.o \
|
||||
#List of objects to compile (all goes to libtomcrypt.a)
|
||||
OBJECTS=src/ciphers/aes/aes.o src/ciphers/aes/aes_enc.o src/ciphers/anubis.o src/ciphers/blowfish.o \
|
||||
src/ciphers/camellia.o src/ciphers/cast5.o src/ciphers/des.o src/ciphers/kasumi.o src/ciphers/khazad.o \
|
||||
src/ciphers/kseed.o src/ciphers/multi2.o src/ciphers/noekeon.o src/ciphers/rc2.o src/ciphers/rc5.o \
|
||||
src/ciphers/rc6.o src/ciphers/safer/safer.o src/ciphers/safer/saferp.o src/ciphers/skipjack.o \
|
||||
src/ciphers/twofish/twofish.o src/ciphers/xtea.o src/encauth/ccm/ccm_add_aad.o \
|
||||
src/encauth/ccm/ccm_add_nonce.o src/encauth/ccm/ccm_done.o src/encauth/ccm/ccm_init.o \
|
||||
src/encauth/ccm/ccm_memory.o src/encauth/ccm/ccm_process.o src/encauth/ccm/ccm_reset.o \
|
||||
src/encauth/ccm/ccm_test.o src/encauth/chachapoly/chacha20poly1305_add_aad.o \
|
||||
src/encauth/chachapoly/chacha20poly1305_decrypt.o src/encauth/chachapoly/chacha20poly1305_done.o \
|
||||
src/encauth/chachapoly/chacha20poly1305_encrypt.o src/encauth/chachapoly/chacha20poly1305_init.o \
|
||||
src/encauth/chachapoly/chacha20poly1305_memory.o src/encauth/chachapoly/chacha20poly1305_setiv.o \
|
||||
src/encauth/chachapoly/chacha20poly1305_setiv_rfc7905.o \
|
||||
src/encauth/chachapoly/chacha20poly1305_test.o src/encauth/eax/eax_addheader.o \
|
||||
src/encauth/eax/eax_decrypt.o src/encauth/eax/eax_decrypt_verify_memory.o src/encauth/eax/eax_done.o \
|
||||
src/encauth/eax/eax_encrypt.o src/encauth/eax/eax_encrypt_authenticate_memory.o \
|
||||
src/encauth/eax/eax_init.o src/encauth/eax/eax_test.o src/encauth/gcm/gcm_add_aad.o \
|
||||
src/encauth/gcm/gcm_add_iv.o src/encauth/gcm/gcm_done.o src/encauth/gcm/gcm_gf_mult.o \
|
||||
src/encauth/gcm/gcm_init.o src/encauth/gcm/gcm_memory.o src/encauth/gcm/gcm_mult_h.o \
|
||||
src/encauth/gcm/gcm_process.o src/encauth/gcm/gcm_reset.o src/encauth/gcm/gcm_test.o \
|
||||
src/encauth/ocb/ocb_decrypt.o src/encauth/ocb/ocb_decrypt_verify_memory.o \
|
||||
src/encauth/ocb/ocb_done_decrypt.o src/encauth/ocb/ocb_done_encrypt.o src/encauth/ocb/ocb_encrypt.o \
|
||||
src/encauth/ocb/ocb_encrypt_authenticate_memory.o src/encauth/ocb/ocb_init.o src/encauth/ocb/ocb_ntz.o \
|
||||
src/encauth/ocb/ocb_shift_xor.o src/encauth/ocb/ocb_test.o src/encauth/ocb/s_ocb_done.o \
|
||||
src/hashes/chc/chc.o src/hashes/helper/hash_file.o src/hashes/helper/hash_filehandle.o \
|
||||
src/hashes/helper/hash_memory.o src/hashes/helper/hash_memory_multi.o src/hashes/md2.o src/hashes/md4.o \
|
||||
src/hashes/md5.o src/hashes/rmd128.o src/hashes/rmd160.o src/hashes/rmd256.o src/hashes/rmd320.o \
|
||||
src/hashes/sha1.o src/hashes/sha2/sha256.o src/hashes/sha2/sha512.o src/hashes/tiger.o \
|
||||
src/hashes/whirl/whirl.o src/mac/f9/f9_done.o src/mac/f9/f9_file.o src/mac/f9/f9_init.o \
|
||||
src/mac/f9/f9_memory.o src/mac/f9/f9_memory_multi.o src/mac/f9/f9_process.o src/mac/f9/f9_test.o \
|
||||
src/mac/hmac/hmac_done.o src/mac/hmac/hmac_file.o src/mac/hmac/hmac_init.o src/mac/hmac/hmac_memory.o \
|
||||
src/mac/hmac/hmac_memory_multi.o src/mac/hmac/hmac_process.o src/mac/hmac/hmac_test.o \
|
||||
src/mac/omac/omac_done.o src/mac/omac/omac_file.o src/mac/omac/omac_init.o src/mac/omac/omac_memory.o \
|
||||
src/mac/omac/omac_memory_multi.o src/mac/omac/omac_process.o src/mac/omac/omac_test.o \
|
||||
src/mac/pelican/pelican.o src/mac/pelican/pelican_memory.o src/mac/pelican/pelican_test.o \
|
||||
src/mac/pmac/pmac_done.o src/mac/pmac/pmac_file.o src/mac/pmac/pmac_init.o src/mac/pmac/pmac_memory.o \
|
||||
src/encauth/ocb3/ocb3_add_aad.o src/encauth/ocb3/ocb3_decrypt.o src/encauth/ocb3/ocb3_decrypt_last.o \
|
||||
src/encauth/ocb3/ocb3_decrypt_verify_memory.o src/encauth/ocb3/ocb3_done.o \
|
||||
src/encauth/ocb3/ocb3_encrypt.o src/encauth/ocb3/ocb3_encrypt_authenticate_memory.o \
|
||||
src/encauth/ocb3/ocb3_encrypt_last.o src/encauth/ocb3/ocb3_init.o src/encauth/ocb3/ocb3_int_ntz.o \
|
||||
src/encauth/ocb3/ocb3_int_xor_blocks.o src/encauth/ocb3/ocb3_test.o src/hashes/blake2b.o \
|
||||
src/hashes/blake2s.o src/hashes/chc/chc.o src/hashes/helper/hash_file.o \
|
||||
src/hashes/helper/hash_filehandle.o src/hashes/helper/hash_memory.o \
|
||||
src/hashes/helper/hash_memory_multi.o src/hashes/md2.o src/hashes/md4.o src/hashes/md5.o \
|
||||
src/hashes/rmd128.o src/hashes/rmd160.o src/hashes/rmd256.o src/hashes/rmd320.o src/hashes/sha1.o \
|
||||
src/hashes/sha2/sha224.o src/hashes/sha2/sha256.o src/hashes/sha2/sha384.o src/hashes/sha2/sha512.o \
|
||||
src/hashes/sha2/sha512_224.o src/hashes/sha2/sha512_256.o src/hashes/sha3.o src/hashes/sha3_test.o \
|
||||
src/hashes/tiger.o src/hashes/whirl/whirl.o src/mac/blake2/blake2bmac.o \
|
||||
src/mac/blake2/blake2bmac_file.o src/mac/blake2/blake2bmac_memory.o \
|
||||
src/mac/blake2/blake2bmac_memory_multi.o src/mac/blake2/blake2bmac_test.o src/mac/blake2/blake2smac.o \
|
||||
src/mac/blake2/blake2smac_file.o src/mac/blake2/blake2smac_memory.o \
|
||||
src/mac/blake2/blake2smac_memory_multi.o src/mac/blake2/blake2smac_test.o src/mac/f9/f9_done.o \
|
||||
src/mac/f9/f9_file.o src/mac/f9/f9_init.o src/mac/f9/f9_memory.o src/mac/f9/f9_memory_multi.o \
|
||||
src/mac/f9/f9_process.o src/mac/f9/f9_test.o src/mac/hmac/hmac_done.o src/mac/hmac/hmac_file.o \
|
||||
src/mac/hmac/hmac_init.o src/mac/hmac/hmac_memory.o src/mac/hmac/hmac_memory_multi.o \
|
||||
src/mac/hmac/hmac_process.o src/mac/hmac/hmac_test.o src/mac/omac/omac_done.o src/mac/omac/omac_file.o \
|
||||
src/mac/omac/omac_init.o src/mac/omac/omac_memory.o src/mac/omac/omac_memory_multi.o \
|
||||
src/mac/omac/omac_process.o src/mac/omac/omac_test.o src/mac/pelican/pelican.o \
|
||||
src/mac/pelican/pelican_memory.o src/mac/pelican/pelican_test.o src/mac/pmac/pmac_done.o \
|
||||
src/mac/pmac/pmac_file.o src/mac/pmac/pmac_init.o src/mac/pmac/pmac_memory.o \
|
||||
src/mac/pmac/pmac_memory_multi.o src/mac/pmac/pmac_ntz.o src/mac/pmac/pmac_process.o \
|
||||
src/mac/pmac/pmac_shift_xor.o src/mac/pmac/pmac_test.o src/mac/xcbc/xcbc_done.o \
|
||||
src/mac/pmac/pmac_shift_xor.o src/mac/pmac/pmac_test.o src/mac/poly1305/poly1305.o \
|
||||
src/mac/poly1305/poly1305_file.o src/mac/poly1305/poly1305_memory.o \
|
||||
src/mac/poly1305/poly1305_memory_multi.o src/mac/poly1305/poly1305_test.o src/mac/xcbc/xcbc_done.o \
|
||||
src/mac/xcbc/xcbc_file.o src/mac/xcbc/xcbc_init.o src/mac/xcbc/xcbc_memory.o \
|
||||
src/mac/xcbc/xcbc_memory_multi.o src/mac/xcbc/xcbc_process.o src/mac/xcbc/xcbc_test.o \
|
||||
src/math/fp/ltc_ecc_fp_mulmod.o src/math/gmp_desc.o src/math/ltm_desc.o src/math/multi.o \
|
||||
src/math/rand_prime.o src/math/tfm_desc.o src/misc/base64/base64_decode.o \
|
||||
src/misc/base64/base64_encode.o src/misc/burn_stack.o src/misc/crypt/crypt.o \
|
||||
src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt_cipher_descriptor.o \
|
||||
src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_find_cipher.o \
|
||||
src/math/radix_to_bin.o src/math/rand_bn.o src/math/rand_prime.o src/math/tfm_desc.o src/misc/adler32.o \
|
||||
src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o src/misc/burn_stack.o \
|
||||
src/misc/compare_testvector.o src/misc/crc32.o src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o \
|
||||
src/misc/crypt/crypt_cipher_descriptor.o src/misc/crypt/crypt_cipher_is_valid.o \
|
||||
src/misc/crypt/crypt_constants.o src/misc/crypt/crypt_find_cipher.o \
|
||||
src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher_id.o \
|
||||
src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_any.o \
|
||||
src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_hash_oid.o \
|
||||
src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o src/misc/crypt/crypt_hash_descriptor.o \
|
||||
src/misc/crypt/crypt_hash_is_valid.o src/misc/crypt/crypt_ltc_mp_descriptor.o \
|
||||
src/misc/crypt/crypt_prng_descriptor.o src/misc/crypt/crypt_prng_is_valid.o \
|
||||
src/misc/crypt/crypt_register_cipher.o src/misc/crypt/crypt_register_hash.o \
|
||||
src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_unregister_cipher.o \
|
||||
src/misc/crypt/crypt_unregister_hash.o src/misc/crypt/crypt_unregister_prng.o \
|
||||
src/misc/error_to_string.o src/misc/pkcs5/pkcs_5_1.o src/misc/pkcs5/pkcs_5_2.o src/misc/zeromem.o \
|
||||
src/modes/cbc/cbc_decrypt.o src/modes/cbc/cbc_done.o src/modes/cbc/cbc_encrypt.o \
|
||||
src/modes/cbc/cbc_getiv.o src/modes/cbc/cbc_setiv.o src/modes/cbc/cbc_start.o \
|
||||
src/modes/cfb/cfb_decrypt.o src/modes/cfb/cfb_done.o src/modes/cfb/cfb_encrypt.o \
|
||||
src/modes/cfb/cfb_getiv.o src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o \
|
||||
src/modes/ctr/ctr_decrypt.o src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o \
|
||||
src/modes/ctr/ctr_getiv.o src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o src/modes/ctr/ctr_test.o \
|
||||
src/misc/crypt/crypt_hash_is_valid.o src/misc/crypt/crypt_inits.o \
|
||||
src/misc/crypt/crypt_ltc_mp_descriptor.o src/misc/crypt/crypt_prng_descriptor.o \
|
||||
src/misc/crypt/crypt_prng_is_valid.o src/misc/crypt/crypt_prng_rng_descriptor.o \
|
||||
src/misc/crypt/crypt_register_all_ciphers.o src/misc/crypt/crypt_register_all_hashes.o \
|
||||
src/misc/crypt/crypt_register_all_prngs.o src/misc/crypt/crypt_register_cipher.o \
|
||||
src/misc/crypt/crypt_register_hash.o src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_sizes.o \
|
||||
src/misc/crypt/crypt_unregister_cipher.o src/misc/crypt/crypt_unregister_hash.o \
|
||||
src/misc/crypt/crypt_unregister_prng.o src/misc/error_to_string.o src/misc/hkdf/hkdf.o \
|
||||
src/misc/hkdf/hkdf_test.o src/misc/mem_neq.o src/misc/pk_get_oid.o src/misc/pkcs5/pkcs_5_1.o \
|
||||
src/misc/pkcs5/pkcs_5_2.o src/misc/pkcs5/pkcs_5_test.o src/misc/zeromem.o src/modes/cbc/cbc_decrypt.o \
|
||||
src/modes/cbc/cbc_done.o src/modes/cbc/cbc_encrypt.o src/modes/cbc/cbc_getiv.o \
|
||||
src/modes/cbc/cbc_setiv.o src/modes/cbc/cbc_start.o src/modes/cfb/cfb_decrypt.o \
|
||||
src/modes/cfb/cfb_done.o src/modes/cfb/cfb_encrypt.o src/modes/cfb/cfb_getiv.o \
|
||||
src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o src/modes/ctr/ctr_decrypt.o \
|
||||
src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o src/modes/ctr/ctr_getiv.o \
|
||||
src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o src/modes/ctr/ctr_test.o \
|
||||
src/modes/ecb/ecb_decrypt.o src/modes/ecb/ecb_done.o src/modes/ecb/ecb_encrypt.o \
|
||||
src/modes/ecb/ecb_start.o src/modes/f8/f8_decrypt.o src/modes/f8/f8_done.o src/modes/f8/f8_encrypt.o \
|
||||
src/modes/f8/f8_getiv.o src/modes/f8/f8_setiv.o src/modes/f8/f8_start.o src/modes/f8/f8_test_mode.o \
|
||||
@@ -157,10 +136,16 @@ src/modes/lrw/lrw_decrypt.o src/modes/lrw/lrw_done.o src/modes/lrw/lrw_encrypt.o
|
||||
src/modes/lrw/lrw_getiv.o src/modes/lrw/lrw_process.o src/modes/lrw/lrw_setiv.o \
|
||||
src/modes/lrw/lrw_start.o src/modes/lrw/lrw_test.o src/modes/ofb/ofb_decrypt.o src/modes/ofb/ofb_done.o \
|
||||
src/modes/ofb/ofb_encrypt.o src/modes/ofb/ofb_getiv.o src/modes/ofb/ofb_setiv.o \
|
||||
src/modes/ofb/ofb_start.o src/pk/asn1/der/bit/der_decode_bit_string.o \
|
||||
src/pk/asn1/der/bit/der_encode_bit_string.o src/pk/asn1/der/bit/der_length_bit_string.o \
|
||||
src/modes/ofb/ofb_start.o src/modes/xts/xts_decrypt.o src/modes/xts/xts_done.o \
|
||||
src/modes/xts/xts_encrypt.o src/modes/xts/xts_init.o src/modes/xts/xts_mult_x.o \
|
||||
src/modes/xts/xts_test.o src/pk/asn1/der/bit/der_decode_bit_string.o \
|
||||
src/pk/asn1/der/bit/der_decode_raw_bit_string.o src/pk/asn1/der/bit/der_encode_bit_string.o \
|
||||
src/pk/asn1/der/bit/der_encode_raw_bit_string.o src/pk/asn1/der/bit/der_length_bit_string.o \
|
||||
src/pk/asn1/der/boolean/der_decode_boolean.o src/pk/asn1/der/boolean/der_encode_boolean.o \
|
||||
src/pk/asn1/der/boolean/der_length_boolean.o src/pk/asn1/der/choice/der_decode_choice.o \
|
||||
src/pk/asn1/der/generalizedtime/der_decode_generalizedtime.o \
|
||||
src/pk/asn1/der/generalizedtime/der_encode_generalizedtime.o \
|
||||
src/pk/asn1/der/generalizedtime/der_length_generalizedtime.o \
|
||||
src/pk/asn1/der/ia5/der_decode_ia5_string.o src/pk/asn1/der/ia5/der_encode_ia5_string.o \
|
||||
src/pk/asn1/der/ia5/der_length_ia5_string.o src/pk/asn1/der/integer/der_decode_integer.o \
|
||||
src/pk/asn1/der/integer/der_encode_integer.o src/pk/asn1/der/integer/der_length_integer.o \
|
||||
@@ -175,22 +160,32 @@ src/pk/asn1/der/printable_string/der_length_printable_string.o \
|
||||
src/pk/asn1/der/sequence/der_decode_sequence_ex.o \
|
||||
src/pk/asn1/der/sequence/der_decode_sequence_flexi.o \
|
||||
src/pk/asn1/der/sequence/der_decode_sequence_multi.o \
|
||||
src/pk/asn1/der/sequence/der_decode_subject_public_key_info.o \
|
||||
src/pk/asn1/der/sequence/der_encode_sequence_ex.o \
|
||||
src/pk/asn1/der/sequence/der_encode_sequence_multi.o src/pk/asn1/der/sequence/der_length_sequence.o \
|
||||
src/pk/asn1/der/sequence/der_sequence_free.o src/pk/asn1/der/set/der_encode_set.o \
|
||||
src/pk/asn1/der/sequence/der_encode_sequence_multi.o \
|
||||
src/pk/asn1/der/sequence/der_encode_subject_public_key_info.o \
|
||||
src/pk/asn1/der/sequence/der_length_sequence.o src/pk/asn1/der/sequence/der_sequence_free.o \
|
||||
src/pk/asn1/der/sequence/der_sequence_shrink.o src/pk/asn1/der/set/der_encode_set.o \
|
||||
src/pk/asn1/der/set/der_encode_setof.o src/pk/asn1/der/short_integer/der_decode_short_integer.o \
|
||||
src/pk/asn1/der/short_integer/der_encode_short_integer.o \
|
||||
src/pk/asn1/der/short_integer/der_length_short_integer.o src/pk/asn1/der/utctime/der_decode_utctime.o \
|
||||
src/pk/asn1/der/utctime/der_encode_utctime.o src/pk/asn1/der/utctime/der_length_utctime.o \
|
||||
src/pk/asn1/der/utf8/der_decode_utf8_string.o src/pk/asn1/der/utf8/der_encode_utf8_string.o \
|
||||
src/pk/asn1/der/utf8/der_length_utf8_string.o src/pk/dsa/dsa_decrypt_key.o \
|
||||
src/pk/dsa/dsa_encrypt_key.o src/pk/dsa/dsa_export.o src/pk/dsa/dsa_free.o src/pk/dsa/dsa_import.o \
|
||||
src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_shared_secret.o src/pk/dsa/dsa_sign_hash.o \
|
||||
src/pk/dsa/dsa_verify_hash.o src/pk/dsa/dsa_verify_key.o src/pk/ecc/ecc.o \
|
||||
src/pk/ecc/ecc_ansi_x963_export.o src/pk/ecc/ecc_ansi_x963_import.o src/pk/ecc/ecc_decrypt_key.o \
|
||||
src/pk/ecc/ecc_encrypt_key.o src/pk/ecc/ecc_export.o src/pk/ecc/ecc_free.o src/pk/ecc/ecc_get_size.o \
|
||||
src/pk/ecc/ecc_import.o src/pk/ecc/ecc_make_key.o src/pk/ecc/ecc_shared_secret.o \
|
||||
src/pk/ecc/ecc_sign_hash.o src/pk/ecc/ecc_sizes.o src/pk/ecc/ecc_test.o src/pk/ecc/ecc_verify_hash.o \
|
||||
src/pk/asn1/der/short_integer/der_length_short_integer.o \
|
||||
src/pk/asn1/der/teletex_string/der_decode_teletex_string.o \
|
||||
src/pk/asn1/der/teletex_string/der_length_teletex_string.o \
|
||||
src/pk/asn1/der/utctime/der_decode_utctime.o src/pk/asn1/der/utctime/der_encode_utctime.o \
|
||||
src/pk/asn1/der/utctime/der_length_utctime.o src/pk/asn1/der/utf8/der_decode_utf8_string.o \
|
||||
src/pk/asn1/der/utf8/der_encode_utf8_string.o src/pk/asn1/der/utf8/der_length_utf8_string.o \
|
||||
src/pk/dh/dh.o src/pk/dh/dh_check_pubkey.o src/pk/dh/dh_export.o src/pk/dh/dh_export_key.o \
|
||||
src/pk/dh/dh_free.o src/pk/dh/dh_generate_key.o src/pk/dh/dh_import.o src/pk/dh/dh_set.o \
|
||||
src/pk/dh/dh_set_pg_dhparam.o src/pk/dh/dh_shared_secret.o src/pk/dsa/dsa_decrypt_key.o \
|
||||
src/pk/dsa/dsa_encrypt_key.o src/pk/dsa/dsa_export.o src/pk/dsa/dsa_free.o \
|
||||
src/pk/dsa/dsa_generate_key.o src/pk/dsa/dsa_generate_pqg.o src/pk/dsa/dsa_import.o \
|
||||
src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_set.o src/pk/dsa/dsa_set_pqg_dsaparam.o \
|
||||
src/pk/dsa/dsa_shared_secret.o src/pk/dsa/dsa_sign_hash.o src/pk/dsa/dsa_verify_hash.o \
|
||||
src/pk/dsa/dsa_verify_key.o src/pk/ecc/ecc.o src/pk/ecc/ecc_ansi_x963_export.o \
|
||||
src/pk/ecc/ecc_ansi_x963_import.o src/pk/ecc/ecc_decrypt_key.o src/pk/ecc/ecc_encrypt_key.o \
|
||||
src/pk/ecc/ecc_export.o src/pk/ecc/ecc_free.o src/pk/ecc/ecc_get_size.o src/pk/ecc/ecc_import.o \
|
||||
src/pk/ecc/ecc_make_key.o src/pk/ecc/ecc_shared_secret.o src/pk/ecc/ecc_sign_hash.o \
|
||||
src/pk/ecc/ecc_sizes.o src/pk/ecc/ecc_test.o src/pk/ecc/ecc_verify_hash.o \
|
||||
src/pk/ecc/ltc_ecc_is_valid_idx.o src/pk/ecc/ltc_ecc_map.o src/pk/ecc/ltc_ecc_mul2add.o \
|
||||
src/pk/ecc/ltc_ecc_mulmod.o src/pk/ecc/ltc_ecc_mulmod_timing.o src/pk/ecc/ltc_ecc_points.o \
|
||||
src/pk/ecc/ltc_ecc_projective_add_point.o src/pk/ecc/ltc_ecc_projective_dbl_point.o \
|
||||
@@ -200,164 +195,105 @@ src/pk/katja/katja_make_key.o src/pk/pkcs1/pkcs_1_i2osp.o src/pk/pkcs1/pkcs_1_mg
|
||||
src/pk/pkcs1/pkcs_1_oaep_decode.o src/pk/pkcs1/pkcs_1_oaep_encode.o src/pk/pkcs1/pkcs_1_os2ip.o \
|
||||
src/pk/pkcs1/pkcs_1_pss_decode.o src/pk/pkcs1/pkcs_1_pss_encode.o src/pk/pkcs1/pkcs_1_v1_5_decode.o \
|
||||
src/pk/pkcs1/pkcs_1_v1_5_encode.o src/pk/rsa/rsa_decrypt_key.o src/pk/rsa/rsa_encrypt_key.o \
|
||||
src/pk/rsa/rsa_export.o src/pk/rsa/rsa_exptmod.o src/pk/rsa/rsa_free.o src/pk/rsa/rsa_import.o \
|
||||
src/pk/rsa/rsa_make_key.o src/pk/rsa/rsa_sign_hash.o src/pk/rsa/rsa_verify_hash.o src/prngs/fortuna.o \
|
||||
src/pk/rsa/rsa_export.o src/pk/rsa/rsa_exptmod.o src/pk/rsa/rsa_free.o src/pk/rsa/rsa_get_size.o \
|
||||
src/pk/rsa/rsa_import.o src/pk/rsa/rsa_import_pkcs8.o src/pk/rsa/rsa_import_x509.o \
|
||||
src/pk/rsa/rsa_make_key.o src/pk/rsa/rsa_set.o src/pk/rsa/rsa_sign_hash.o \
|
||||
src/pk/rsa/rsa_sign_saltlen_get.o src/pk/rsa/rsa_verify_hash.o src/prngs/chacha20.o src/prngs/fortuna.o \
|
||||
src/prngs/rc4.o src/prngs/rng_get_bytes.o src/prngs/rng_make_prng.o src/prngs/sober128.o \
|
||||
src/prngs/sprng.o src/prngs/yarrow.o
|
||||
src/prngs/sprng.o src/prngs/yarrow.o src/stream/chacha/chacha_crypt.o src/stream/chacha/chacha_done.o \
|
||||
src/stream/chacha/chacha_ivctr32.o src/stream/chacha/chacha_ivctr64.o \
|
||||
src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_setup.o src/stream/chacha/chacha_test.o \
|
||||
src/stream/rc4/rc4_stream.o src/stream/rc4/rc4_test.o src/stream/sober128/sober128_stream.o \
|
||||
src/stream/sober128/sober128_test.o
|
||||
|
||||
HEADERS=src/headers/tomcrypt_cfg.h src/headers/tomcrypt_mac.h src/headers/tomcrypt_macros.h \
|
||||
src/headers/tomcrypt_custom.h src/headers/tomcrypt_argchk.h src/headers/tomcrypt_cipher.h \
|
||||
src/headers/tomcrypt_pk.h src/headers/tomcrypt_hash.h src/headers/tomcrypt_math.h \
|
||||
src/headers/tomcrypt_misc.h src/headers/tomcrypt.h src/headers/tomcrypt_pkcs.h \
|
||||
src/headers/tomcrypt_prng.h testprof/tomcrypt_test.h
|
||||
#List of test objects to compile (all goes to libtomcrypt_prof.a)
|
||||
TOBJECTS=tests/base64_test.o tests/cipher_hash_test.o tests/common.o tests/der_test.o tests/dh_test.o \
|
||||
tests/dsa_test.o tests/ecc_test.o tests/file_test.o tests/katja_test.o tests/mac_test.o tests/misc_test.o \
|
||||
tests/modes_test.o tests/mpi_test.o tests/multi_test.o tests/no_prng.o tests/pkcs_1_eme_test.o \
|
||||
tests/pkcs_1_emsa_test.o tests/pkcs_1_oaep_test.o tests/pkcs_1_pss_test.o tests/pkcs_1_test.o \
|
||||
tests/prng_test.o tests/rotate_test.o tests/rsa_test.o tests/store_test.o tests/test.o
|
||||
|
||||
#END_INS
|
||||
#The following headers will be installed by "make install"
|
||||
HEADERS=src/headers/tomcrypt.h src/headers/tomcrypt_argchk.h src/headers/tomcrypt_cfg.h \
|
||||
src/headers/tomcrypt_cipher.h src/headers/tomcrypt_custom.h src/headers/tomcrypt_hash.h \
|
||||
src/headers/tomcrypt_mac.h src/headers/tomcrypt_macros.h src/headers/tomcrypt_math.h \
|
||||
src/headers/tomcrypt_misc.h src/headers/tomcrypt_pk.h src/headers/tomcrypt_pkcs.h \
|
||||
src/headers/tomcrypt_prng.h
|
||||
|
||||
TESTOBJECTS=demos/test.o
|
||||
HASHOBJECTS=demos/hashsum.o
|
||||
CRYPTOBJECTS=demos/encrypt.o
|
||||
SMALLOBJECTS=demos/small.o
|
||||
TVS=demos/tv_gen.o
|
||||
MULTIS=demos/multi.o
|
||||
TIMINGS=demos/timing.o
|
||||
TESTS=demos/test.o
|
||||
#The default rule for make builds the libtomcrypt.a library (static)
|
||||
default: $(LIBMAIN_S)
|
||||
|
||||
#Files left over from making the crypt.pdf.
|
||||
LEFTOVERS=*.dvi *.log *.aux *.toc *.idx *.ilg *.ind *.out
|
||||
#SPECIAL: AES comes in two flavours - enc+dec and enc-only
|
||||
src/ciphers/aes/aes_enc.o: $(srcdir)/src/ciphers/aes/aes.c $(srcdir)/src/ciphers/aes/aes_tab.c
|
||||
$(CC) $(LTC_CFLAGS) -DENCRYPT_ONLY -c $(srcdir)/src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
|
||||
|
||||
#Compressed filenames
|
||||
COMPRESSED=crypt-$(VERSION).tar.bz2 crypt-$(VERSION).zip
|
||||
#SPECIAL: these are the rules to make certain object files
|
||||
src/ciphers/aes/aes.o: $(srcdir)/src/ciphers/aes/aes.c $(srcdir)/src/ciphers/aes/aes_tab.c
|
||||
src/ciphers/twofish/twofish.o: $(srcdir)/src/ciphers/twofish/twofish.c $(srcdir)/src/ciphers/twofish/twofish_tab.c
|
||||
src/hashes/whirl/whirl.o: $(srcdir)/src/hashes/whirl/whirl.c $(srcdir)/src/hashes/whirl/whirltab.c
|
||||
src/hashes/sha2/sha512.o: $(srcdir)/src/hashes/sha2/sha512.c $(srcdir)/src/hashes/sha2/sha384.c
|
||||
src/hashes/sha2/sha512_224.o: $(srcdir)/src/hashes/sha2/sha512.c $(srcdir)/src/hashes/sha2/sha512_224.c
|
||||
src/hashes/sha2/sha512_256.o: $(srcdir)/src/hashes/sha2/sha512.c $(srcdir)/src/hashes/sha2/sha512_256.c
|
||||
src/hashes/sha2/sha256.o: $(srcdir)/src/hashes/sha2/sha256.c $(srcdir)/src/hashes/sha2/sha224.c
|
||||
|
||||
#The default rule for make builds the libtomcrypt library.
|
||||
default:library
|
||||
#Dependencies on *.h
|
||||
$(OBJECTS): $(HEADERS)
|
||||
$(TOBJECTS): $(HEADERS) tests/tomcrypt_test.h
|
||||
|
||||
#ciphers come in two flavours... enc+dec and enc
|
||||
src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
|
||||
$(CC) $(CFLAGS) -DENCRYPT_ONLY -c $< -o src/ciphers/aes/aes_enc.o
|
||||
#This is necessary for compatibility with BSD make (namely on OpenBSD)
|
||||
.SUFFIXES: .o .c
|
||||
.c.o:
|
||||
$(CC) $(LTC_CFLAGS) -c $< -o $@
|
||||
|
||||
#These are the rules to make certain object files.
|
||||
src/ciphers/aes/aes.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
|
||||
src/ciphers/twofish/twofish.o: src/ciphers/twofish/twofish.c src/ciphers/twofish/twofish_tab.c
|
||||
src/hashes/whirl/whirl.o: src/hashes/whirl/whirl.c src/hashes/whirl/whirltab.c
|
||||
src/hashes/sha2/sha512.o: src/hashes/sha2/sha512.c src/hashes/sha2/sha384.c
|
||||
src/hashes/sha2/sha256.o: src/hashes/sha2/sha256.c src/hashes/sha2/sha224.c
|
||||
|
||||
#This rule makes the libtomcrypt library.
|
||||
library: $(LIBNAME)
|
||||
|
||||
testprof/$(LIBTEST):
|
||||
cd testprof ; CFLAGS="$(CFLAGS)" LIBTEST_S=$(LIBTEST_S) $(MAKE)
|
||||
|
||||
$(LIBNAME): $(OBJECTS)
|
||||
$(AR) $(ARFLAGS) $@ $(OBJECTS)
|
||||
#Create libtomcrypt.a
|
||||
$(LIBMAIN_S): $(OBJECTS)
|
||||
$(AR) $(ARFLAGS) $@ $(OBJECTS)
|
||||
$(RANLIB) $@
|
||||
|
||||
#This rule makes the hash program included with libtomcrypt
|
||||
hashsum: library $(HASHOBJECTS)
|
||||
$(CC) $(HASHOBJECTS) $(LIBNAME) $(EXTRALIBS) -o $(HASH) $(WARN)
|
||||
#Demo tools/utilities
|
||||
hashsum: demos/hashsum.o $(LIBMAIN_S)
|
||||
$(CC) demos/hashsum.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
|
||||
ltcrypt: demos/ltcrypt.o $(LIBMAIN_S)
|
||||
$(CC) demos/ltcrypt.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
|
||||
small: demos/small.o $(LIBMAIN_S)
|
||||
$(CC) demos/small.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
|
||||
tv_gen: demos/tv_gen.o $(LIBMAIN_S)
|
||||
$(CC) demos/tv_gen.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
|
||||
sizes: demos/sizes.o $(LIBMAIN_S)
|
||||
$(CC) demos/sizes.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
|
||||
constants: demos/constants.o $(LIBMAIN_S)
|
||||
$(CC) demos/constants.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
|
||||
timing: demos/timing.o $(LIBMAIN_S)
|
||||
$(CC) demos/timing.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
|
||||
|
||||
#makes the crypt program
|
||||
crypt: library $(CRYPTOBJECTS)
|
||||
$(CC) $(CRYPTOBJECTS) $(LIBNAME) $(EXTRALIBS) -o $(CRYPT) $(WARN)
|
||||
#Tests
|
||||
test: $(TOBJECTS) $(LIBMAIN_S)
|
||||
$(CC) $(TOBJECTS) $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
|
||||
@echo "NOTICE: start the tests by: ./test"
|
||||
|
||||
#makes the small program
|
||||
small: library $(SMALLOBJECTS)
|
||||
$(CC) $(SMALLOBJECTS) $(LIBNAME) $(EXTRALIBS) -o $(SMALL) $(WARN)
|
||||
|
||||
tv_gen: library $(TVS)
|
||||
$(CC) $(LDFLAGS) $(TVS) $(LIBNAME) $(EXTRALIBS) -o $(TV)
|
||||
all: $(LIBMAIN_S) hashsum ltcrypt small tv_gen sizes constants timing test
|
||||
|
||||
multi: library $(MULTIS)
|
||||
$(CC) $(MULTIS) $(LIBNAME) $(EXTRALIBS) -o $(MULTI)
|
||||
|
||||
timing: library testprof/$(LIBTEST) $(TIMINGS)
|
||||
$(CC) $(LDFLAGS) $(TIMINGS) testprof/$(LIBTEST) $(LIBNAME) $(EXTRALIBS) -o $(TIMING)
|
||||
|
||||
test: library testprof/$(LIBTEST) $(TESTS)
|
||||
$(CC) $(LDFLAGS) $(TESTS) testprof/$(LIBTEST) $(LIBNAME) $(EXTRALIBS) -o $(TEST)
|
||||
|
||||
#This rule installs the library and the header files. This must be run
|
||||
#as root in order to have a high enough permission to write to the correct
|
||||
#directories and to set the owner and group to root.
|
||||
ifndef NODOCS
|
||||
install: library docs
|
||||
else
|
||||
install: library
|
||||
endif
|
||||
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH)
|
||||
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
|
||||
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(DATAPATH)
|
||||
install -g $(GROUP) -o $(USER) $(LIBNAME) $(DESTDIR)$(LIBPATH)
|
||||
install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
|
||||
ifndef NODOCS
|
||||
install -g $(GROUP) -o $(USER) doc/crypt.pdf $(DESTDIR)$(DATAPATH)
|
||||
endif
|
||||
|
||||
install_test: testprof/$(LIBTEST)
|
||||
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH)
|
||||
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
|
||||
install -g $(GROUP) -o $(USER) testprof/$(LIBTEST) $(DESTDIR)$(LIBPATH)
|
||||
|
||||
profile:
|
||||
CFLAGS="$(CFLAGS) -fprofile-generate" $(MAKE) timing EXTRALIBS="$(EXTRALIBS) -lgcov"
|
||||
./timing
|
||||
rm -f timing `find . -type f | grep [.][ao] | xargs`
|
||||
CFLAGS="$(CFLAGS) -fprofile-use" $(MAKE) timing EXTRALIBS="$(EXTRALIBS) -lgcov"
|
||||
|
||||
|
||||
#This rule cleans the source tree of all compiled code, not including the pdf
|
||||
#documentation.
|
||||
#NOTE: this makefile works also on cygwin, thus we need to delete *.exe
|
||||
clean:
|
||||
-rm -f $(OBJECTS)
|
||||
-rm -f libtomcrypt.a
|
||||
-@rm -f $(OBJECTS) $(TOBJECTS)
|
||||
-@rm -f $(LIBMAIN_S)
|
||||
-@rm -f demos/*.o *_tv.txt
|
||||
-@rm -f test constants sizes tv_gen hashsum ltcrypt small timing
|
||||
-@rm -f test.exe constants.exe sizes.exe tv_gen.exe hashsum.exe ltcrypt.exe small.exe timing.exe
|
||||
|
||||
#build the doxy files (requires Doxygen, tetex and patience)
|
||||
doxy:
|
||||
doxygen
|
||||
cd doc/doxygen/latex ; ${MAKE} ; mv -f refman.pdf ../../.
|
||||
echo The huge doxygen PDF should be available as doc/refman.pdf
|
||||
|
||||
#This builds the crypt.pdf file. Note that the rm -f *.pdf has been removed
|
||||
#from the clean command! This is because most people would like to keep the
|
||||
#nice pre-compiled crypt.pdf that comes with libtomcrypt! We only need to
|
||||
#delete it if we are rebuilding it.
|
||||
docs: crypt.tex
|
||||
rm -f doc/crypt.pdf $(LEFTOVERS)
|
||||
echo "hello" > crypt.ind
|
||||
latex crypt > /dev/null
|
||||
latex crypt > /dev/null
|
||||
makeindex crypt.idx > /dev/null
|
||||
perl fixupind.pl
|
||||
latex crypt > /dev/null
|
||||
dvipdf crypt
|
||||
mv -ivf crypt.pdf doc/crypt.pdf
|
||||
rm -f $(LEFTOVERS)
|
||||
#Install the library + headers
|
||||
install: $(LIBMAIN_S) $(HEADERS)
|
||||
@mkdir -p $(DESTDIR)$(INCPATH) $(DESTDIR)$(LIBPATH)/pkgconfig
|
||||
@cp $(LIBMAIN_S) $(DESTDIR)$(LIBPATH)/
|
||||
@cp $(HEADERS) $(DESTDIR)$(INCPATH)/
|
||||
@sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION),' libtomcrypt.pc.in > $(DESTDIR)$(LIBPATH)/pkgconfig/libtomcrypt.pc
|
||||
|
||||
docdvi: crypt.tex
|
||||
echo hello > crypt.ind
|
||||
latex crypt > /dev/null
|
||||
latex crypt > /dev/null
|
||||
makeindex crypt.idx
|
||||
perl fixupind.pl
|
||||
latex crypt > /dev/null
|
||||
latex crypt > /dev/null
|
||||
#Install useful tools
|
||||
install_bins: hashsum
|
||||
@mkdir -p $(DESTDIR)$(BINPATH)
|
||||
@cp hashsum $(DESTDIR)$(BINPATH)/
|
||||
|
||||
#zipup the project (take that!)
|
||||
no_oops: clean
|
||||
cd .. ; cvs commit
|
||||
echo Scanning for scratch/dirty files
|
||||
find . -type f | grep -v CVS | xargs -n 1 bash mess.sh
|
||||
|
||||
zipup: no_oops docs
|
||||
cd .. ; rm -rf crypt* libtomcrypt-$(VERSION) ; mkdir libtomcrypt-$(VERSION) ; \
|
||||
cp -R ./libtomcrypt/* ./libtomcrypt-$(VERSION)/ ; \
|
||||
cd libtomcrypt-$(VERSION) ; rm -rf `find . -type d | grep CVS | xargs` ; cd .. ; \
|
||||
tar -cjvf crypt-$(VERSION).tar.bz2 libtomcrypt-$(VERSION) ; \
|
||||
zip -9r crypt-$(VERSION).zip libtomcrypt-$(VERSION) ; \
|
||||
gpg -b -a crypt-$(VERSION).tar.bz2 ; gpg -b -a crypt-$(VERSION).zip ; \
|
||||
mv -fv crypt* ~ ; rm -rf libtomcrypt-$(VERSION)
|
||||
|
||||
|
||||
# $Source: /cvs/libtom/libtomcrypt/makefile,v $
|
||||
# $Revision: 1.145 $
|
||||
# $Date: 2006/12/02 19:23:21 $
|
||||
#Install documentation
|
||||
install_docs: doc/crypt.pdf
|
||||
@mkdir -p $(DESTDIR)$(DATAPATH)
|
||||
@cp doc/crypt.pdf $(DESTDIR)$(DATAPATH)/
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
stopped at ch12
|
||||
-- needs examples for ecc/dsa!!! (and for asn.1)
|
||||
|
||||
must have for v1.16
|
||||
- document PK build flags
|
||||
- document makefile flags [INSTALL_* for instance]
|
||||
- prepare manual for printing (both soft and hard cover)
|
||||
|
||||
Nice to have [in order of precedence]
|
||||
- add X9.63 IES
|
||||
- add CPP macros like OpenSSL has for ASN1 (e.g. encode/decode functions, etc) shameless ripoff :-)
|
||||
for 1.18
|
||||
- document new ECC functions
|
||||
- add test for new functions
|
||||
|
||||
51
libtomcrypt/build.sh
Normal file → Executable file
51
libtomcrypt/build.sh
Normal file → Executable file
@@ -1,20 +1,59 @@
|
||||
#!/bin/bash
|
||||
echo "$1 ($2, $3)..."
|
||||
|
||||
make clean 1>/dev/null 2>/dev/null
|
||||
|
||||
echo -n "building..."
|
||||
CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5" make -j4 -f $3 test tv_gen 1>gcc_1.txt 2>gcc_2.txt || (echo "build $1 failed see gcc_2.txt for more information" && cat gcc_2.txt && exit 1)
|
||||
|
||||
if [ -f /proc/cpuinfo ]
|
||||
then
|
||||
MAKE_JOBS=$(( ($(cat /proc/cpuinfo | grep -E '^processor[[:space:]]*:' | tail -n -1 | cut -d':' -f2) + 1) * 2 + 1 ))
|
||||
else
|
||||
MAKE_JOBS=8
|
||||
fi
|
||||
|
||||
CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5" make -j$MAKE_JOBS -f $3 all_test 1>gcc_1.txt 2>gcc_2.txt
|
||||
mret=$?
|
||||
cnt=$(wc -l < gcc_2.txt)
|
||||
# ignore 1 line since ar prints to stderr instead of stdout and ar is called for
|
||||
# $(LIBNAME)
|
||||
if [[ $mret -ne 0 ]] || [[ $cnt -gt 1 ]]; then
|
||||
echo "build $1 failed! printing gcc_2.txt now for convenience"
|
||||
cat gcc_2.txt
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -n "testing..."
|
||||
|
||||
if [ -a test ] && [ -f test ] && [ -x test ]; then
|
||||
((./test >test_std.txt 2>test_err.txt && ./tv_gen > tv.txt) && echo "$1 test passed." && echo "y" > testok.txt) || (echo "$1 test failed" && cat test_err.txt && exit 1)
|
||||
((./test >test_std.txt 2>test_err.txt && ./tv_gen > tv.txt) && echo "$1 test passed." && echo "y" > testok.txt) || (echo "$1 test failed, look at test_err.txt or tv.txt" && exit 1)
|
||||
if find *_tv.txt -type f 1>/dev/null 2>/dev/null ; then
|
||||
for f in *_tv.txt; do if (diff --ignore-case $f notes/$f) then true; else (echo "tv_gen $f failed" && rm -f testok.txt && exit 1); fi; done
|
||||
for f in *_tv.txt; do
|
||||
# check for lines starting with '<' ($f might be a subset of notes/$f)
|
||||
difftroubles=$(diff -i -w -B $f notes/$f | grep '^<')
|
||||
if [ -n "$difftroubles" ]; then
|
||||
echo "FAILURE: $f"
|
||||
diff -i -w -B $f notes/$f
|
||||
echo "tv_gen $f failed" && rm -f testok.txt && exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [ -a testok.txt ] && [ -f testok.txt ]; then
|
||||
if [ "$LTC_COVERAGE" != "" ]; then
|
||||
./coverage_more.sh > test_coverage_more.txt || exit 1
|
||||
lcov_opts="--capture --no-external --directory src -q"
|
||||
lcov_out=$(echo coverage_$1_$2_$3 | tr ' -=+' '_')".info"
|
||||
lcov $lcov_opts --output-file $lcov_out
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
exit 1
|
||||
|
||||
# $Source: /cvs/libtom/libtomcrypt/build.sh,v $
|
||||
# $Revision: 1.9 $
|
||||
# $Date: 2006/03/18 14:10:55 $
|
||||
# ref: $Format:%D$
|
||||
# git commit: $Format:%H$
|
||||
# commit time: $Format:%ai$
|
||||
|
||||
@@ -1,3 +1,82 @@
|
||||
January 22nd, 2018
|
||||
v1.18.1
|
||||
-- Fix wrong SHA3 blocksizes, thanks to Claus Fischer for reporting this via Mail (PR #329)
|
||||
-- Fix NULL-pointer dereference in `ccm_memory()` with LTC_CLEAN_STACK enabled (PR #327)
|
||||
-- Fix `ccm_process()` being unable to process input buffers longer than 256 bytes (PR #326)
|
||||
-- Fix the `register_all_{ciphers,hashes,prngs}()` return values (PR #316)
|
||||
-- Fix some typos, warnings and duplicate prototypes in code & doc (PR's #310 #320 #321 #335)
|
||||
-- Fix possible undefined behavior with LTC_PTHREAD (PR #337)
|
||||
-- Fix some DER bugs (PR #339)
|
||||
-- Fix CTR-mode when accelerator is used (OP-TEE/optee_os #2086)
|
||||
-- Fix installation procedure (Issue #340)
|
||||
|
||||
October 10th, 2017
|
||||
v1.18.0
|
||||
-- Bugfix multi2
|
||||
-- Bugfix Noekeon
|
||||
-- Bugfix XTEA
|
||||
-- Bugfix rng_get_bytes() on windows where we could read from c:\dev\random
|
||||
-- Fixed the Bleichbacher Signature attack in PKCS#1 v1.5 EMSA, thanks to Alex Dent
|
||||
-- Fixed a potential cache-based timing attack in CCM, thanks to Sebastian Verschoor
|
||||
-- Fix GCM counter reuse and potential timing attacks in EAX, OCB and OCBv3,
|
||||
thanks to Raphaël Jamet
|
||||
-- Implement hardened RSA operations when CRT is used
|
||||
-- Enabled timing resistant calculations of ECC and RSA operations per default
|
||||
-- Applied some patches from the OLPC project regarding PKCS#1 and preventing
|
||||
the hash algorithms from overflowing
|
||||
-- Larry Bugbee contributed the necessary stuff to more easily call libtomcrypt
|
||||
from a dynamic language like Python, as shown in his pyTomCrypt
|
||||
-- Nikos Mavrogiannopoulos contributed RSA blinding and export of RSA and DSA keys
|
||||
in OpenSSL/GnuTLS compatible format
|
||||
-- Patrick Pelletier contributed a smart volley of patches
|
||||
-- Christopher Brown contributed some patches and additions to ASN.1/DER
|
||||
-- Pascal Brand of STMicroelectronics contributed patches regarding CCM, the
|
||||
XTS mode and RSA private key operations with keys without CRT parameters
|
||||
-- RC2 now also works with smaller key-sizes
|
||||
-- Improved/extended several tests & demos
|
||||
-- Hardened DSA and RSA by testing (through Karel's perl-CryptX)
|
||||
against Google's "Wycheproof" and Kudelski Security's "CDF"
|
||||
-- Fixed all compiler warnings
|
||||
-- Fixed several build issues on FreeBSD, NetBSD, Linux x32 ABI, HP-UX/IA64,
|
||||
Mac OS X, Windows (32&64bit, Cygwin, MingW & MSVC) ...
|
||||
-- Re-worked all makefiles
|
||||
-- Re-worked most PRNG's
|
||||
-- The code is now verified by a linter, thanks to Francois Perrad
|
||||
-- Documentation (crypt.pdf) is now built deterministically, thanks to Michael Stapelberg
|
||||
-- Add Adler32 and CRC32 checksum algorithms
|
||||
-- Add Base64-URL de-/encoding and some strict variants
|
||||
-- Add Blake2b & Blake2s (hash & mac), thanks to Kelvin Sherlock
|
||||
-- Add Camellia block cipher
|
||||
-- Add ChaCha (stream cipher), Poly1305 (mac), ChaCha20Poly1305 (encauth)
|
||||
-- Add constant-time mem-compare mem_neq()
|
||||
-- Add DER GeneralizedTime de-/encoding
|
||||
-- Add DSA and ECC key generation FIPS-186-4 compliance
|
||||
-- Add HKDF, thanks to RyanC (especially for also providing documentation :-) )
|
||||
-- Add OCBv3
|
||||
-- Add PKCS#1 v1.5 mode of SSL3.0
|
||||
-- Add PKCS#1 testvectors from RSA
|
||||
-- Add PKCS#8 & X.509 import for RSA keys
|
||||
-- Add stream cipher API
|
||||
-- Add SHA3 & SHAKE
|
||||
-- Add SHA512/256 and SHA512/224
|
||||
-- Add Triple-DES 2-key mode, thanks to Paul Howarth
|
||||
-- Brought back Diffie-Hellman
|
||||
|
||||
May 12th, 2007
|
||||
v1.17 -- Cryptography Research Inc. contributed another small volley of patches, one to fix __WCHAR_DEFINED__ for BSD platforms,
|
||||
another to silence MSVC warnings.
|
||||
-- Added LTC_XCBC_PURE to XCBC mode which lets you use it in three-key mode.
|
||||
-- [CRI] Added libtomcrypt.dsp for Visual C++ users.
|
||||
-- [CRI] Added more functions for manipulating the ECC fixed point cache (including saving and loading)
|
||||
-- [CRI] Modified ecc_make_key() to always produce keys smaller than base point order, for standards-compliance
|
||||
-- Elliptic Semiconductor contributed XTS chaining mode to the cipher suite (subsequently optimized it)
|
||||
-- Fixed xcbc_init() keylen when using single key mode.
|
||||
-- Bruce Fortune pointed out a typo in the hmac_process() description in the manual. Fixed.
|
||||
-- Added variable width counter support to CTR mode
|
||||
-- Fixed CMAC (aka OMAC) when using 64-bit block ciphers and LTC_FAST ... my bad.
|
||||
-- Fixed bug in ecc_is_valid() that would basically always return true
|
||||
-- renamed a lot of macros to add the LTC_ prefix [e.g. RIJNDAEL => LTC_RIJNDAEL]
|
||||
|
||||
December 16th, 2006
|
||||
v1.16 -- Brian Gladman pointed out that a recent change to GCM broke how the IV was handled. Currently the code complies against his test vectors
|
||||
so the code should be considered frozen now.
|
||||
@@ -1551,6 +1630,6 @@ v0.02 -- Changed RC5 to only allow 12 to 24 rounds
|
||||
v0.01 -- We will call this the first version.
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/changes,v $ */
|
||||
/* $Revision: 1.274 $ */
|
||||
/* $Date: 2006/12/16 19:08:17 $ */
|
||||
/* $Revision: 1.288 $ */
|
||||
/* $Date: 2007/05/12 14:37:41 $ */
|
||||
|
||||
|
||||
15
libtomcrypt/check_source.sh
Executable file
15
libtomcrypt/check_source.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
# output version
|
||||
bash printinfo.sh
|
||||
|
||||
make clean > /dev/null
|
||||
|
||||
echo "checking..."
|
||||
./helper.pl --check-source --check-makefiles --check-defines|| exit 1
|
||||
|
||||
exit 0
|
||||
|
||||
# ref: $Format:%D$
|
||||
# git commit: $Format:%H$
|
||||
# commit time: $Format:%ai$
|
||||
51
libtomcrypt/coverage.sh
Executable file
51
libtomcrypt/coverage.sh
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$TRAVIS_CI" == "private" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$#" != "5" ]; then
|
||||
echo "Usage is: ${0} \"coverage\" \"<prepend CFLAGS>\" \"<makefile>\" \"<append CFLAGS>\" <math library to link to>"
|
||||
echo "CC=gcc ${0} \"coverage\" \" \" \"makefile\" \"-DUSE_LTM -DLTM_DESC -I../libtommath\" ../libtommath/libtommath.a"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
if [ -z "$(echo $CC | grep "gcc")" ]; then
|
||||
echo "no gcc detected, early exit success"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$(echo $3 | grep -v 'makefile[.]')" == "" ]; then
|
||||
echo "only run $0 for the regular makefile, early exit success"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# output version
|
||||
bash printinfo.sh
|
||||
|
||||
bash build.sh " $1" " $2" " $3 COVERAGE=1" "$4" "$5"
|
||||
if [ -a testok.txt ] && [ -f testok.txt ]; then
|
||||
echo
|
||||
else
|
||||
echo
|
||||
echo "Test failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
./coverage_more.sh > test_coverage_more.txt || { rm -f testok.txt && exit 1 ; }
|
||||
|
||||
make lcov-single
|
||||
# if this was executed as './coverage.sh ...' create coverage locally
|
||||
if [[ "${0%% *}" == "./${0##*/}" ]]; then
|
||||
make lcov-html
|
||||
else
|
||||
coveralls-lcov coverage.info
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
# ref: $Format:%D$
|
||||
# git commit: $Format:%H$
|
||||
# commit time: $Format:%ai$
|
||||
24
libtomcrypt/coverage_more.sh
Executable file
24
libtomcrypt/coverage_more.sh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
./sizes
|
||||
./constants
|
||||
|
||||
for i in $(for j in $(echo $(./hashsum -h | awk '/Algorithms/,EOF' | tail -n +2)); do echo $j; done | sort); do echo -n "$i: " && ./hashsum -a $i tests/test.key ; done > hashsum_tv.txt
|
||||
difftroubles=$(diff -i -w -B hashsum_tv.txt notes/hashsum_tv.txt | grep '^<') || true
|
||||
if [ -n "$difftroubles" ]; then
|
||||
echo "FAILURE: hashsum_tv.tx"
|
||||
diff -i -w -B hashsum_tv.txt notes/hashsum_tv.txt
|
||||
echo "hashsum failed"
|
||||
exit 1
|
||||
else
|
||||
echo "hashsum okay"
|
||||
fi
|
||||
|
||||
|
||||
exit 0
|
||||
|
||||
# ref: $Format:%D$
|
||||
# git commit: $Format:%H$
|
||||
# commit time: $Format:%ai$
|
||||
40
libtomcrypt/coverity.sh
Executable file
40
libtomcrypt/coverity.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ $# -lt 2 ]
|
||||
then
|
||||
echo "usage is: ${0##*/} <path to coverity scan> <extra compiler options>"
|
||||
echo "e.g. \"${0##*/} \"/usr/local/bin/coverity\" \"-DLTM_DESC -I/path/to/libtommath/\"\""
|
||||
exit -1
|
||||
fi
|
||||
|
||||
PATH=$PATH:$1/bin
|
||||
|
||||
make clean
|
||||
rm -r cov-int/
|
||||
|
||||
myCflags=""
|
||||
myCflags="$myCflags -O2 ${2}"
|
||||
myCflags="$myCflags -pipe -Werror -Wpointer-arith -Winit-self -Wextra -Wall -Wformat -Wformat-security"
|
||||
|
||||
CFLAGS="$myCflags" cov-build --dir cov-int make -f makefile.unix $MAKE_OPTS IGNORE_SPEED=1 1>gcc_1.txt
|
||||
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "make failed"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
# zipup everything
|
||||
tar caf libtomcrypt.lzma cov-int
|
||||
|
||||
mytoken=$(cat .coverity_token)
|
||||
mymail=$(cat .coverity_mail)
|
||||
myversion=$(git describe --dirty)
|
||||
|
||||
curl -k --form project=libtomcrypt \
|
||||
--form token=${mytoken} \
|
||||
--form email=${mymail} \
|
||||
--form file=@libtomcrypt.lzma \
|
||||
--form version=\"${myversion}\" \
|
||||
--form description="\"libtomcrypt version ${myversion}\"" \
|
||||
https://scan.coverity.com/builds?project=libtom%2Flibtomcrypt
|
||||
@@ -6,19 +6,19 @@
|
||||
\contentsline {figure}{\numberline {3.1}{\ignorespaces Built--In Software Ciphers}}{19}{figure.3.1}
|
||||
\contentsline {figure}{\numberline {3.2}{\ignorespaces Twofish Build Options}}{21}{figure.3.2}
|
||||
\addvspace {10\p@ }
|
||||
\contentsline {figure}{\numberline {4.1}{\ignorespaces Built--In Software Hashes}}{57}{figure.4.1}
|
||||
\contentsline {figure}{\numberline {4.1}{\ignorespaces Built--In Software Hashes}}{59}{figure.4.1}
|
||||
\addvspace {10\p@ }
|
||||
\addvspace {10\p@ }
|
||||
\contentsline {figure}{\numberline {6.1}{\ignorespaces List of Provided PRNGs}}{82}{figure.6.1}
|
||||
\contentsline {figure}{\numberline {6.1}{\ignorespaces List of Provided PRNGs}}{84}{figure.6.1}
|
||||
\addvspace {10\p@ }
|
||||
\addvspace {10\p@ }
|
||||
\addvspace {10\p@ }
|
||||
\contentsline {figure}{\numberline {9.1}{\ignorespaces DSA Key Sizes}}{119}{figure.9.1}
|
||||
\contentsline {figure}{\numberline {9.1}{\ignorespaces DSA Key Sizes}}{121}{figure.9.1}
|
||||
\addvspace {10\p@ }
|
||||
\contentsline {figure}{\numberline {10.1}{\ignorespaces List of ASN.1 Supported Types}}{127}{figure.10.1}
|
||||
\contentsline {figure}{\numberline {10.1}{\ignorespaces List of ASN.1 Supported Types}}{129}{figure.10.1}
|
||||
\addvspace {10\p@ }
|
||||
\addvspace {10\p@ }
|
||||
\contentsline {figure}{\numberline {12.1}{\ignorespaces RSA/DH Key Strength}}{149}{figure.12.1}
|
||||
\contentsline {figure}{\numberline {12.2}{\ignorespaces ECC Key Strength}}{149}{figure.12.2}
|
||||
\contentsline {figure}{\numberline {12.1}{\ignorespaces RSA/DH Key Strength}}{151}{figure.12.1}
|
||||
\contentsline {figure}{\numberline {12.2}{\ignorespaces ECC Key Strength}}{151}{figure.12.2}
|
||||
\addvspace {10\p@ }
|
||||
\addvspace {10\p@ }
|
||||
|
||||
86
libtomcrypt/demos/constants.c
Normal file
86
libtomcrypt/demos/constants.c
Normal file
@@ -0,0 +1,86 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L
|
||||
#include <libgen.h>
|
||||
#else
|
||||
#define basename(x) x
|
||||
#endif
|
||||
|
||||
/**
|
||||
@file demo_crypt_constants.c
|
||||
|
||||
Demo how to get various constants to dynamic languages
|
||||
like Python
|
||||
|
||||
Larry Bugbee, February 2013
|
||||
*/
|
||||
|
||||
static void _print_line(const char* cmd, const char* desc)
|
||||
{
|
||||
printf(" %-16s - %s\n", cmd, desc);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc == 1) {
|
||||
/* given a specific constant name, get and print its value */
|
||||
char name[] = "CTR_COUNTER_BIG_ENDIAN";
|
||||
int value;
|
||||
char *names_list;
|
||||
unsigned int names_list_len;
|
||||
|
||||
if (crypt_get_constant(name, &value) != 0) exit(EXIT_FAILURE);
|
||||
printf("\n %s is %d \n\n", name, value);
|
||||
|
||||
/* get and print the length of the names (and values) list */
|
||||
|
||||
if (crypt_list_all_constants(NULL, &names_list_len) != 0) exit(EXIT_FAILURE);
|
||||
printf(" need to allocate %u bytes \n\n", names_list_len);
|
||||
|
||||
/* get and print the names (and values) list */
|
||||
if ((names_list = malloc(names_list_len)) == NULL) exit(EXIT_FAILURE);
|
||||
if (crypt_list_all_constants(names_list, &names_list_len) != 0) exit(EXIT_FAILURE);
|
||||
printf(" supported constants:\n\n%s\n\n", names_list);
|
||||
free(names_list);
|
||||
} else if (argc == 2) {
|
||||
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
|
||||
char* base = strdup(basename(argv[0]));
|
||||
printf("Usage: %s [-a] [-s name]\n\n", base);
|
||||
_print_line("<no argument>", "The old behavior of the demo");
|
||||
_print_line("-a", "Only lists all constants");
|
||||
_print_line("-s name", "List a single constant given as argument");
|
||||
_print_line("-h", "The help you're looking at");
|
||||
free(base);
|
||||
} else if (strcmp(argv[1], "-a") == 0) {
|
||||
char *names_list;
|
||||
unsigned int names_list_len;
|
||||
/* get and print the length of the names (and values) list */
|
||||
if (crypt_list_all_constants(NULL, &names_list_len) != 0) exit(EXIT_FAILURE);
|
||||
/* get and print the names (and values) list */
|
||||
names_list = malloc(names_list_len);
|
||||
if (crypt_list_all_constants(names_list, &names_list_len) != 0) exit(EXIT_FAILURE);
|
||||
printf("%s\n", names_list);
|
||||
}
|
||||
} else if (argc == 3) {
|
||||
if (strcmp(argv[1], "-s") == 0) {
|
||||
int value;
|
||||
if (crypt_get_constant(argv[2], &value) != 0) exit(EXIT_FAILURE);
|
||||
printf("%s,%u\n", argv[2], value);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
309
libtomcrypt/demos/demo_dynamic.py
Normal file
309
libtomcrypt/demos/demo_dynamic.py
Normal file
@@ -0,0 +1,309 @@
|
||||
|
||||
|
||||
"""
|
||||
demo_dynamic.py v2b
|
||||
|
||||
This program demonstrates Python's use of the dynamic
|
||||
language support additions to LTC, namely access to LTC
|
||||
constants, struct and union sizes, and the binding of a
|
||||
math package to LTC. Also provided are simple code
|
||||
fragments to illustrate how one might write a Python
|
||||
wrapper for LTC and how an app might call the wrapper.
|
||||
This or a similar model should work for Ruby and other
|
||||
dynamic languages.
|
||||
|
||||
This instance uses Python's ctypes and requires a single
|
||||
.dylib linking together LTC and a math library. Building
|
||||
a single .dylib is needed because LTC wants a fairly tight
|
||||
relationship between itself and the mathlib. (ctypes can
|
||||
load multiple .dylibs, but it does not support this level
|
||||
of tight coupling between otherwise independent libraries.)
|
||||
|
||||
My .dylib was created on OSX/macOS with the following:
|
||||
sudo make -j5 -f makefile.shared \
|
||||
CFLAGS="-DUSE_TFM -DTFM_DESC -I/usr/local/include" \
|
||||
EXTRALIBS=/usr/local/lib/libtfm.a install
|
||||
|
||||
For python 2.7.12 on Ubuntu Xenial the following worked for
|
||||
me (without MPI support):
|
||||
sudo make -f makefile.shared install PREFIX="/usr"
|
||||
|
||||
Reminder: you don't need to bind in a math library unless
|
||||
you are going to use LTC functions that need a
|
||||
mathlib. For example, public key crypto requires
|
||||
a mathlib; hashing and symmetric encryption do not.
|
||||
|
||||
------
|
||||
|
||||
This code was originally written for Python 2.7 with the
|
||||
ctypes standard library. This version is modified to run
|
||||
under both Python 2.7 and 3.6.
|
||||
|
||||
Arguably the biggest change for Python3 has to do with
|
||||
strings. Under Python2, native strings are ASCII bytes and
|
||||
passing them to LTC is natural and requires no conversion.
|
||||
Under Python3 all native strings are Unicode which requires
|
||||
they be converted to bytes before use by LTC.
|
||||
|
||||
Note the following for Python3.
|
||||
- ASCII keys, IVs and other string arguments must be
|
||||
'bytes'. Define them with a 'b' prefix or convert
|
||||
via the 'bytes()' function.
|
||||
- "strings" returned from LTC are bytes and conversion
|
||||
to Unicode might be necessary for proper printing.
|
||||
If so, use <string>.decode('utf-8').
|
||||
- The Python2 'print' statement becomes a function in
|
||||
Python3 which requires parenthesis, eg. 'print()'.
|
||||
|
||||
NB: Unicode is achieved under Python2 by either defining
|
||||
a Unicode string with a 'u' prefix or passing ASCII
|
||||
strings thru the 'unicode()' function.
|
||||
|
||||
Larry Bugbee
|
||||
March 2014 v1
|
||||
August 2017 v2b
|
||||
|
||||
"""
|
||||
|
||||
|
||||
import sys
|
||||
from ctypes import *
|
||||
from ctypes.util import find_library
|
||||
|
||||
# switches to enable/disable selected output
|
||||
SHOW_ALL_CONSTANTS = True
|
||||
SHOW_ALL_SIZES = True
|
||||
SHOW_SELECTED_CONSTANTS = True
|
||||
SHOW_SELECTED_SIZES = True
|
||||
SHOW_BUILD_OPTIONS_ALGS = True
|
||||
SHOW_SHA256_EXAMPLE = True
|
||||
SHOW_CHACHA_EXAMPLE = True
|
||||
|
||||
print(' ')
|
||||
print(' demo_dynamic.py')
|
||||
|
||||
def inprint(s, indent=0):
|
||||
"prints strings indented, including multline strings"
|
||||
for line in s.split('\n'):
|
||||
print(' '*indent + line)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# load the .dylib
|
||||
|
||||
libname = 'tomcrypt'
|
||||
libpath = find_library(libname)
|
||||
print(' ')
|
||||
print(' path to library %s: %s' % (libname, libpath))
|
||||
|
||||
LTC = cdll.LoadLibrary(libpath)
|
||||
print(' loaded: %s' % LTC)
|
||||
print(' ')
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# get list of all supported constants followed by a list of all
|
||||
# supported sizes. One alternative: these lists may be parsed
|
||||
# and used as needed.
|
||||
|
||||
if SHOW_ALL_CONSTANTS:
|
||||
print('-'*60)
|
||||
print(' all supported constants and their values:')
|
||||
|
||||
# get size to allocate for constants output list
|
||||
str_len = c_int(0)
|
||||
ret = LTC.crypt_list_all_constants(None, byref(str_len))
|
||||
print(' need to allocate %d bytes to build list \n' % str_len.value)
|
||||
|
||||
# allocate that size and get (name, size) pairs, each pair
|
||||
# separated by a newline char.
|
||||
names_sizes = c_buffer(str_len.value)
|
||||
ret = LTC.crypt_list_all_constants(names_sizes, byref(str_len))
|
||||
print(names_sizes.value.decode("utf-8"))
|
||||
print(' ')
|
||||
|
||||
|
||||
if SHOW_ALL_SIZES:
|
||||
print('-'*60)
|
||||
print(' all supported sizes:')
|
||||
|
||||
# get size to allocate for sizes output list
|
||||
str_len = c_int(0)
|
||||
ret = LTC.crypt_list_all_sizes(None, byref(str_len))
|
||||
print(' need to allocate %d bytes to build list \n' % str_len.value)
|
||||
|
||||
# allocate that size and get (name, size) pairs, each pair
|
||||
# separated by a newline char.
|
||||
names_sizes = c_buffer(str_len.value)
|
||||
ret = LTC.crypt_list_all_sizes(names_sizes, byref(str_len))
|
||||
print(names_sizes.value.decode("utf-8"))
|
||||
print(' ')
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# get individually named constants and sizes
|
||||
|
||||
if SHOW_SELECTED_CONSTANTS:
|
||||
print('-'*60)
|
||||
print('\n selected constants:')
|
||||
|
||||
names = [
|
||||
b'ENDIAN_LITTLE',
|
||||
b'ENDIAN_64BITWORD',
|
||||
b'PK_PUBLIC',
|
||||
b'LTC_MILLER_RABIN_REPS',
|
||||
b'CTR_COUNTER_BIG_ENDIAN',
|
||||
]
|
||||
for name in names:
|
||||
const_value = c_int(0)
|
||||
rc = LTC.crypt_get_constant(name, byref(const_value))
|
||||
value = const_value.value
|
||||
print(' %-25s %d' % (name.decode("utf-8"), value))
|
||||
print(' ')
|
||||
|
||||
if SHOW_SELECTED_SIZES:
|
||||
print('-'*60)
|
||||
print('\n selected sizes:')
|
||||
|
||||
names = [
|
||||
b'rijndael_key',
|
||||
b'rsa_key',
|
||||
b'symmetric_CTR',
|
||||
b'twofish_key',
|
||||
b'ecc_point',
|
||||
b'gcm_state',
|
||||
b'sha512_state',
|
||||
]
|
||||
for name in names:
|
||||
size_value = c_int(0)
|
||||
rc = LTC.crypt_get_size(name, byref(size_value))
|
||||
value = size_value.value
|
||||
print(' %-25s %d' % (name.decode("utf-8"), value))
|
||||
print(' ')
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
# LibTomCrypt exposes one interesting string that can be accessed
|
||||
# via Python's ctypes module, "crypt_build_settings", which
|
||||
# provides a list of this build's compiler switches and supported
|
||||
# algorithms. If someday LTC exposes other interesting strings,
|
||||
# they can be found with:
|
||||
# nm /usr/local/lib/libtomcrypt.dylib | grep " D "
|
||||
|
||||
def get_named_string(lib, name):
|
||||
return c_char_p.in_dll(lib, name).value.decode("utf-8")
|
||||
|
||||
if SHOW_BUILD_OPTIONS_ALGS:
|
||||
print('-'*60)
|
||||
print('This is a string compiled into LTC showing compile')
|
||||
print('options and algorithms supported by this build \n')
|
||||
# print(get_named_string(LTC, 'crypt_build_settings'))
|
||||
inprint(get_named_string(LTC, 'crypt_build_settings'), 4)
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
# here is an example of how Python code can be written to access
|
||||
# LTC's implementation of SHA256 and ChaCha,
|
||||
|
||||
# - - - - - - - - - - - - -
|
||||
# definitions
|
||||
|
||||
from binascii import hexlify, unhexlify
|
||||
|
||||
def _err2str(err):
|
||||
# define return type
|
||||
errstr = LTC.error_to_string
|
||||
errstr.restype = c_char_p
|
||||
# get and return err string
|
||||
return errstr(err)
|
||||
|
||||
def _get_size(name):
|
||||
size = c_int(0)
|
||||
rc = LTC.crypt_get_size(bytes(name), byref(size))
|
||||
if rc != 0:
|
||||
raise Exception('LTC.crypt_get_size(%s) rc = %d' % (name, rc))
|
||||
return size.value
|
||||
|
||||
def _get_constant(name):
|
||||
constant = c_int(0)
|
||||
rc = LTC.crypt_get_constant(bytes(name), byref(constant))
|
||||
if rc != 0:
|
||||
raise Exception('LTC.crypt_get_constant(%s) rc = %d' % (name, rc))
|
||||
return constant.value
|
||||
|
||||
CRYPT_OK = _get_constant(b'CRYPT_OK')
|
||||
|
||||
class SHA256(object):
|
||||
def __init__(self):
|
||||
self.state = c_buffer(_get_size(b'sha256_state'))
|
||||
LTC.sha256_init(byref(self.state))
|
||||
def update(self, data):
|
||||
LTC.sha256_process(byref(self.state), data, len(data))
|
||||
def digest(self):
|
||||
md = c_buffer(32)
|
||||
LTC.sha256_done(byref(self.state), byref(md))
|
||||
return md.raw
|
||||
|
||||
class ChaCha(object):
|
||||
def __init__(self, key, rounds):
|
||||
self.state = c_buffer(_get_size(b'chacha_state'))
|
||||
self.counter = c_int(1)
|
||||
err = LTC.chacha_setup(byref(self.state), key, len(key), rounds)
|
||||
if err != CRYPT_OK:
|
||||
raise Exception('LTC.chacha_setup(), err = %d, "%s"' % (err, _err2str(err)))
|
||||
def set_iv32(self, iv):
|
||||
err = LTC.chacha_ivctr32(byref(self.state), iv, len(iv), byref(self.counter))
|
||||
if err != CRYPT_OK:
|
||||
raise Exception('LTC.chacha_ivctr32(), err = %d, "%s"' % (err, _err2str(err)))
|
||||
def crypt(self, datain):
|
||||
dataout = c_buffer(len(datain))
|
||||
err = LTC.chacha_crypt(byref(self.state), datain, len(datain), byref(dataout))
|
||||
if err != CRYPT_OK:
|
||||
raise Exception('LTC.chacha_crypt(), err = %d, "%s"' % (err, _err2str(err)))
|
||||
return dataout.raw
|
||||
|
||||
# - - - - - - - - - - - - -
|
||||
# a SHA256 app fragment
|
||||
|
||||
if SHOW_SHA256_EXAMPLE:
|
||||
print('-'*60)
|
||||
data = b'hello world' # we want bytes, not Unicode
|
||||
|
||||
sha256 = SHA256()
|
||||
sha256.update(data)
|
||||
md = sha256.digest()
|
||||
|
||||
template = '\n the SHA256 digest for "%s" is %s \n'
|
||||
print(template % (data, hexlify(md)))
|
||||
|
||||
# - - - - - - - - - - - - -
|
||||
# a ChaCha app fragment
|
||||
|
||||
if SHOW_CHACHA_EXAMPLE:
|
||||
print('-'*60)
|
||||
key = b'hownowbrowncow\x00\x00' # exactly 16 or 32 bytes
|
||||
rounds = 12 # common values: 8, 12, 20
|
||||
iv = b'123456789012' # exactly 12 bytes
|
||||
plain = b'Kilroy was here, there, and everywhere!'
|
||||
|
||||
cha = ChaCha(key, rounds)
|
||||
cha.set_iv32(iv)
|
||||
cipher = cha.crypt(plain)
|
||||
|
||||
template = '\n ChaCha%d ciphertext for "%s" is "%s"'
|
||||
print(template % (rounds, plain, hexlify(cipher)))
|
||||
|
||||
cha.set_iv32(iv) # reset to decrypt
|
||||
decrypted = cha.crypt(cipher)
|
||||
|
||||
template = ' ChaCha%d decoded text for "%s" is "%s" \n'
|
||||
print(template % (rounds, plain, decrypted.decode("utf-8")))
|
||||
|
||||
# Footnote: Keys should be erased fm memory as soon as possible after use,
|
||||
# and that includes Python. For a tip on how to do that in Python, see
|
||||
# http://buggywhip.blogspot.com/2010/12/erase-keys-and-credit-card-numbers-in.html
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -26,58 +26,58 @@ void register_algs(void)
|
||||
{
|
||||
int x;
|
||||
|
||||
#ifdef RIJNDAEL
|
||||
#ifdef LTC_RIJNDAEL
|
||||
register_cipher (&aes_desc);
|
||||
#endif
|
||||
#ifdef BLOWFISH
|
||||
#ifdef LTC_BLOWFISH
|
||||
register_cipher (&blowfish_desc);
|
||||
#endif
|
||||
#ifdef XTEA
|
||||
#ifdef LTC_XTEA
|
||||
register_cipher (&xtea_desc);
|
||||
#endif
|
||||
#ifdef RC5
|
||||
#ifdef LTC_RC5
|
||||
register_cipher (&rc5_desc);
|
||||
#endif
|
||||
#ifdef RC6
|
||||
#ifdef LTC_RC6
|
||||
register_cipher (&rc6_desc);
|
||||
#endif
|
||||
#ifdef SAFERP
|
||||
#ifdef LTC_SAFERP
|
||||
register_cipher (&saferp_desc);
|
||||
#endif
|
||||
#ifdef TWOFISH
|
||||
#ifdef LTC_TWOFISH
|
||||
register_cipher (&twofish_desc);
|
||||
#endif
|
||||
#ifdef SAFER
|
||||
#ifdef LTC_SAFER
|
||||
register_cipher (&safer_k64_desc);
|
||||
register_cipher (&safer_sk64_desc);
|
||||
register_cipher (&safer_k128_desc);
|
||||
register_cipher (&safer_sk128_desc);
|
||||
#endif
|
||||
#ifdef RC2
|
||||
#ifdef LTC_RC2
|
||||
register_cipher (&rc2_desc);
|
||||
#endif
|
||||
#ifdef DES
|
||||
#ifdef LTC_DES
|
||||
register_cipher (&des_desc);
|
||||
register_cipher (&des3_desc);
|
||||
#endif
|
||||
#ifdef CAST5
|
||||
#ifdef LTC_CAST5
|
||||
register_cipher (&cast5_desc);
|
||||
#endif
|
||||
#ifdef NOEKEON
|
||||
#ifdef LTC_NOEKEON
|
||||
register_cipher (&noekeon_desc);
|
||||
#endif
|
||||
#ifdef SKIPJACK
|
||||
#ifdef LTC_SKIPJACK
|
||||
register_cipher (&skipjack_desc);
|
||||
#endif
|
||||
#ifdef KHAZAD
|
||||
#ifdef LTC_KHAZAD
|
||||
register_cipher (&khazad_desc);
|
||||
#endif
|
||||
#ifdef ANUBIS
|
||||
#ifdef LTC_ANUBIS
|
||||
register_cipher (&anubis_desc);
|
||||
#endif
|
||||
|
||||
if (register_hash(&sha256_desc) == -1) {
|
||||
printf("Error registering SHA256\n");
|
||||
printf("Error registering LTC_SHA256\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
hash_idx = find_hash("sha256");
|
||||
if (hash_idx == -1) {
|
||||
printf("SHA256 not found...?\n");
|
||||
printf("LTC_SHA256 not found...?\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
@@ -236,6 +236,6 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/demos/encrypt.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2005/08/04 20:43:50 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Written by Daniel Richards <kyhwana@world-net.co.nz> 6/7/2002
|
||||
* hash.c: This app uses libtomcrypt to hash either stdin or a file
|
||||
@@ -9,111 +18,283 @@
|
||||
|
||||
#include <tomcrypt.h>
|
||||
|
||||
int errno;
|
||||
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L
|
||||
#include <libgen.h>
|
||||
#else
|
||||
#define basename(x) x
|
||||
#endif
|
||||
|
||||
void register_algs();
|
||||
#if !defined(PATH_MAX) && defined(_MSC_VER)
|
||||
#include <windows.h>
|
||||
#define PATH_MAX MAX_PATH
|
||||
#endif
|
||||
|
||||
/* thanks http://stackoverflow.com/a/8198009 */
|
||||
#define _base(x) ((x >= '0' && x <= '9') ? '0' : \
|
||||
(x >= 'a' && x <= 'f') ? 'a' - 10 : \
|
||||
(x >= 'A' && x <= 'F') ? 'A' - 10 : \
|
||||
'\255')
|
||||
#define HEXOF(x) (x - _base(x))
|
||||
|
||||
static char* hashsum;
|
||||
|
||||
static void cleanup(void)
|
||||
{
|
||||
free(hashsum);
|
||||
}
|
||||
|
||||
static void die(int status)
|
||||
{
|
||||
unsigned long w, x;
|
||||
FILE* o = status == EXIT_SUCCESS ? stdout : stderr;
|
||||
fprintf(o, "usage: %s -a algorithm [-c] [file...]\n\n", hashsum);
|
||||
fprintf(o, "\t-c\tCheck the hash(es) of the file(s) written in [file].\n");
|
||||
fprintf(o, "\t\t(-a not required)\n");
|
||||
fprintf(o, "\nAlgorithms:\n\t");
|
||||
w = 0;
|
||||
for (x = 0; hash_descriptor[x].name != NULL; x++) {
|
||||
w += fprintf(o, "%-14s", hash_descriptor[x].name);
|
||||
if (w >= 70) {
|
||||
fprintf(o, "\n\t");
|
||||
w = 0;
|
||||
}
|
||||
}
|
||||
if (w != 0) fprintf(o, "\n");
|
||||
exit(status);
|
||||
}
|
||||
|
||||
static void printf_hex(unsigned char* hash_buffer, unsigned long w)
|
||||
{
|
||||
unsigned long x;
|
||||
for (x = 0; x < w; x++) {
|
||||
printf("%02x",hash_buffer[x]);
|
||||
}
|
||||
}
|
||||
|
||||
static void check_file(int argn, int argc, char **argv)
|
||||
{
|
||||
int err, failed, invalid;
|
||||
unsigned char is_buffer[MAXBLOCKSIZE], should_buffer[MAXBLOCKSIZE];
|
||||
char buf[PATH_MAX + (MAXBLOCKSIZE * 3)];
|
||||
/* iterate through all files */
|
||||
while(argn < argc) {
|
||||
char* s;
|
||||
FILE* f = fopen(argv[argn], "rb");
|
||||
if(f == NULL) {
|
||||
int n = snprintf(buf, sizeof(buf), "%s: %s", hashsum, argv[argn]);
|
||||
if (n > 0 && n < (int)sizeof(buf))
|
||||
perror(buf);
|
||||
else
|
||||
perror(argv[argn]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
failed = 0;
|
||||
invalid = 0;
|
||||
/* read the file line by line */
|
||||
while((s = fgets(buf, sizeof(buf), f)) != NULL)
|
||||
{
|
||||
int tries, n;
|
||||
unsigned long hash_len, w, x;
|
||||
char* space = strstr(s, " ");
|
||||
|
||||
/* skip lines with comments */
|
||||
if (buf[0] == '#') continue;
|
||||
|
||||
if (space == NULL) {
|
||||
fprintf(stderr, "%s: no properly formatted checksum lines found\n", hashsum);
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
hash_len = space - s;
|
||||
hash_len /= 2;
|
||||
|
||||
if (hash_len > sizeof(should_buffer)) {
|
||||
fprintf(stderr, "%s: hash too long\n", hashsum);
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
/* convert the hex-string back to binary */
|
||||
for (x = 0; x < hash_len; ++x) {
|
||||
should_buffer[x] = HEXOF(s[x*2]) << 4 | HEXOF(s[x*2 + 1]);
|
||||
}
|
||||
|
||||
space++;
|
||||
if (*space != '*') {
|
||||
fprintf(stderr, "%s: unsupported input mode '%c'\n", hashsum, *space);
|
||||
goto ERR;
|
||||
}
|
||||
space++;
|
||||
|
||||
for (n = 0; n < (buf + sizeof(buf)) - space; ++n) {
|
||||
if(iscntrl((int)space[n])) {
|
||||
space[n] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* try all hash algorithms that have the appropriate hash size */
|
||||
tries = 0;
|
||||
for (x = 0; hash_descriptor[x].name != NULL; ++x) {
|
||||
if (hash_descriptor[x].hashsize == hash_len) {
|
||||
tries++;
|
||||
w = sizeof(is_buffer);
|
||||
if ((err = hash_file(x, space, is_buffer, &w)) != CRYPT_OK) {
|
||||
fprintf(stderr, "%s: File hash error: %s: %s\n", hashsum, space, error_to_string(err));
|
||||
ERR:
|
||||
fclose(f);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if(XMEMCMP(should_buffer, is_buffer, w) == 0) {
|
||||
printf("%s: OK\n", space);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} /* for */
|
||||
if (hash_descriptor[x].name == NULL) {
|
||||
if(tries > 0) {
|
||||
printf("%s: FAILED\n", space);
|
||||
failed++;
|
||||
}
|
||||
else {
|
||||
invalid++;
|
||||
}
|
||||
}
|
||||
} /* while */
|
||||
fclose(f);
|
||||
if(invalid) {
|
||||
fprintf(stderr, "%s: WARNING: %d %s is improperly formatted\n", hashsum, invalid, invalid > 1?"lines":"line");
|
||||
}
|
||||
if(failed) {
|
||||
fprintf(stderr, "%s: WARNING: %d computed %s did NOT match\n", hashsum, failed, failed > 1?"checksums":"checksum");
|
||||
}
|
||||
argn++;
|
||||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int idx, x, z;
|
||||
unsigned long w;
|
||||
int idxs[TAB_SIZE], idx, check, y, z, err, argn;
|
||||
unsigned long w, x;
|
||||
unsigned char hash_buffer[MAXBLOCKSIZE];
|
||||
hash_state md;
|
||||
|
||||
hashsum = strdup(basename(argv[0]));
|
||||
atexit(cleanup);
|
||||
|
||||
/* You need to register algorithms before using them */
|
||||
register_algs();
|
||||
if (argc < 2) {
|
||||
printf("usage: ./hash algorithm file [file ...]\n");
|
||||
printf("Algorithms:\n");
|
||||
for (x = 0; hash_descriptor[x].name != NULL; x++) {
|
||||
printf(" %s (%d)\n", hash_descriptor[x].name, hash_descriptor[x].ID);
|
||||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
register_all_ciphers();
|
||||
register_all_hashes();
|
||||
if (argc > 1 && (strcmp("-h", argv[1]) == 0 || strcmp("--help", argv[1]) == 0)) {
|
||||
die(EXIT_SUCCESS);
|
||||
}
|
||||
if (argc < 3) {
|
||||
die(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
idx = find_hash(argv[1]);
|
||||
if (idx == -1) {
|
||||
fprintf(stderr, "\nInvalid hash specified on command line.\n");
|
||||
return -1;
|
||||
for (x = 0; x < sizeof(idxs)/sizeof(idxs[0]); ++x) {
|
||||
idxs[x] = -2;
|
||||
}
|
||||
argn = 1;
|
||||
check = 0;
|
||||
idx = 0;
|
||||
|
||||
while(argn < argc){
|
||||
if(strcmp("-a", argv[argn]) == 0) {
|
||||
argn++;
|
||||
if(argn < argc) {
|
||||
idxs[idx] = find_hash(argv[argn]);
|
||||
if (idxs[idx] == -1) {
|
||||
struct {
|
||||
const char* is;
|
||||
const char* should;
|
||||
} shasum_compat[] =
|
||||
{
|
||||
#ifdef LTC_SHA1
|
||||
{ "1", sha1_desc.name },
|
||||
#endif
|
||||
#ifdef LTC_SHA224
|
||||
{ "224", sha224_desc.name },
|
||||
#endif
|
||||
#ifdef LTC_SHA256
|
||||
{ "256", sha256_desc.name },
|
||||
#endif
|
||||
#ifdef LTC_SHA384
|
||||
{ "384", sha384_desc.name },
|
||||
#endif
|
||||
#ifdef LTC_SHA512
|
||||
{ "512", sha512_desc.name },
|
||||
#endif
|
||||
#ifdef LTC_SHA512_224
|
||||
{ "512224", sha512_224_desc.name },
|
||||
#endif
|
||||
#ifdef LTC_SHA512_256
|
||||
{ "512256", sha512_256_desc.name },
|
||||
#endif
|
||||
{ NULL, NULL }
|
||||
};
|
||||
for (x = 0; shasum_compat[x].is != NULL; ++x) {
|
||||
if(XSTRCMP(shasum_compat[x].is, argv[argn]) == 0) {
|
||||
idxs[idx] = find_hash(shasum_compat[x].should);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (idxs[idx] == -1) {
|
||||
fprintf(stderr, "%s: Unrecognized algorithm\n", hashsum);
|
||||
die(EXIT_FAILURE);
|
||||
}
|
||||
idx++;
|
||||
if ((size_t)idx >= sizeof(idxs)/sizeof(idxs[0])) {
|
||||
fprintf(stderr, "%s: Too many '-a' options chosen\n", hashsum);
|
||||
die(EXIT_FAILURE);
|
||||
}
|
||||
argn++;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
die(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
if(strcmp("-c", argv[argn]) == 0) {
|
||||
check = 1;
|
||||
argn++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (argc == 2) {
|
||||
hash_descriptor[idx].init(&md);
|
||||
do {
|
||||
x = fread(hash_buffer, 1, sizeof(hash_buffer), stdin);
|
||||
hash_descriptor[idx].process(&md, hash_buffer, x);
|
||||
} while (x == sizeof(hash_buffer));
|
||||
hash_descriptor[idx].done(&md, hash_buffer);
|
||||
for (x = 0; x < (int)hash_descriptor[idx].hashsize; x++) {
|
||||
printf("%02x",hash_buffer[x]);
|
||||
if (check == 1) {
|
||||
check_file(argn, argc, argv);
|
||||
}
|
||||
|
||||
if (argc == argn) {
|
||||
w = sizeof(hash_buffer);
|
||||
if ((err = hash_filehandle(idxs[0], stdin, hash_buffer, &w)) != CRYPT_OK) {
|
||||
fprintf(stderr, "%s: File hash error: %s\n", hashsum, error_to_string(err));
|
||||
return EXIT_FAILURE;
|
||||
} else {
|
||||
for (x = 0; x < w; x++) {
|
||||
printf("%02x",hash_buffer[x]);
|
||||
}
|
||||
printf(" *-\n");
|
||||
}
|
||||
printf(" (stdin)\n");
|
||||
} else {
|
||||
for (z = 2; z < argc; z++) {
|
||||
w = sizeof(hash_buffer);
|
||||
if ((errno = hash_file(idx,argv[z],hash_buffer,&w)) != CRYPT_OK) {
|
||||
printf("File hash error: %s\n", error_to_string(errno));
|
||||
} else {
|
||||
for (x = 0; x < (int)hash_descriptor[idx].hashsize; x++) {
|
||||
printf("%02x",hash_buffer[x]);
|
||||
}
|
||||
printf(" %s\n", argv[z]);
|
||||
for (z = argn; z < argc; z++) {
|
||||
for (y = 0; y < idx; ++y) {
|
||||
w = sizeof(hash_buffer);
|
||||
if ((err = hash_file(idxs[y],argv[z],hash_buffer,&w)) != CRYPT_OK) {
|
||||
fprintf(stderr, "%s: File hash error: %s\n", hashsum, error_to_string(err));
|
||||
return EXIT_FAILURE;
|
||||
} else {
|
||||
printf_hex(hash_buffer, w);
|
||||
printf(" *%s\n", argv[z]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void register_algs(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
#ifdef TIGER
|
||||
register_hash (&tiger_desc);
|
||||
#endif
|
||||
#ifdef MD2
|
||||
register_hash (&md2_desc);
|
||||
#endif
|
||||
#ifdef MD4
|
||||
register_hash (&md4_desc);
|
||||
#endif
|
||||
#ifdef MD5
|
||||
register_hash (&md5_desc);
|
||||
#endif
|
||||
#ifdef SHA1
|
||||
register_hash (&sha1_desc);
|
||||
#endif
|
||||
#ifdef SHA224
|
||||
register_hash (&sha224_desc);
|
||||
#endif
|
||||
#ifdef SHA256
|
||||
register_hash (&sha256_desc);
|
||||
#endif
|
||||
#ifdef SHA384
|
||||
register_hash (&sha384_desc);
|
||||
#endif
|
||||
#ifdef SHA512
|
||||
register_hash (&sha512_desc);
|
||||
#endif
|
||||
#ifdef RIPEMD128
|
||||
register_hash (&rmd128_desc);
|
||||
#endif
|
||||
#ifdef RIPEMD160
|
||||
register_hash (&rmd160_desc);
|
||||
#endif
|
||||
#ifdef WHIRLPOOL
|
||||
register_hash (&whirlpool_desc);
|
||||
#endif
|
||||
#ifdef CHC_HASH
|
||||
register_hash(&chc_desc);
|
||||
if ((err = chc_register(register_cipher(&aes_enc_desc))) != CRYPT_OK) {
|
||||
printf("chc_register error: %s\n", error_to_string(err));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/demos/hashsum.c,v $ */
|
||||
/* $Revision: 1.2 $ */
|
||||
/* $Date: 2005/05/05 14:35:56 $ */
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
205
libtomcrypt/demos/ltcrypt.c
Normal file
205
libtomcrypt/demos/ltcrypt.c
Normal file
@@ -0,0 +1,205 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
|
||||
/* encrypt V1.1 Fri Oct 18 04:28:03 NZDT 2002 */
|
||||
/* File de/encryption, using libtomcrypt */
|
||||
/* Written by Daniel Richards <kyhwana@world-net.co.nz> */
|
||||
/* Help from Tom St Denis with various bits */
|
||||
/* This code is public domain, no rights reserved. */
|
||||
/* Encrypts by default, -d flag enables decryption */
|
||||
/* ie: ./encrypt blowfish story.txt story.ct */
|
||||
/* ./encrypt -d blowfish story.ct story.pt */
|
||||
|
||||
#include <tomcrypt.h>
|
||||
|
||||
int usage(char *name)
|
||||
{
|
||||
int x;
|
||||
|
||||
printf("Usage encrypt: %s cipher infile outfile\n", name);
|
||||
printf("Usage decrypt: %s -d cipher infile outfile\n", name);
|
||||
printf("Usage test: %s -t cipher\nCiphers:\n", name);
|
||||
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
||||
printf("%s\n",cipher_descriptor[x].name);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned char plaintext[512],ciphertext[512];
|
||||
unsigned char tmpkey[512], key[MAXBLOCKSIZE], IV[MAXBLOCKSIZE];
|
||||
unsigned char inbuf[512]; /* i/o block size */
|
||||
unsigned long outlen, y, ivsize, x, decrypt;
|
||||
symmetric_CTR ctr;
|
||||
int cipher_idx, hash_idx, ks;
|
||||
char *infile, *outfile, *cipher;
|
||||
prng_state prng;
|
||||
FILE *fdin, *fdout;
|
||||
int err;
|
||||
|
||||
/* register algs, so they can be printed */
|
||||
register_all_ciphers();
|
||||
register_all_hashes();
|
||||
register_all_prngs();
|
||||
|
||||
if (argc < 4) {
|
||||
if ((argc > 2) && (!strcmp(argv[1], "-t"))) {
|
||||
cipher = argv[2];
|
||||
cipher_idx = find_cipher(cipher);
|
||||
if (cipher_idx == -1) {
|
||||
printf("Invalid cipher %s entered on command line.\n", cipher);
|
||||
exit(-1);
|
||||
} /* if */
|
||||
if (cipher_descriptor[cipher_idx].test)
|
||||
{
|
||||
if (cipher_descriptor[cipher_idx].test() != CRYPT_OK)
|
||||
{
|
||||
printf("Error when testing cipher %s.\n", cipher);
|
||||
exit(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Testing cipher %s succeeded.\n", cipher);
|
||||
exit(0);
|
||||
} /* if ... else */
|
||||
} /* if */
|
||||
}
|
||||
return usage(argv[0]);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "-d")) {
|
||||
decrypt = 1;
|
||||
cipher = argv[2];
|
||||
infile = argv[3];
|
||||
outfile = argv[4];
|
||||
} else {
|
||||
decrypt = 0;
|
||||
cipher = argv[1];
|
||||
infile = argv[2];
|
||||
outfile = argv[3];
|
||||
}
|
||||
|
||||
/* file handles setup */
|
||||
fdin = fopen(infile,"rb");
|
||||
if (fdin == NULL) {
|
||||
perror("Can't open input for reading");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
fdout = fopen(outfile,"wb");
|
||||
if (fdout == NULL) {
|
||||
perror("Can't open output for writing");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
cipher_idx = find_cipher(cipher);
|
||||
if (cipher_idx == -1) {
|
||||
printf("Invalid cipher entered on command line.\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
hash_idx = find_hash("sha256");
|
||||
if (hash_idx == -1) {
|
||||
printf("LTC_SHA256 not found...?\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
ivsize = cipher_descriptor[cipher_idx].block_length;
|
||||
ks = hash_descriptor[hash_idx].hashsize;
|
||||
if (cipher_descriptor[cipher_idx].keysize(&ks) != CRYPT_OK) {
|
||||
printf("Invalid keysize???\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("\nEnter key: ");
|
||||
if(fgets((char *)tmpkey,sizeof(tmpkey), stdin) == NULL)
|
||||
exit(-1);
|
||||
outlen = sizeof(key);
|
||||
if ((err = hash_memory(hash_idx,tmpkey,strlen((char *)tmpkey),key,&outlen)) != CRYPT_OK) {
|
||||
printf("Error hashing key: %s\n", error_to_string(err));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (decrypt) {
|
||||
/* Need to read in IV */
|
||||
if (fread(IV,1,ivsize,fdin) != ivsize) {
|
||||
printf("Error reading IV from input.\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if ((err = ctr_start(cipher_idx,IV,key,ks,0,CTR_COUNTER_LITTLE_ENDIAN,&ctr)) != CRYPT_OK) {
|
||||
printf("ctr_start error: %s\n",error_to_string(err));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* IV done */
|
||||
do {
|
||||
y = fread(inbuf,1,sizeof(inbuf),fdin);
|
||||
|
||||
if ((err = ctr_decrypt(inbuf,plaintext,y,&ctr)) != CRYPT_OK) {
|
||||
printf("ctr_decrypt error: %s\n", error_to_string(err));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (fwrite(plaintext,1,y,fdout) != y) {
|
||||
printf("Error writing to file.\n");
|
||||
exit(-1);
|
||||
}
|
||||
} while (y == sizeof(inbuf));
|
||||
fclose(fdin);
|
||||
fclose(fdout);
|
||||
|
||||
} else { /* encrypt */
|
||||
/* Setup yarrow for random bytes for IV */
|
||||
|
||||
if ((err = rng_make_prng(128, find_prng("yarrow"), &prng, NULL)) != CRYPT_OK) {
|
||||
printf("Error setting up PRNG, %s\n", error_to_string(err));
|
||||
}
|
||||
|
||||
/* You can use rng_get_bytes on platforms that support it */
|
||||
/* x = rng_get_bytes(IV,ivsize,NULL);*/
|
||||
x = yarrow_read(IV,ivsize,&prng);
|
||||
if (x != ivsize) {
|
||||
printf("Error reading PRNG for IV required.\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (fwrite(IV,1,ivsize,fdout) != ivsize) {
|
||||
printf("Error writing IV to output.\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if ((err = ctr_start(cipher_idx,IV,key,ks,0,CTR_COUNTER_LITTLE_ENDIAN,&ctr)) != CRYPT_OK) {
|
||||
printf("ctr_start error: %s\n",error_to_string(err));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
do {
|
||||
y = fread(inbuf,1,sizeof(inbuf),fdin);
|
||||
|
||||
if ((err = ctr_encrypt(inbuf,ciphertext,y,&ctr)) != CRYPT_OK) {
|
||||
printf("ctr_encrypt error: %s\n", error_to_string(err));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (fwrite(ciphertext,1,y,fdout) != y) {
|
||||
printf("Error writing to output.\n");
|
||||
exit(-1);
|
||||
}
|
||||
} while (y == sizeof(inbuf));
|
||||
fclose(fdout);
|
||||
fclose(fdin);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
@@ -33,7 +33,7 @@ int main(void)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* HMAC */
|
||||
/* LTC_HMAC */
|
||||
len = sizeof(buf[0]);
|
||||
hmac_memory(find_hash("sha256"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
|
||||
len2 = sizeof(buf[0]);
|
||||
@@ -55,7 +55,7 @@ int main(void)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* OMAC */
|
||||
/* LTC_OMAC */
|
||||
len = sizeof(buf[0]);
|
||||
omac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
|
||||
len2 = sizeof(buf[0]);
|
||||
@@ -105,6 +105,6 @@ int main(void)
|
||||
}
|
||||
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/demos/multi.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2006/06/07 22:25:09 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
397
libtomcrypt/demos/openssl-enc.c
Normal file
397
libtomcrypt/demos/openssl-enc.c
Normal file
@@ -0,0 +1,397 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Demo to do the rough equivalent of:
|
||||
*
|
||||
* openssl enc -aes-256-cbc -pass pass:foobar -in infile -out outfile -p
|
||||
*
|
||||
* Compilation:
|
||||
*
|
||||
* $(CC) -I /path/to/headers -L .../libs \
|
||||
* -o openssl-enc \
|
||||
* openssl-enc.c -ltomcrypt
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* ./openssl-enc <enc|dec> infile outfile "passphrase" [salt]
|
||||
*
|
||||
* If provided, the salt must be EXACTLY a 16-char hex string.
|
||||
*
|
||||
* Demo is an example of:
|
||||
*
|
||||
* - (When decrypting) yanking salt out of the OpenSSL "Salted__..." header
|
||||
* - OpenSSL-compatible key derivation (in OpenSSL's modified PKCS#5v1 approach)
|
||||
* - Grabbing an Initialization Vector from the key generator
|
||||
* - Performing simple block encryption using AES
|
||||
* - PKCS#7-type padding (which hopefully can get ripped out of this demo and
|
||||
* made a libtomcrypt thing someday).
|
||||
*
|
||||
* This program is free for all purposes without any express guarantee it
|
||||
* works. If you really want to see a license here, assume the WTFPL :-)
|
||||
*
|
||||
* BJ Black, bblack@barracuda.com, https://wjblack.com
|
||||
*
|
||||
* BUGS:
|
||||
* Passing a password on a command line is a HORRIBLE idea. Don't use
|
||||
* this program for serious work!
|
||||
*/
|
||||
|
||||
#include <tomcrypt.h>
|
||||
|
||||
#ifndef LTC_RIJNDAEL
|
||||
#error Cannot compile this demo; Rijndael (AES) required
|
||||
#endif
|
||||
#ifndef LTC_CBC_MODE
|
||||
#error Cannot compile this demo; CBC mode required
|
||||
#endif
|
||||
#ifndef LTC_PKCS_5
|
||||
#error Cannot compile this demo; PKCS5 required
|
||||
#endif
|
||||
#ifndef LTC_RNG_GET_BYTES
|
||||
#error Cannot compile this demo; random generator required
|
||||
#endif
|
||||
#ifndef LTC_MD5
|
||||
#error Cannot compile this demo; MD5 required
|
||||
#endif
|
||||
|
||||
/* OpenSSL by default only runs one hash round */
|
||||
#define OPENSSL_ITERATIONS 1
|
||||
/* Use aes-256-cbc, so 256 bits of key, 128 of IV */
|
||||
#define KEY_LENGTH (256>>3)
|
||||
#define IV_LENGTH (128>>3)
|
||||
/* PKCS#5v1 requires exactly an 8-byte salt */
|
||||
#define SALT_LENGTH 8
|
||||
/* The header OpenSSL puts on an encrypted file */
|
||||
static char salt_header[] = { 'S', 'a', 'l', 't', 'e', 'd', '_', '_' };
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/* A simple way to handle the possibility that a block may increase in size
|
||||
after padding. */
|
||||
union paddable {
|
||||
unsigned char unpad[1024];
|
||||
unsigned char pad[1024+MAXBLOCKSIZE];
|
||||
};
|
||||
|
||||
/*
|
||||
* Print usage and exit with a bad status (and perror() if any errno).
|
||||
*
|
||||
* Input: argv[0] and the error string
|
||||
* Output: <no return>
|
||||
* Side Effects: print messages and barf (does exit(3))
|
||||
*/
|
||||
void barf(const char *pname, const char *err)
|
||||
{
|
||||
printf("Usage: %s <enc|dec> infile outfile passphrase [salt]\n", pname);
|
||||
printf("\n");
|
||||
printf(" # encrypts infile->outfile, random salt\n");
|
||||
printf(" %s enc infile outfile \"passphrase\"\n", pname);
|
||||
printf("\n");
|
||||
printf(" # encrypts infile->outfile, salt from cmdline\n");
|
||||
printf(" %s enc infile outfile pass 0123456789abcdef\n", pname);
|
||||
printf("\n");
|
||||
printf(" # decrypts infile->outfile, pulls salt from infile\n");
|
||||
printf(" %s dec infile outfile pass\n", pname);
|
||||
printf("\n");
|
||||
printf(" # decrypts infile->outfile, salt specified\n");
|
||||
printf(" # (don't try to read the salt from infile)\n");
|
||||
printf(" %s dec infile outfile pass 0123456789abcdef"
|
||||
"\n", pname);
|
||||
printf("\n");
|
||||
printf("Application Error: %s\n", err);
|
||||
if(errno)
|
||||
perror(" System Error");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse a salt value passed in on the cmdline.
|
||||
*
|
||||
* Input: string passed in and a buf to put it in (exactly 8 bytes!)
|
||||
* Output: CRYPT_OK if parsed OK, CRYPT_ERROR if not
|
||||
* Side Effects: none
|
||||
*/
|
||||
int parse_hex_salt(unsigned char *in, unsigned char *out)
|
||||
{
|
||||
int idx;
|
||||
for(idx=0; idx<SALT_LENGTH; idx++)
|
||||
if(sscanf((char*)in+idx*2, "%02hhx", out+idx) != 1)
|
||||
return CRYPT_ERROR;
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse the Salted__[+8 bytes] from an OpenSSL-compatible file header.
|
||||
*
|
||||
* Input: file to read from and a to put the salt in (exactly 8 bytes!)
|
||||
* Output: CRYPT_OK if parsed OK, CRYPT_ERROR if not
|
||||
* Side Effects: infile's read pointer += 16
|
||||
*/
|
||||
int parse_openssl_header(FILE *in, unsigned char *out)
|
||||
{
|
||||
unsigned char tmp[SALT_LENGTH];
|
||||
if(fread(tmp, 1, sizeof(tmp), in) != sizeof(tmp))
|
||||
return CRYPT_ERROR;
|
||||
if(memcmp(tmp, salt_header, sizeof(tmp)))
|
||||
return CRYPT_ERROR;
|
||||
if(fread(tmp, 1, sizeof(tmp), in) != sizeof(tmp))
|
||||
return CRYPT_ERROR;
|
||||
memcpy(out, tmp, sizeof(tmp));
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump a hexed stream of bytes (convenience func).
|
||||
*
|
||||
* Input: buf to read from, length
|
||||
* Output: none
|
||||
* Side Effects: bytes printed as a hex blob, no lf at the end
|
||||
*/
|
||||
void dump_bytes(unsigned char *in, unsigned long len)
|
||||
{
|
||||
unsigned long idx;
|
||||
for(idx=0; idx<len; idx++)
|
||||
printf("%02hhX", *(in+idx));
|
||||
}
|
||||
|
||||
/*
|
||||
* Pad or unpad a message using PKCS#7 padding.
|
||||
* Padding will add 1-(blocksize) bytes and unpadding will remove that amount.
|
||||
* Set is_padding to 1 to pad, 0 to unpad.
|
||||
*
|
||||
* Input: paddable buffer, size read, block length of cipher, mode
|
||||
* Output: number of bytes after padding resp. after unpadding
|
||||
* Side Effects: none
|
||||
*/
|
||||
size_t pkcs7_pad(union paddable *buf, size_t nb, int block_length,
|
||||
int is_padding)
|
||||
{
|
||||
unsigned char padval;
|
||||
off_t idx;
|
||||
|
||||
if(is_padding) {
|
||||
/* We are PADDING this block (and therefore adding bytes) */
|
||||
/* The pad value in PKCS#7 is the number of bytes remaining in
|
||||
the block, so for a 16-byte block and 3 bytes left, it's
|
||||
0x030303. In the oddball case where nb is an exact multiple
|
||||
multiple of block_length, set the padval to blocksize (i.e.
|
||||
add one full block) */
|
||||
padval = (unsigned char) (block_length - (nb % block_length));
|
||||
padval = padval ? padval : block_length;
|
||||
|
||||
memset(buf->pad+nb, padval, padval);
|
||||
return nb+padval;
|
||||
} else {
|
||||
/* We are UNPADDING this block (and removing bytes)
|
||||
We really just need to verify that the pad bytes are correct,
|
||||
so start at the end of the string and work backwards. */
|
||||
|
||||
/* Figure out what the padlength should be by looking at the
|
||||
last byte */
|
||||
idx = nb-1;
|
||||
padval = buf->pad[idx];
|
||||
|
||||
/* padval must be nonzero and <= block length */
|
||||
if(padval <= 0 || padval > block_length)
|
||||
return 0;
|
||||
|
||||
/* First byte's accounted for; do the rest */
|
||||
idx--;
|
||||
|
||||
while(idx >= (off_t)(nb-padval))
|
||||
if(buf->pad[idx] != padval)
|
||||
return 0;
|
||||
else
|
||||
idx--;
|
||||
|
||||
/* If we got here, the pad checked out, so return a smaller
|
||||
number of bytes than nb (basically where we left off+1) */
|
||||
return idx+1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform an encrypt/decrypt operation to/from files using AES+CBC+PKCS7 pad.
|
||||
* Set encrypt to 1 to encrypt, 0 to decrypt.
|
||||
*
|
||||
* Input: in/out files, key, iv, and mode
|
||||
* Output: CRYPT_OK if no error
|
||||
* Side Effects: bytes slurped from infile, pushed to outfile, fds updated.
|
||||
*/
|
||||
int do_crypt(FILE *infd, FILE *outfd, unsigned char *key, unsigned char *iv,
|
||||
int encrypt)
|
||||
{
|
||||
union paddable inbuf, outbuf;
|
||||
int cipher, ret;
|
||||
symmetric_CBC cbc;
|
||||
size_t nb;
|
||||
|
||||
/* Register your cipher! */
|
||||
cipher = register_cipher(&aes_desc);
|
||||
if(cipher == -1)
|
||||
return CRYPT_INVALID_CIPHER;
|
||||
|
||||
/* Start a CBC session with cipher/key/val params */
|
||||
ret = cbc_start(cipher, iv, key, KEY_LENGTH, 0, &cbc);
|
||||
if( ret != CRYPT_OK )
|
||||
return -1;
|
||||
|
||||
do {
|
||||
/* Get bytes from the source */
|
||||
nb = fread(inbuf.unpad, 1, sizeof(inbuf.unpad), infd);
|
||||
if(!nb)
|
||||
return encrypt ? CRYPT_OK : CRYPT_ERROR;
|
||||
|
||||
/* Barf if we got a read error */
|
||||
if(ferror(infd))
|
||||
return CRYPT_ERROR;
|
||||
|
||||
if(encrypt) {
|
||||
/* We're encrypting, so pad first (if at EOF) and then
|
||||
crypt */
|
||||
if(feof(infd))
|
||||
nb = pkcs7_pad(&inbuf, nb,
|
||||
aes_desc.block_length, 1);
|
||||
|
||||
ret = cbc_encrypt(inbuf.pad, outbuf.pad, nb, &cbc);
|
||||
if(ret != CRYPT_OK)
|
||||
return ret;
|
||||
|
||||
} else {
|
||||
/* We're decrypting, so decrypt and then unpad if at
|
||||
EOF */
|
||||
ret = cbc_decrypt(inbuf.unpad, outbuf.unpad, nb, &cbc);
|
||||
if( ret != CRYPT_OK )
|
||||
return ret;
|
||||
|
||||
if( feof(infd) )
|
||||
nb = pkcs7_pad(&outbuf, nb,
|
||||
aes_desc.block_length, 0);
|
||||
if(nb == 0)
|
||||
/* The file didn't decrypt correctly */
|
||||
return CRYPT_ERROR;
|
||||
|
||||
}
|
||||
|
||||
/* Push bytes to outfile */
|
||||
if(fwrite(outbuf.unpad, 1, nb, outfd) != nb)
|
||||
return CRYPT_ERROR;
|
||||
|
||||
} while(!feof(infd));
|
||||
|
||||
/* Close up */
|
||||
cbc_done(&cbc);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/* Convenience macro for the various barfable places below */
|
||||
#define BARF(a) { \
|
||||
if(infd) fclose(infd); \
|
||||
if(outfd) { fclose(outfd); remove(argv[3]); } \
|
||||
barf(argv[0], a); \
|
||||
}
|
||||
/*
|
||||
* The main routine. Mostly validate cmdline params, open files, run the KDF,
|
||||
* and do the crypt.
|
||||
*/
|
||||
int main(int argc, char *argv[]) {
|
||||
unsigned char salt[SALT_LENGTH];
|
||||
FILE *infd = NULL, *outfd = NULL;
|
||||
int encrypt = -1;
|
||||
int hash = -1;
|
||||
int ret;
|
||||
unsigned char keyiv[KEY_LENGTH + IV_LENGTH];
|
||||
unsigned long keyivlen = (KEY_LENGTH + IV_LENGTH);
|
||||
unsigned char *key, *iv;
|
||||
|
||||
/* Check proper number of cmdline args */
|
||||
if(argc < 5 || argc > 6)
|
||||
BARF("Invalid number of arguments");
|
||||
|
||||
/* Check proper mode of operation */
|
||||
if (!strncmp(argv[1], "enc", 3))
|
||||
encrypt = 1;
|
||||
else if(!strncmp(argv[1], "dec", 3))
|
||||
encrypt = 0;
|
||||
else
|
||||
BARF("Bad command name");
|
||||
|
||||
/* Check we can open infile/outfile */
|
||||
infd = fopen(argv[2], "rb");
|
||||
if(infd == NULL)
|
||||
BARF("Could not open infile");
|
||||
outfd = fopen(argv[3], "wb");
|
||||
if(outfd == NULL)
|
||||
BARF("Could not open outfile");
|
||||
|
||||
/* Get the salt from wherever */
|
||||
if(argc == 6) {
|
||||
/* User-provided */
|
||||
if(parse_hex_salt((unsigned char*) argv[5], salt) != CRYPT_OK)
|
||||
BARF("Bad user-specified salt");
|
||||
} else if(!strncmp(argv[1], "enc", 3)) {
|
||||
/* Encrypting; get from RNG */
|
||||
if(rng_get_bytes(salt, sizeof(salt), NULL) != sizeof(salt))
|
||||
BARF("Not enough random data");
|
||||
} else {
|
||||
/* Parse from infile (decrypt only) */
|
||||
if(parse_openssl_header(infd, salt) != CRYPT_OK)
|
||||
BARF("Invalid OpenSSL header in infile");
|
||||
}
|
||||
|
||||
/* Fetch the MD5 hasher for PKCS#5 */
|
||||
hash = register_hash(&md5_desc);
|
||||
if(hash == -1)
|
||||
BARF("Could not register MD5 hash");
|
||||
|
||||
/* Set things to a sane initial state */
|
||||
zeromem(keyiv, sizeof(keyiv));
|
||||
key = keyiv + 0; /* key comes first */
|
||||
iv = keyiv + KEY_LENGTH; /* iv comes next */
|
||||
|
||||
/* Run the key derivation from the provided passphrase. This gets us
|
||||
the key and iv. */
|
||||
ret = pkcs_5_alg1_openssl((unsigned char*)argv[4], strlen(argv[4]), salt,
|
||||
OPENSSL_ITERATIONS, hash, keyiv, &keyivlen );
|
||||
if(ret != CRYPT_OK)
|
||||
BARF("Could not derive key/iv from passphrase");
|
||||
|
||||
/* Display the salt/key/iv like OpenSSL cmdline does when -p */
|
||||
printf("salt="); dump_bytes(salt, sizeof(salt)); printf("\n");
|
||||
printf("key="); dump_bytes(key, KEY_LENGTH); printf("\n");
|
||||
printf("iv ="); dump_bytes(iv, IV_LENGTH ); printf("\n");
|
||||
|
||||
/* If we're encrypting, write the salt header as OpenSSL does */
|
||||
if(!strncmp(argv[1], "enc", 3)) {
|
||||
if(fwrite(salt_header, 1, sizeof(salt_header), outfd) !=
|
||||
sizeof(salt_header) )
|
||||
BARF("Error writing salt header to outfile");
|
||||
if(fwrite(salt, 1, sizeof(salt), outfd) != sizeof(salt))
|
||||
BARF("Error writing salt to outfile");
|
||||
}
|
||||
|
||||
/* At this point, the files are open, the salt has been figured out,
|
||||
and we're ready to pump data through crypt. */
|
||||
|
||||
/* Do the crypt operation */
|
||||
if(do_crypt(infd, outfd, key, iv, encrypt) != CRYPT_OK)
|
||||
BARF("Error during crypt operation");
|
||||
|
||||
/* Clean up */
|
||||
fclose(infd); fclose(outfd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
79
libtomcrypt/demos/sizes.c
Normal file
79
libtomcrypt/demos/sizes.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
|
||||
#include "tomcrypt.h"
|
||||
|
||||
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L
|
||||
#include <libgen.h>
|
||||
#else
|
||||
#define basename(x) x
|
||||
#endif
|
||||
/**
|
||||
@file demo_crypt_sizes.c
|
||||
|
||||
Demo how to get various sizes to dynamic languages
|
||||
like Python - Larry Bugbee, February 2013
|
||||
*/
|
||||
|
||||
static void _print_line(const char* cmd, const char* desc)
|
||||
{
|
||||
printf(" %-16s - %s\n", cmd, desc);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc == 1) {
|
||||
/* given a specific size name, get and print its size */
|
||||
char name[] = "ltc_hash_descriptor";
|
||||
unsigned int size;
|
||||
char *sizes_list;
|
||||
unsigned int sizes_list_len;
|
||||
if (crypt_get_size(name, &size) != 0) exit(EXIT_FAILURE);
|
||||
printf("\n size of '%s' is %u \n\n", name, size);
|
||||
|
||||
/* get and print the length of the names (and sizes) list */
|
||||
if (crypt_list_all_sizes(NULL, &sizes_list_len) != 0) exit(EXIT_FAILURE);
|
||||
printf(" need to allocate %u bytes \n\n", sizes_list_len);
|
||||
|
||||
/* get and print the names (and sizes) list */
|
||||
sizes_list = malloc(sizes_list_len);
|
||||
if (crypt_list_all_sizes(sizes_list, &sizes_list_len) != 0) exit(EXIT_FAILURE);
|
||||
printf(" supported sizes:\n\n%s\n\n", sizes_list);
|
||||
} else if (argc == 2) {
|
||||
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
|
||||
char* base = strdup(basename(argv[0]));
|
||||
printf("Usage: %s [-a] [-s name]\n\n", base);
|
||||
_print_line("<no argument>", "The old behavior of the demo");
|
||||
_print_line("-a", "Only lists all sizes");
|
||||
_print_line("-s name", "List a single size given as argument");
|
||||
_print_line("-h", "The help you're looking at");
|
||||
free(base);
|
||||
} else if (strcmp(argv[1], "-a") == 0) {
|
||||
char *sizes_list;
|
||||
unsigned int sizes_list_len;
|
||||
/* get and print the length of the names (and sizes) list */
|
||||
if (crypt_list_all_sizes(NULL, &sizes_list_len) != 0) exit(EXIT_FAILURE);
|
||||
/* get and print the names (and sizes) list */
|
||||
sizes_list = malloc(sizes_list_len);
|
||||
if (crypt_list_all_sizes(sizes_list, &sizes_list_len) != 0) exit(EXIT_FAILURE);
|
||||
printf("%s\n", sizes_list);
|
||||
}
|
||||
} else if (argc == 3) {
|
||||
if (strcmp(argv[1], "-s") == 0) {
|
||||
unsigned int size;
|
||||
if (crypt_get_size(argv[2], &size) != 0) exit(EXIT_FAILURE);
|
||||
printf("%s,%u\n", argv[2], size);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
@@ -1,3 +1,11 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
/* small demo app that just includes a cipher/hash/prng */
|
||||
#include <tomcrypt.h>
|
||||
|
||||
@@ -9,6 +17,6 @@ int main(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/demos/small.c,v $ */
|
||||
/* $Revision: 1.3 $ */
|
||||
/* $Date: 2006/06/07 22:25:09 $ */
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -31,6 +31,6 @@ int main(void)
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/demos/test.c,v $ */
|
||||
/* $Revision: 1.28 $ */
|
||||
/* $Date: 2006/05/25 10:50:08 $ */
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,129 +1,25 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include <tomcrypt.h>
|
||||
|
||||
void reg_algs(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
#ifdef RIJNDAEL
|
||||
register_cipher (&aes_desc);
|
||||
#endif
|
||||
#ifdef BLOWFISH
|
||||
register_cipher (&blowfish_desc);
|
||||
#endif
|
||||
#ifdef XTEA
|
||||
register_cipher (&xtea_desc);
|
||||
#endif
|
||||
#ifdef RC5
|
||||
register_cipher (&rc5_desc);
|
||||
#endif
|
||||
#ifdef RC6
|
||||
register_cipher (&rc6_desc);
|
||||
#endif
|
||||
#ifdef SAFERP
|
||||
register_cipher (&saferp_desc);
|
||||
#endif
|
||||
#ifdef TWOFISH
|
||||
register_cipher (&twofish_desc);
|
||||
#endif
|
||||
#ifdef SAFER
|
||||
register_cipher (&safer_k64_desc);
|
||||
register_cipher (&safer_sk64_desc);
|
||||
register_cipher (&safer_k128_desc);
|
||||
register_cipher (&safer_sk128_desc);
|
||||
#endif
|
||||
#ifdef RC2
|
||||
register_cipher (&rc2_desc);
|
||||
#endif
|
||||
#ifdef DES
|
||||
register_cipher (&des_desc);
|
||||
register_cipher (&des3_desc);
|
||||
#endif
|
||||
#ifdef CAST5
|
||||
register_cipher (&cast5_desc);
|
||||
#endif
|
||||
#ifdef NOEKEON
|
||||
register_cipher (&noekeon_desc);
|
||||
#endif
|
||||
#ifdef SKIPJACK
|
||||
register_cipher (&skipjack_desc);
|
||||
#endif
|
||||
#ifdef ANUBIS
|
||||
register_cipher (&anubis_desc);
|
||||
#endif
|
||||
#ifdef KHAZAD
|
||||
register_cipher (&khazad_desc);
|
||||
#endif
|
||||
|
||||
#ifdef TIGER
|
||||
register_hash (&tiger_desc);
|
||||
#endif
|
||||
#ifdef MD2
|
||||
register_hash (&md2_desc);
|
||||
#endif
|
||||
#ifdef MD4
|
||||
register_hash (&md4_desc);
|
||||
#endif
|
||||
#ifdef MD5
|
||||
register_hash (&md5_desc);
|
||||
#endif
|
||||
#ifdef SHA1
|
||||
register_hash (&sha1_desc);
|
||||
#endif
|
||||
#ifdef SHA224
|
||||
register_hash (&sha224_desc);
|
||||
#endif
|
||||
#ifdef SHA256
|
||||
register_hash (&sha256_desc);
|
||||
#endif
|
||||
#ifdef SHA384
|
||||
register_hash (&sha384_desc);
|
||||
#endif
|
||||
#ifdef SHA512
|
||||
register_hash (&sha512_desc);
|
||||
#endif
|
||||
#ifdef RIPEMD128
|
||||
register_hash (&rmd128_desc);
|
||||
#endif
|
||||
#ifdef RIPEMD160
|
||||
register_hash (&rmd160_desc);
|
||||
#endif
|
||||
#ifdef WHIRLPOOL
|
||||
register_hash (&whirlpool_desc);
|
||||
#endif
|
||||
#ifdef CHC_HASH
|
||||
register_hash(&chc_desc);
|
||||
if ((err = chc_register(register_cipher(&aes_desc))) != CRYPT_OK) {
|
||||
printf("chc_register error: %s\n", error_to_string(err));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_LTM
|
||||
ltc_mp = ltm_desc;
|
||||
#elif defined(USE_TFM)
|
||||
ltc_mp = tfm_desc;
|
||||
#elif defined(USE_GMP)
|
||||
ltc_mp = gmp_desc;
|
||||
#else
|
||||
extern ltc_math_descriptor EXT_MATH_LIB;
|
||||
ltc_mp = EXT_MATH_LIB;
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
void hash_gen(void)
|
||||
{
|
||||
unsigned char md[MAXBLOCKSIZE], *buf;
|
||||
unsigned long outlen, x, y, z;
|
||||
FILE *out;
|
||||
int err;
|
||||
|
||||
|
||||
out = fopen("hash_tv.txt", "w");
|
||||
if (out == NULL) {
|
||||
perror("can't open hash_tv");
|
||||
}
|
||||
|
||||
|
||||
fprintf(out, "Hash Test Vectors:\n\nThese are the hashes of nn bytes '00 01 02 03 .. (nn-1)'\n\n");
|
||||
for (x = 0; hash_descriptor[x].name != NULL; x++) {
|
||||
buf = XMALLOC(2 * hash_descriptor[x].blocksize + 1);
|
||||
@@ -160,16 +56,16 @@ void cipher_gen(void)
|
||||
int err, kl, lastkl;
|
||||
FILE *out;
|
||||
symmetric_key skey;
|
||||
|
||||
|
||||
out = fopen("cipher_tv.txt", "w");
|
||||
|
||||
fprintf(out,
|
||||
|
||||
fprintf(out,
|
||||
"Cipher Test Vectors\n\nThese are test encryptions with key of nn bytes '00 01 02 03 .. (nn-1)' and original PT of the same style.\n"
|
||||
"The output of step N is used as the key and plaintext for step N+1 (key bytes repeated as required to fill the key)\n\n");
|
||||
|
||||
|
||||
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
||||
fprintf(out, "Cipher: %s\n", cipher_descriptor[x].name);
|
||||
|
||||
|
||||
/* three modes, smallest, medium, large keys */
|
||||
lastkl = 10000;
|
||||
for (y = 0; y < 3; y++) {
|
||||
@@ -199,7 +95,7 @@ void cipher_gen(void)
|
||||
printf("setup error: %s\n", error_to_string(err));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
for (z = 0; (int)z < cipher_descriptor[x].block_length; z++) {
|
||||
pt[z] = (unsigned char)z;
|
||||
}
|
||||
@@ -226,7 +122,7 @@ void cipher_gen(void)
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
fclose(out);
|
||||
}
|
||||
}
|
||||
|
||||
void hmac_gen(void)
|
||||
{
|
||||
@@ -234,17 +130,17 @@ void hmac_gen(void)
|
||||
int x, y, z, err;
|
||||
FILE *out;
|
||||
unsigned long len;
|
||||
|
||||
|
||||
out = fopen("hmac_tv.txt", "w");
|
||||
|
||||
fprintf(out,
|
||||
fprintf(out,
|
||||
"HMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are HMACed. The initial key is\n"
|
||||
"of the same format (the same length as the HASH output size). The HMAC key in step N+1 is the HMAC output of\n"
|
||||
"step N.\n\n");
|
||||
|
||||
for (x = 0; hash_descriptor[x].name != NULL; x++) {
|
||||
fprintf(out, "HMAC-%s\n", hash_descriptor[x].name);
|
||||
|
||||
|
||||
/* initial key */
|
||||
for (y = 0; y < (int)hash_descriptor[x].hashsize; y++) {
|
||||
key[y] = (y&255);
|
||||
@@ -255,7 +151,7 @@ void hmac_gen(void)
|
||||
perror("Can't malloc memory");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
for (y = 0; y <= (int)(hash_descriptor[x].blocksize * 2); y++) {
|
||||
for (z = 0; z < y; z++) {
|
||||
input[z] = (unsigned char)(z & 255);
|
||||
@@ -279,17 +175,18 @@ void hmac_gen(void)
|
||||
}
|
||||
fclose(out);
|
||||
}
|
||||
|
||||
|
||||
void omac_gen(void)
|
||||
{
|
||||
#ifdef LTC_OMAC
|
||||
unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
|
||||
int err, x, y, z, kl;
|
||||
FILE *out;
|
||||
unsigned long len;
|
||||
|
||||
|
||||
out = fopen("omac_tv.txt", "w");
|
||||
|
||||
fprintf(out,
|
||||
fprintf(out,
|
||||
"OMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are OMAC'ed. The initial key is\n"
|
||||
"of the same format (length specified per cipher). The OMAC key in step N+1 is the OMAC output of\n"
|
||||
"step N (repeated as required to fill the array).\n\n");
|
||||
@@ -304,12 +201,12 @@ void omac_gen(void)
|
||||
kl = cipher_descriptor[x].max_key_length;
|
||||
}
|
||||
fprintf(out, "OMAC-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
|
||||
|
||||
|
||||
/* initial key/block */
|
||||
for (y = 0; y < kl; y++) {
|
||||
key[y] = (y & 255);
|
||||
}
|
||||
|
||||
|
||||
for (y = 0; y <= (int)(cipher_descriptor[x].block_length*2); y++) {
|
||||
for (z = 0; z < y; z++) {
|
||||
input[z] = (unsigned char)(z & 255);
|
||||
@@ -333,20 +230,22 @@ void omac_gen(void)
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
fclose(out);
|
||||
#endif
|
||||
}
|
||||
|
||||
void pmac_gen(void)
|
||||
{
|
||||
#ifdef LTC_PMAC
|
||||
unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
|
||||
int err, x, y, z, kl;
|
||||
FILE *out;
|
||||
unsigned long len;
|
||||
|
||||
|
||||
out = fopen("pmac_tv.txt", "w");
|
||||
|
||||
fprintf(out,
|
||||
"PMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are OMAC'ed. The initial key is\n"
|
||||
"of the same format (length specified per cipher). The OMAC key in step N+1 is the OMAC output of\n"
|
||||
fprintf(out,
|
||||
"PMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are PMAC'ed. The initial key is\n"
|
||||
"of the same format (length specified per cipher). The PMAC key in step N+1 is the PMAC output of\n"
|
||||
"step N (repeated as required to fill the array).\n\n");
|
||||
|
||||
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
||||
@@ -359,12 +258,12 @@ void pmac_gen(void)
|
||||
kl = cipher_descriptor[x].max_key_length;
|
||||
}
|
||||
fprintf(out, "PMAC-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
|
||||
|
||||
|
||||
/* initial key/block */
|
||||
for (y = 0; y < kl; y++) {
|
||||
key[y] = (y & 255);
|
||||
}
|
||||
|
||||
|
||||
for (y = 0; y <= (int)(cipher_descriptor[x].block_length*2); y++) {
|
||||
for (z = 0; z < y; z++) {
|
||||
input[z] = (unsigned char)(z & 255);
|
||||
@@ -388,13 +287,15 @@ void pmac_gen(void)
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
fclose(out);
|
||||
#endif
|
||||
}
|
||||
|
||||
void eax_gen(void)
|
||||
{
|
||||
#ifdef LTC_EAX_MODE
|
||||
int err, kl, x, y1, z;
|
||||
FILE *out;
|
||||
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], header[MAXBLOCKSIZE*2],
|
||||
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], header[MAXBLOCKSIZE*2],
|
||||
plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
|
||||
unsigned long len;
|
||||
|
||||
@@ -418,7 +319,7 @@ void eax_gen(void)
|
||||
for (z = 0; z < kl; z++) {
|
||||
key[z] = (z & 255);
|
||||
}
|
||||
|
||||
|
||||
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
|
||||
for (z = 0; z < y1; z++) {
|
||||
plaintext[z] = (unsigned char)(z & 255);
|
||||
@@ -448,13 +349,15 @@ void eax_gen(void)
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
fclose(out);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ocb_gen(void)
|
||||
{
|
||||
#ifdef LTC_OCB_MODE
|
||||
int err, kl, x, y1, z;
|
||||
FILE *out;
|
||||
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
|
||||
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
|
||||
plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
|
||||
unsigned long len;
|
||||
|
||||
@@ -483,7 +386,7 @@ void ocb_gen(void)
|
||||
for (z = 0; z < cipher_descriptor[x].block_length; z++) {
|
||||
nonce[z] = z;
|
||||
}
|
||||
|
||||
|
||||
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
|
||||
for (z = 0; z < y1; z++) {
|
||||
plaintext[z] = (unsigned char)(z & 255);
|
||||
@@ -511,14 +414,81 @@ void ocb_gen(void)
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
fclose(out);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ocb3_gen(void)
|
||||
{
|
||||
#ifdef LTC_OCB3_MODE
|
||||
int err, kl, x, y1, z, noncelen;
|
||||
FILE *out;
|
||||
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
|
||||
plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
|
||||
unsigned long len;
|
||||
|
||||
out = fopen("ocb3_tv.txt", "w");
|
||||
fprintf(out, "OCB3 Test Vectors. Uses the 00010203...NN-1 pattern for nonce/plaintext/key. The outputs\n"
|
||||
"are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n"
|
||||
"step repeated sufficiently. The nonce is fixed throughout. AAD is fixed to 3 bytes (ASCII) 'AAD'.\n\n");
|
||||
|
||||
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
||||
kl = cipher_descriptor[x].block_length;
|
||||
|
||||
/* skip ciphers which do not have 64 or 128 bit block sizes */
|
||||
if (kl != 16) continue;
|
||||
|
||||
if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
|
||||
kl = cipher_descriptor[x].max_key_length;
|
||||
}
|
||||
fprintf(out, "OCB3-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
|
||||
|
||||
/* the key */
|
||||
for (z = 0; z < kl; z++) {
|
||||
key[z] = (z & 255);
|
||||
}
|
||||
|
||||
/* fixed nonce */
|
||||
noncelen = MIN(15, cipher_descriptor[x].block_length);
|
||||
for (z = 0; z < noncelen; z++) {
|
||||
nonce[z] = z;
|
||||
}
|
||||
|
||||
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
|
||||
for (z = 0; z < y1; z++) {
|
||||
plaintext[z] = (unsigned char)(z & 255);
|
||||
}
|
||||
len = 16;
|
||||
if ((err = ocb3_encrypt_authenticate_memory(x, key, kl, nonce, noncelen, (unsigned char*)"AAD", 3, plaintext, y1, plaintext, tag, &len)) != CRYPT_OK) {
|
||||
printf("Error OCB3'ing: %s\n", error_to_string(err));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
fprintf(out, "%3d: ", y1);
|
||||
for (z = 0; z < y1; z++) {
|
||||
fprintf(out, "%02X", plaintext[z]);
|
||||
}
|
||||
fprintf(out, ", ");
|
||||
for (z = 0; z <(int)len; z++) {
|
||||
fprintf(out, "%02X", tag[z]);
|
||||
}
|
||||
fprintf(out, "\n");
|
||||
|
||||
/* forward the key */
|
||||
for (z = 0; z < kl; z++) {
|
||||
key[z] = tag[z % len];
|
||||
}
|
||||
}
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
fclose(out);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ccm_gen(void)
|
||||
{
|
||||
#ifdef LTC_CCM_MODE
|
||||
int err, kl, x, y1, z;
|
||||
FILE *out;
|
||||
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
|
||||
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
|
||||
plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
|
||||
unsigned long len;
|
||||
|
||||
@@ -547,7 +517,7 @@ void ccm_gen(void)
|
||||
for (z = 0; z < cipher_descriptor[x].block_length; z++) {
|
||||
nonce[z] = z;
|
||||
}
|
||||
|
||||
|
||||
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
|
||||
for (z = 0; z < y1; z++) {
|
||||
plaintext[z] = (unsigned char)(z & 255);
|
||||
@@ -557,6 +527,10 @@ void ccm_gen(void)
|
||||
printf("Error CCM'ing: %s\n", error_to_string(err));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (len == 0) {
|
||||
printf("Error CCM'ing: zero length\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
fprintf(out, "%3d: ", y1);
|
||||
for (z = 0; z < y1; z++) {
|
||||
fprintf(out, "%02X", plaintext[z]);
|
||||
@@ -575,10 +549,12 @@ void ccm_gen(void)
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
fclose(out);
|
||||
#endif
|
||||
}
|
||||
|
||||
void gcm_gen(void)
|
||||
{
|
||||
#ifdef LTC_GCM_MODE
|
||||
int err, kl, x, y1, z;
|
||||
FILE *out;
|
||||
unsigned char key[MAXBLOCKSIZE], plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
|
||||
@@ -604,8 +580,8 @@ void gcm_gen(void)
|
||||
for (z = 0; z < kl; z++) {
|
||||
key[z] = (z & 255);
|
||||
}
|
||||
|
||||
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
|
||||
|
||||
for (y1 = 1; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
|
||||
for (z = 0; z < y1; z++) {
|
||||
plaintext[z] = (unsigned char)(z & 255);
|
||||
}
|
||||
@@ -614,6 +590,10 @@ void gcm_gen(void)
|
||||
printf("Error GCM'ing: %s\n", error_to_string(err));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (len == 0) {
|
||||
printf("Error GCM'ing: zero length\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
fprintf(out, "%3d: ", y1);
|
||||
for (z = 0; z < y1; z++) {
|
||||
fprintf(out, "%02X", plaintext[z]);
|
||||
@@ -632,19 +612,20 @@ void gcm_gen(void)
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
fclose(out);
|
||||
#endif
|
||||
}
|
||||
|
||||
void base64_gen(void)
|
||||
{
|
||||
FILE *out;
|
||||
unsigned char dst[256], src[32];
|
||||
unsigned long x, y, len;
|
||||
|
||||
unsigned char dst[256], src[32], ch;
|
||||
unsigned long x, len;
|
||||
|
||||
out = fopen("base64_tv.txt", "w");
|
||||
fprintf(out, "Base64 vectors. These are the base64 encodings of the strings 00,01,02...NN-1\n\n");
|
||||
for (x = 0; x <= 32; x++) {
|
||||
for (y = 0; y < x; y++) {
|
||||
src[y] = y;
|
||||
for (ch = 0; ch < x; ch++) {
|
||||
src[ch] = ch;
|
||||
}
|
||||
len = sizeof(dst);
|
||||
base64_encode(src, x, dst, &len);
|
||||
@@ -681,7 +662,7 @@ void ecc_gen(void)
|
||||
mp_read_radix(modulus, (char *)ltc_ecc_sets[x].prime, 16);
|
||||
mp_read_radix(G->x, (char *)ltc_ecc_sets[x].Gx, 16);
|
||||
mp_read_radix(G->y, (char *)ltc_ecc_sets[x].Gy, 16);
|
||||
mp_set(G->z, 1);
|
||||
mp_set(G->z, 1);
|
||||
|
||||
while (mp_cmp(k, order) == LTC_MP_LT) {
|
||||
ltc_mp.ecc_ptmul(k, G, R, modulus, 1);
|
||||
@@ -699,11 +680,12 @@ void ecc_gen(void)
|
||||
|
||||
void lrw_gen(void)
|
||||
{
|
||||
#ifdef LTC_LRW_MODE
|
||||
FILE *out;
|
||||
unsigned char tweak[16], key[16], iv[16], buf[1024];
|
||||
int x, y, err;
|
||||
symmetric_LRW lrw;
|
||||
|
||||
|
||||
/* initialize default key and tweak */
|
||||
for (x = 0; x < 16; x++) {
|
||||
tweak[x] = key[x] = iv[x] = x;
|
||||
@@ -760,27 +742,61 @@ void lrw_gen(void)
|
||||
lrw_done(&lrw);
|
||||
}
|
||||
fclose(out);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
reg_algs();
|
||||
register_all_ciphers();
|
||||
register_all_hashes();
|
||||
register_all_prngs();
|
||||
#ifdef USE_LTM
|
||||
ltc_mp = ltm_desc;
|
||||
#elif defined(USE_TFM)
|
||||
ltc_mp = tfm_desc;
|
||||
#elif defined(USE_GMP)
|
||||
ltc_mp = gmp_desc;
|
||||
#elif defined(EXT_MATH_LIB)
|
||||
extern ltc_math_descriptor EXT_MATH_LIB;
|
||||
ltc_mp = EXT_MATH_LIB;
|
||||
#else
|
||||
fprintf(stderr, "No MPI provider available\n");
|
||||
exit(EXIT_FAILURE);
|
||||
#endif
|
||||
|
||||
printf("Generating hash vectors..."); fflush(stdout); hash_gen(); printf("done\n");
|
||||
printf("Generating cipher vectors..."); fflush(stdout); cipher_gen(); printf("done\n");
|
||||
printf("Generating HMAC vectors..."); fflush(stdout); hmac_gen(); printf("done\n");
|
||||
#ifdef LTC_OMAC
|
||||
printf("Generating OMAC vectors..."); fflush(stdout); omac_gen(); printf("done\n");
|
||||
#endif
|
||||
#ifdef LTC_PMAC
|
||||
printf("Generating PMAC vectors..."); fflush(stdout); pmac_gen(); printf("done\n");
|
||||
#endif
|
||||
#ifdef LTC_EAX_MODE
|
||||
printf("Generating EAX vectors..."); fflush(stdout); eax_gen(); printf("done\n");
|
||||
#endif
|
||||
#ifdef LTC_OCB_MODE
|
||||
printf("Generating OCB vectors..."); fflush(stdout); ocb_gen(); printf("done\n");
|
||||
#endif
|
||||
#ifdef LTC_OCB3_MODE
|
||||
printf("Generating OCB3 vectors..."); fflush(stdout); ocb3_gen(); printf("done\n");
|
||||
#endif
|
||||
#ifdef LTC_CCM_MODE
|
||||
printf("Generating CCM vectors..."); fflush(stdout); ccm_gen(); printf("done\n");
|
||||
#endif
|
||||
#ifdef LTC_GCM_MODE
|
||||
printf("Generating GCM vectors..."); fflush(stdout); gcm_gen(); printf("done\n");
|
||||
#endif
|
||||
printf("Generating BASE64 vectors..."); fflush(stdout); base64_gen(); printf("done\n");
|
||||
printf("Generating MATH vectors..."); fflush(stdout); math_gen(); printf("done\n");
|
||||
printf("Generating ECC vectors..."); fflush(stdout); ecc_gen(); printf("done\n");
|
||||
#ifdef LTC_LRW_MODE
|
||||
printf("Generating LRW vectors..."); fflush(stdout); lrw_gen(); printf("done\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/demos/tv_gen.c,v $ */
|
||||
/* $Revision: 1.15 $ */
|
||||
/* $Date: 2006/06/09 22:10:27 $ */
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
2430
libtomcrypt/doc/Doxyfile
Normal file
2430
libtomcrypt/doc/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
BIN
libtomcrypt/doc/libtomsm.png
Normal file
BIN
libtomcrypt/doc/libtomsm.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
63
libtomcrypt/doc/makefile
Normal file
63
libtomcrypt/doc/makefile
Normal file
@@ -0,0 +1,63 @@
|
||||
ifeq ($V,1)
|
||||
silent=
|
||||
silent_stdout=
|
||||
else
|
||||
silent=@
|
||||
silent_stdout= > /dev/null
|
||||
endif
|
||||
|
||||
#Files left over from making the crypt.pdf.
|
||||
LEFTOVERS=*.dvi *.log *.aux *.toc *.idx *.ilg *.ind *.out *.lof
|
||||
|
||||
#build the doxy files (requires Doxygen, tetex and patience)
|
||||
.PHONY: doxygen
|
||||
doxygen:
|
||||
doxygen $(silent_stdout)
|
||||
|
||||
patched_doxygen:
|
||||
(cat Doxyfile && echo "HAVE_DOT=no") | doxygen - $(silent_stdout)
|
||||
|
||||
doxy: patched_doxygen
|
||||
${MAKE} -C doxygen/latex $(silent_stdout) && mv -f doxygen/latex/refman.pdf .
|
||||
@echo The huge doxygen PDF should be available as doc/refman.pdf
|
||||
|
||||
#This builds the crypt.pdf file. Note that the rm -f *.pdf has been removed
|
||||
#from the clean command! This is because most people would like to keep the
|
||||
#nice pre-compiled crypt.pdf that comes with libtomcrypt! We only need to
|
||||
#delete it if we are rebuilding it.
|
||||
docs crypt.pdf: crypt.tex
|
||||
rm -f crypt.pdf $(LEFTOVERS)
|
||||
cp crypt.tex crypt.bak
|
||||
touch -r crypt.tex crypt.bak
|
||||
(printf "%s" "\def\fixedpdfdate{"; date +'D:%Y%m%d%H%M%S%:z' -d @$$(stat --format=%Y crypt.tex) | sed "s/:\([0-9][0-9]\)$$/'\1'}/g") > crypt-deterministic.tex
|
||||
printf "%s\n" "\pdfinfo{" >> crypt-deterministic.tex
|
||||
printf "%s\n" " /CreationDate (\fixedpdfdate)" >> crypt-deterministic.tex
|
||||
printf "%s\n}\n" " /ModDate (\fixedpdfdate)" >> crypt-deterministic.tex
|
||||
cat crypt.tex >> crypt-deterministic.tex
|
||||
mv crypt-deterministic.tex crypt.tex
|
||||
touch -r crypt.bak crypt.tex
|
||||
echo "hello" > crypt.ind
|
||||
latex crypt $(silent_stdout)
|
||||
latex crypt $(silent_stdout)
|
||||
makeindex crypt.idx $(silent_stdout)
|
||||
perl ../helper.pl --fixupind crypt.ind
|
||||
pdflatex crypt $(silent_stdout)
|
||||
sed -b -i 's,^/ID \[.*\]$$,/ID [<0> <0>],g' crypt.pdf
|
||||
mv crypt.bak crypt.tex
|
||||
rm -f $(LEFTOVERS)
|
||||
|
||||
docdvi: crypt.tex
|
||||
echo hello > crypt.ind
|
||||
latex crypt $(silent_stdout)
|
||||
latex crypt $(silent_stdout)
|
||||
makeindex crypt.idx
|
||||
perl ../helper.pl --fixupind crypt.ind
|
||||
latex crypt $(silent_stdout)
|
||||
latex crypt $(silent_stdout)
|
||||
|
||||
termdoc: docdvi
|
||||
dvi2tty crypt.dvi -w120
|
||||
|
||||
clean:
|
||||
rm -f $(LEFTOVERS)
|
||||
rm -rf doxygen/
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user