Skip to content

Commit ef736e0

Browse files
author
8go
authored
changed hash iterations
1 parent 459a75d commit ef736e0

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

gpg-encrypt-twice-symmetrically.sh

+32-15
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
# If this software does not suit you, here are some alternative pieces of
77
# software that are very similar:
8-
# age <https://github.com/FiloSottile/age
9-
# rage <https://github.com/str4d/rage
8+
# scrypt https://www.tarsnap.com/scrypt.html
9+
# age https://github.com/FiloSottile/age
10+
# rage https://github.com/str4d/rage
1011
# https://github.com/SixArm/gpg-encrypt
1112
# https://github.com/SixArm/gpg-decrypt
1213
# https://github.com/SixArm/openssl-encrypt
@@ -43,10 +44,12 @@ TMP="tmp" # to indicate temporary file
4344
MAX_FILESIZE_FOR_QR=4096 # if the output file is larger than that no QR code will be produced
4445
UMASK_ORIGINAL=$(umask) # the original umask value, for later restoring
4546
UMASK_READONLY="0377" # created files (will be r--)
46-
# SHA_HASH_ITERATIONS: --s2k-count allowed values/range: 1024-65011712
47+
# SHA_HASH_ITERATIONS: --s2k-count allowed values/range: 1024-65011712, 65011712 is a firm maximum
4748
# SHA_HASH_ITERATIONS: --s2k-count default is 37748736, set by gpg-agent
4849
# SHA_HASH_ITERATIONS: --s2k-count 65011712 roughly 0.2 sec on basic average 2020 CPU, tested
49-
SHA_HASH_ITERATIONS_RECOMMENDED=65011712 # 65M
50+
# We use a number close to the Max, but not exactly Max,
51+
# just in case there is or will be a rainbow table for Max iterations
52+
SHA_HASH_ITERATIONS_RECOMMENDED=65011601 # 65M
5053
SHA_HASH_ITERATIONS=$SHA_HASH_ITERATIONS_RECOMMENDED # 65M
5154
# SHA_HASH_ITERATIONS=65011712 # 65M # for testing only
5255
# HASHING_TIME_IN_SEC=$(expr $SHA_HASH_ITERATIONS / 325000000) # estimate for moderate CPU in 2020, negligable so we don't use/print it
@@ -62,7 +65,7 @@ PASSPHRASE_FILE_TWOFISH_OPTION="--batch --passphrase-file $PASSPHRASE_FILE_TWOFI
6265

6366
# usage: outputs to stdout the --help usage message.
6467
usage() {
65-
echo "${0##*/}: Version: v2020-09-30"
68+
echo "${0##*/}: Version: v2020-11-02"
6669
echo "${0##*/}: Usage: ${0##*/} [--help] [--encrypt|--decrypt] files"
6770
echo "${0##*/}: e.g. ${0##*/} file1.txt file2.jpg # encrypt 2 files"
6871
echo "${0##*/}: e.g. ${0##*/} # read from stdin, encrypt text from stdin input"
@@ -81,11 +84,11 @@ usage() {
8184
echo "${0##*/}: If no file is provided as command line argument, script will read "
8285
echo "${0##*/}: plain-text from std input."
8386
echo "${0##*/}: "
84-
echo "${0##*/}: If a file named \"passphrase-file-aes\" exists in the local"
87+
echo "${0##*/}: If a file named \"$PASSPHRASE_FILE_AES_FILE\" exists in the local"
8588
echo "${0##*/}: directory, then it will be used as passphrase source instead of stdin"
8689
echo "${0##*/}: for the AES-round (first round) of encryption."
8790
echo "${0##*/}: "
88-
echo "${0##*/}: If a file named \"passphrase-file-twofish\" exists in the local"
91+
echo "${0##*/}: If a file named \"$PASSPHRASE_FILE_TWOFISH_FILE\" exists in the local"
8992
echo "${0##*/}: directory, then it will be used as passphrase source instead of stdin"
9093
echo "${0##*/}: for the TwoFish-round (second round) of encryption."
9194
echo "${0##*/}: "
@@ -97,9 +100,10 @@ usage() {
97100
echo "${0##*/}: Decrypt does the opposite. It recovers the plaintext from the ciphertext."
98101
echo "${0##*/}: TLDR: The whole decryption script in a nutshell does the 3 lines of code from above in the reverse order but with --decrypt instead of --symmetric."
99102
echo ""
100-
echo ""
101-
echo "Typical encryption process looks similar to this: "
102-
cat << END
103+
if [ "$DEBUG" == "true" ]; then
104+
echo ""
105+
echo "Typical encryption process looks similar to this: "
106+
cat << END
103107
$ ./${0##*/}
104108
${0##*/}: Verified that version 2 of GPG is installed. Passed check.
105109
${0##*/}: Install latest version of "gpg" (version 2), "sha512sum", "shred" and "qrencode"!
@@ -126,7 +130,7 @@ ${0##*/}: Starting command: gpg \
126130
--pinentry-mode loopback \
127131
--no-symkey-cache \
128132
--output "ciphertext.tmp.enc" \
129-
"-" # no --armor
133+
"-"
130134
secret text
131135
${0##*/}: Success: gpg encrypted file "-" successfully.
132136
${0##*/}: Starting command: gpg \
@@ -157,6 +161,7 @@ ${0##*/}: QR codes are in files "ciphertext.png" and "ciphertext.svg"
157161
${0##*/}: Metadata is in file "ciphertext.inf".
158162
${0##*/}: SUCCESS! Look at ciphertext output in file "ciphertext.enc".
159163
END
164+
fi
160165
} # usage()
161166

162167
# takes 1 optional argument, the return value, the exit value
@@ -185,11 +190,13 @@ read-passphrase-files-if-availble() {
185190
if [ -f "$PASSPHRASE_FILE_AES_FILE" ]; then
186191
echo "${0##*/}: Info: Found file \"$PASSPHRASE_FILE_AES_FILE\". It will be used as source for the AES passphrase. You will not be asked for a passphrase for AES $1."
187192
else
193+
echo "${0##*/}: Info: File \"$PASSPHRASE_FILE_AES_FILE\" not found. It cannot be used as source for the AES passphrase. You will be asked for a passphrase for AES $1."
188194
PASSPHRASE_FILE_AES_OPTION="" # don't use this option
189195
fi
190196
if [ -f "$PASSPHRASE_FILE_TWOFISH_FILE" ]; then
191197
echo "${0##*/}: Info: Found file \"$PASSPHRASE_FILE_TWOFISH_FILE\". It will be used as source for the TwoFish passphrase. You will not be asked for a passphrase for TwoFish $1."
192198
else
199+
echo "${0##*/}: Info: File \"$PASSPHRASE_FILE_TWOFISH_FILE\" not found. It cannot be used as source for the TwoFish passphrase. You will be asked for a passphrase for TwoFish $1."
193200
PASSPHRASE_FILE_TWOFISH_OPTION="" # don't use this option
194201
fi
195202
}
@@ -524,12 +531,12 @@ esac
524531
case "$1" in
525532
--help | --hel | --he | --h | -help | -hel | -he | -h)
526533
usage
527-
cleanup_exit 0
528-
;; # success
534+
exit 0 # no cleanup needed
535+
;; # success
529536
--version | --versio | --versi | --vers | --ver | --ve | --v | -version | -versio | -versi | -vers | -ver | -ve | -v)
530537
usage
531-
cleanup_exit 0
532-
;; # success
538+
exit 0 # no cleanup needed
539+
;; # success
533540
esac
534541

535542
# give some guidance, summary
@@ -583,4 +590,14 @@ for i in "$@"; do
583590
fi
584591
done
585592

593+
# This code is just useful if script is kicked off via GUI such as file manager
594+
# Not needed when used in terminal.
595+
#if [ "${FILESLASHSLASHUSED}" -eq "1" ]; then
596+
# echo "${0##*/}: Done. Close window please by clicking X in top right window corner."
597+
#else
598+
# echo -n "${0##*/}: Hit any key to continue ... "
599+
#fi
600+
#read YESNO
601+
586602
cleanup_exit 0 # success
603+
# EOF

0 commit comments

Comments
 (0)