ietf-openpgp
[Top] [All Lists]

Re: private key CFB

2003-11-21 01:42:44

Two beginner questions:
..begets at least one beginner's answer:

#1. CFB shifts == the algorithm's block size.
    Blowfish, 3DES, CAST, & IDEA use 8 byte blocks.
    AES (128, 192, 256) and Twofish use 16 byte blocks.

#2. Given the string-to-key parameters:

    Hash algorithm: 2
    Salt: 0x61f8a7c834124c3a 
    Type: 3 
    Count code: 96
    Encryption algorithm: 9
    Passphrase: 'passphrase'

..the resulting string is (previously posted by Michael Young,
seconded by yours truly):
 0x 53 f2 fd a7 69 7d 0b a6 c0 ee 18 4f 89 db 1d f8 
    14 6c d4 ad 36 1b 8c 4e 63 13 ab 68 75 a7 ad 0b 

Grammatically-challenged, I gave up trying to figure out S2K mechanics
using the draft and eventually found a nice code sample at the link
below. I also gave up trying to improve on the documentation which
actually makes a lot more sense once the code is working. :)

My Python-ized version looks something like:

# Given string 'passphrase', string 'salt', integer 'count' (actual
# "big" count, not the "count code"), and integer keysize (16 for
# CAST, Blowfish, and AES128, 24 for 3DES and AES192, and 32 for
# AES256)
# 'hasher' is a magic MD5 or SHA1 hash machine
# len(x) : "length of x"

pos, run, result = 0, 0, ''
while pos < keysize:
    md = [] # reset message digest "hash context" every run
    done = 0
    for i in range(run): # preloaded 0x00s depending on iteration "run"
        md.append('\x00')
    if count < (len(passphrase) + len(salt)):
        count = len(passphrase) + len(salt)
    while (count - done) > (len(passphrase) + len(salt)):
        if (len(salt) > 0):
            md.append(salt)
        md.append(passphrase)
        done = done + len(passphrase) + len(salt)
    for i in range(len(salt)): # "for (i=0; i++; i<=len(salt))"
        if done < count:
            md.append(salt[i]) # byte index of 'salt'
            done += 1
    for i in range(len(passphrase)):
        if done < count:
            md.append(passphrase[i]) 
            done += 1
    hash = hasher.new(''.join(md)).digest() # list joining quirk
    size = len(hash)
    if (pos + size) > keysize:
        size = keysize - pos
    result = ''.join([result[:pos], hash[0:size]]) # quirk again
    pos += size
    run += 1
return result

Best of luck,
the poiboy

CVS source for Cryptix OpenPGP implementation
(file PGPIteratedAndSaltedS2K.java)
http://anoncvs.cryptix.org/co.php/projects/openpgp/src/cryptix/openpgp/algorithm/PGPIteratedAndSaltedS2K.java?r=1.8

<Prev in Thread] Current Thread [Next in Thread>