"Finite Field Arithmetic." Chapter 20C: Support for 'Clearsigned' GPG texts in "Litmus."
This article is part of a series of hands-on tutorials introducing FFA, or the Finite Field Arithmetic library. FFA differs from the typical "Open Sores" abomination, in that -- rather than trusting the author blindly with their lives -- prospective users are expected to read and fully understand every single line. In exactly the same manner that you would understand and pack your own parachute. The reader will assemble and test a working FFA with his own hands, and at the same time grasp the purpose of each moving part therein.
- Chapter 1: Genesis.
- Chapter 2: Logical and Bitwise Operations.
- Chapter 3: Shifts.
- Chapter 4: Interlude: FFACalc.
- Chapter 5: "Egyptological" Multiplication and Division.
- Chapter 6: "Geological" RSA.
- Chapter 7: "Turbo Egyptians."
- Chapter 8: Interlude: Randomism.
- Chapter 9: "Exodus from Egypt" with Comba's Algorithm.
- Chapter 10: Introducing Karatsuba's Multiplication.
- Chapter 11: Tuning and Unified API.
- Chapter 12A: Karatsuba Redux. (Part 1 of 2)
- Chapter 12B: Karatsuba Redux. (Part 2 of 2)
- Chapter 13: "Width-Measure" and "Quiet Shifts."
- Chapter 14A: Barrett's Modular Reduction. (Part 1 of 2)
- Chapter 14A-Bis: Barrett's Modular Reduction. (Physical Bounds Proof.)
- Chapter 14B: Barrett's Modular Reduction. (Part 2 of 2.)
- Chapter 15: Greatest Common Divisor.
- Chapter 16A: The Miller-Rabin Test.
- Chapter 17: Introduction to Peh.
- Chapter 18A: Subroutines in Peh.
- Chapter 18B: "Cutouts" in Peh.
- Chapter 18C: Peh School: Generation of Cryptographic Primes.
- Chapter 19: Peh Tuning and Demo Tapes.
- Chapter 20: "Litmus", a Peh-Powered Verifier for GPG Signatures.
- Chapter 20B: Support for Selected Ancient Hash Algos in "Litmus."
- Chapter 20C: Support for 'Clearsigned' GPG texts in "Litmus."
You will need:
- A Keccak-based VTron (for this and all subsequent chapters.)
- All of the materials from Chapters 1 - 20B.
- ffa_ch20c_litmus_clearsigned.kv.vpatch
- ffa_ch20c_litmus_clearsigned.kv.vpatch.asciilifeform.sig
Add the above vpatches and seals to your V-set, and press to ffa_ch20c_litmus_clearsigned.kv.vpatch.
As of Chapter 20C, the versions of Peh and FFA are 250 and 253, respectively. FFA and Peh themselves have not changed from Chapter 19.
Compile Peh:
cd ffacalc gprbuild
... and install it to a path visible in your shell (e.g. /usr/bin.)
Litmus now supports GPG "clearsigned" texts. Compatibility with the program given in the previous chapter is retained. The "clearsigned" mode of operation is selected simply by invoking the script with two arguments instead of the usual three:
....... # Whether we are working on a 'clearsigned text' CLEARSIGN_MODE=false # Set up in the selected mode: case $ARGCOUNT in 2) # If given two arguments, verify a 'clearsigned' text file: CLEARSIGN_MODE=true # The processed payload will end up in a temporary file: DATAFILE=$(mktemp) || { echo "Failed to create temp file!" >&2; \ exit $RET_EGGOG; } # On exit, if in 'clearsign' mode, remove temporary file with payload: trap remove_temp_file EXIT # Expect 'Canonical Text Signature' in GPG sig packet turd expect_sig_class=1 ;; 3) # Verify Detached Signature on given Data File (third argument is path): # The given Data file to be verified against the Signature DATAFILE=$3 # i.e. path given on command line # Expect 'Detached Binary Signature' in GPG sig packet turd expect_sig_class=0 ;; *) # If invalid arg count -- print usage and abort: echo "Usage: $0 publickey.peh signature.sig datafile" echo " or: $0 publickey.peh clearsigned.txt" exit $RET_EGGOG ;; esac .......
RFC4880 (the document GPG nominally conforms to) specifies certain transformations required to obtain the hashable payload from the document (e.g. imposition of MSDOS-style line endings) which were implemented as follows:
....... # If we are operating on a 'clearsigned' text file, $DATAFILE will be # an empty temporary file, and the payload is to be extracted to it, ....... if [ $CLEARSIGN_MODE == true ] then # Find position of 'clearsign' payload start marker: CLEAR_MARKER="\-\-\-\-\-BEGIN PGP SIGNED MESSAGE\-\-\-\-\-" start_clr=$(grep -m 1 -n "$CLEAR_MARKER" $SIGFILE | cut -d ':' -f1) # If payload start marker was not found: if [ "$start_clr" == "" ] then eggog_broken_clearsigned fi # Discard the start marker: start_clr=$(($start_clr + 1)) # The payload ends with the line preceding the sig start: end_clr=$((start_ln - 2)) # Find any 'Hash:' headers: start_body=$(tail -n "+$start_clr" $SIGFILE | \ grep -v -n -m 1 "^Hash:" | cut -d ':' -f1) # Skip the above headers and mandatory empty line: start_clr=$(($start_clr + $start_body)) # If there is no payload, or the markers are misplaced, abort: if [ $start_clr -ge $end_clr ] then eggog_broken_clearsigned fi # Extract the 'clearsign' payload to the temporary file: cat $SIGFILE | sed -n "$start_clr,$end_clr p" | \ sed 's/[ \t]*$//; s/^- //' | \ awk '{printf("%s\r\n",$0)}' \ > $DATAFILE # Remove the trailing CR,LF ending: truncate -s -2 $DATAFILE # After this, proceed exactly like with 'detached' sigs, but # with the expected 'class' being 1 rather than 0. fi .......
To verify a "clearsigned" message, invoke Litmus with two arguments: the public key, followed by the input file, e.g.:
./litmus.sh asciilifeform.peh asciilifeform-clearsigned.txt
... which will yield the output:
VALID GPG RSA signature from asciilifeform <stas@loper-os.org>
~To be continued!~
Built and tested:
/home/shinohai/devel/Ada # ./litmus.sh wot/asciilifeform.peh asciilifeform-clearsigned.txt
VALID GPG RSA signature from asciilifeform
Verified clearsigned things from alf, BingoBoingo, and spyked just fine. Litmus test warned perfectly of the sigs from the sad list published previously.
ffa_ch20c_litmus_clearsigned.kv.vpatch.shinohai.sig
-----BEGIN PGP SIGNATURE-----
iQIzBAABCgAdFiEEJg+le85nelwEv2C6SnWIPMGx00wFAl4bSuAACgkQSnWIPMGx
00yliA/7BDS3HUjgEM/4V4cVzDTaHg9Ux6HEPqzYdnKO/FxNgHSNt1CrrK/Yd9HV
OIF88qmAWJhuwv5AIjkpuEb+wLmVwNXsdJwl08gsz3ex1f04mC9mok1++Ehepv08
V96cu3Dpek239Ul/FHwp9AXW2wuzgotM4BgeH7ItPIjoacy00aya8Tyl4gLyOKb3
lZd/hVbiV5yI5KQx8/l8nrnhEMdcRz/TAcvOgCIk+QiyPwgR/TvAMO8bkKxg+1Rw
7ba3gMRhmM2foDRL/KpsWzRnlgh63oEelsmTXA+VjLGHHejl8Up7dgDVQjTaNTrc
8JITxVZHxZXb1xPOyEP5J4KfgH2sYt5N2dgbeojN1Vek9zfzEHfp6FZzjriI2lcQ
mXSVuYdaIzh0iN1cyodYRV312/BgAhPnWD6DU56LRqQcqVAK44aHAhPRlWfGUVWZ
JBaXeCkpw9ciVjriB9WW3kPHPP44FWodkxw2nNLqC5eqd+D5u9WMock0M+DW2u6C
zEE/h+n8yONd7qRLJ04s8ylVwkuYL4YcFBza7XpwbdcCB6SGSqS1ndhKiTyjNATp
uRAZjdxAS8SZ0NY3eR1NiN5vh4MJrIE1y1aAU/IjJ/7aLaU2azZeXZ7MIuoF9Hwz
EWTCLyO6bG8KSiZ5NWAyGWEKTxiKp9uSV2YhZRNyt9vAAhoxfkM=
=NI0T
-----END PGP SIGNATURE-----
Dear shinohai,
Thanks for testing!
Yours,
-S