def fill(self, d):
     """
     """
     self._d = d
     idx = 0
     self.version, idx = STN.strcalc(STN.str2int, d[idx:idx+1], idx)
     self.alg, idx = STN.strcalc(STN.str2int, d[idx:idx+1], idx)
     self.s2k, idx = S2K.strcalc_s2k(d[idx:], idx)
예제 #2
0
파일: SecretKey.py 프로젝트: Zaryob/wubi
    def fill(self, d):
        idx = PublicKeyBody.fill(self, d)
        self._private_idx = idx # marks start of private data

        self.s2k_usg, idx = STN.strcalc(STN.str2int, d[idx:idx+1], idx)

        if 0 == self.s2k_usg: # unencrypted MPIs
            self.__resolve_secmpi(idx)

        else:

            if self.s2k_usg in [254, 255]: # encrypted MPIs
                self.alg_sym, idx = STN.strcalc(STN.str2int, d[idx:idx+1], idx)
                self.s2k, idx = S2K.strcalc_s2k(d[idx:], idx)

                if 0 == self.alg_sym: # plaintext or unencrypted data
                    self.__resolve_secmpi(idx)
                    return
                elif 1 == self.alg_sym: # IDEA [IDEA]
                    self.iv, idx = STN.strcalc(None, d[idx:idx+8], idx)
                elif 2 == self.alg_sym: # Triple-DES DES-EDE, 168 bit key derived from 192
                    raise NotImplementedError, "3DES"
                elif 3 == self.alg_sym: # CAST5 (128 bit key, as per RFC2144)
                    self.iv, idx = STN.strcalc(None, d[idx:idx+8], idx)
                elif 4 == self.alg_sym: # Blowfish (128 bit key, 16 rounds)
                    self.iv, idx = STN.strcalc(None, d[idx:idx+8], idx)
                elif self.alg_sym in [5, 6]: # Reserved
                    raise NotImplementedError, "Reserved"
                elif 7 == self.alg_sym: # AES with 128-bit key [AES]
                    raise NotImplementedError, "AES 128"
                elif 8 == self.alg_sym: # AES with 192-bit key
                    raise NotImplementedError, "AES 192"
                elif 9 == self.alg_sym: # AES with 256-bit key
                    raise NotImplementedError, "AES 256"
                elif 10 == self.alg_sym: # Twofish with 256-bit key [TWOFISH]
                    raise NotImplementedError, "Twofish"
                elif self.alg_sym in range(100, 111): #100-110 Private/Experimental
                    raise NotImplementedError, "Private/Experimental"
                else:
                    raise ValueError, "Unsupported symmetric encryption algorithm->(%s)" % (str(self.alg_sym))

            else: # s2k usage specifies the symmetric algorithm
                self.alg_sym = self.s2k_usg
                self.iv, idx = STN.strcalc(None, d[idx:idx+8], idx)

            # encrypted data: MPIs + chksum/hash
            if 3 == self.version and self.s2k_usg in [254, 255]:
                if 255 == self.s2k_usg: # checksum is stored in the clear
                    self._enc_d = d[:-2]
                    self.chksum = d[-2:]
                elif 254 == self.s2k_usg: # nothing was specifically mentioned
                    self._enc_d = d[:-20] # about SHA1 in v3/RSA keys, but this
                    self.chksum = d[-20:] # should make sense given the above
            else:
                self._enc_d = d[idx:]