Skip to content

Commit 534cd74

Browse files
committed
Switch from blake2b to sha256 checksum
Future proof by popularity.
1 parent cc0bab5 commit 534cd74

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

paperbackup-verify.sh

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,29 @@
44
# where backup.pdf should be the pdf created with paperbackup.py
55

66
RESTOREPROG=$(dirname $0)/paperrestore.sh
7-
PAPERB2SUMPROG="$(dirname $0)/paperbackup.py --b2sum"
87

9-
rPDF=$( $RESTOREPROG $1 )
10-
11-
bPDF=$(echo "$rPDF" | $PAPERB2SUMPROG )
12-
bEmbedded=$(pdftotext $1 - | grep b2sum -A2 | tail -2 | tr -d '\n')
8+
bPDF=$( $RESTOREPROG $1 | sha256sum | cut -d ' ' -f 1)
9+
bEmbedded=$(pdftotext $1 - | grep sha256sum -A1 | tail -1 | tr -d '\n')
1310

1411
if [ "x$bPDF" == "x$bEmbedded" ]; then
15-
echo "b2sums MATCH :-)"
12+
echo "sha256sums MATCH :-)"
1613
echo
1714
exit 0
1815
else
1916
echo "Creating diff:"
20-
echo "$rPDF" | diff ${1%.*} -
17+
$RESTOREPROG $1 | diff ${1%.*} -
2118
diffret=$?
2219
echo
2320
if [ $diffret -ne 0 ]; then
24-
echo "diff and b2sums do NOT match!"
25-
echo "restored b2sum from PDF: " $bPDF
26-
echo "original b2sum embedded: " $bEmbedded
21+
echo "diff and sha256sums do NOT match!"
22+
echo "restored sha256sum from PDF: " $bPDF
23+
echo "original sha256sum embedded: " $bEmbedded
2724
echo
2825
exit 11
2926
else
30-
echo "diff matches but b2sum is missing."
27+
echo "diff matches but sha256sum is missing."
28+
echo "restored sha256sum from PDF: " $bPDF
29+
echo "original sha256sum embedded: " $bEmbedded
3130
echo
3231
exit 1
3332
fi

paperbackup.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import qrencode
3636
from tempfile import mkstemp
3737
from datetime import datetime
38-
from shutil import which
3938
from PIL import Image
4039
from pyx import *
4140

@@ -71,15 +70,6 @@ def finish_page(pdf, canv, pageno):
7170

7271
# main code
7372

74-
if sys.argv[1] == "--b2sum":
75-
if len(sys.argv) > 2:
76-
with open(sys.argv[2], 'r') as ifile:
77-
data = ''.join(ifile.readlines())
78-
else:
79-
data = ''.join(sys.stdin.readlines())
80-
print(hashlib.blake2b(bytes(data, 'utf8')).hexdigest())
81-
sys.exit(0)
82-
8373
if len(sys.argv) != 2:
8474
raise RuntimeError('Usage {} FILENAME.asc'.format(sys.argv[0]))
8575

@@ -182,7 +172,7 @@ def finish_page(pdf, canv, pageno):
182172
chksumlines.append(line)
183173

184174
# we also want a checksum which the restored file should match
185-
b2sum = hashlib.blake2b(bytes(ascdata, 'utf8')).hexdigest()
175+
checksum = hashlib.sha256(bytes(ascdata, 'utf8')).hexdigest()
186176

187177
# add some documentation around the plaintest
188178
outlines=[]
@@ -192,9 +182,8 @@ def finish_page(pdf, canv, pageno):
192182
outlines.extend(chksumlines)
193183
outlines.append("")
194184
outlines.append("")
195-
outlines.append("b2sum of input file (split over 2 lines):")
196-
outlines.append("%s"%b2sum[:64])
197-
outlines.append("%s"%b2sum[64:])
185+
outlines.append("sha256sum of input file:")
186+
outlines.append("%s"%checksum)
198187
outlines.append("")
199188
outlines.append("")
200189
outlines.append("--")

0 commit comments

Comments
 (0)