def decodeInvitePacket(self, password, packet): #print('decodeInvitePacket('+password+', '+encode(packet)+')') self.salt, packet=splitField(packet, SALT_LENGTH) #print('salt('+encode(self.salt)+', '+encode(packet)+')') sk=pbkdf(password, self.salt) #print('sk: '+encode(sk)) self.decodeDustPacket(sk, packet) self.invite=InviteMessage() self.invite.decodeInviteMessage(self.data) return self.invite
def getBytes(self, n): self.count=self.count+n while len(self.entropy)<n: if self.pers: result=skein512(self.iv, mac=self.key, pers=self.pers, digest_bits=(BLOCK_SIZE)*8) else: result=skein512(self.iv, mac=self.key, digest_bits=(BLOCK_SIZE)*8) self.entropy=self.entropy+result self.iv=result b, self.entropy=splitField(self.entropy, n) return b
def decodeInvitePacket(self, password, packet): #print('decodeInvitePacket('+password+', '+encode(packet)+')') self.salt, packet = splitField(packet, SALT_LENGTH) #print('salt('+encode(self.salt)+', '+encode(packet)+')') sk = pbkdf(password, self.salt) #print('sk: '+encode(sk)) self.decodeDustPacket(sk, packet) self.invite = InviteMessage() self.invite.decodeInviteMessage(self.data) return self.invite
def decodeDustPacket(self, key, packet): self.key=key self.packet=packet self.mac, self.ciphertext=splitField(self.packet, MAC_SIZE) self.iv, self.encrypted=splitField(self.ciphertext, IV_SIZE) self.payload=decrypt(self.key, self.iv, self.encrypted) self.timestamp, self.dataLength, self.paddingLength, self.data=splitFields(self.payload, [TIMESTAMP_SIZE, DATA_LENGTH_SIZE, PADDING_LENGTH_SIZE]) self.timestamp=struct.unpack("I", self.timestamp)[0] self.dataLength=struct.unpack("H", self.dataLength)[0] self.paddingLength=struct.unpack("B", self.paddingLength)[0] self.data, extra=splitField(self.data, self.dataLength) payloadLength=TIMESTAMP_SIZE+DATA_LENGTH_SIZE+PADDING_LENGTH_SIZE+len(self.data) self.payload=self.payload[:payloadLength] ciphertextLength=IV_SIZE+payloadLength self.ciphertext=self.ciphertext[:ciphertextLength] realPacketLength=MAC_SIZE+ciphertextLength+self.paddingLength if len(packet)>realPacketLength: self.remaining=packet[realPacketLength:]
def getBytes(self, n): self.count = self.count + n while len(self.entropy) < n: if self.pers: result = skein512(self.iv, mac=self.key, pers=self.pers, digest_bits=(BLOCK_SIZE) * 8) else: result = skein512(self.iv, mac=self.key, digest_bits=(BLOCK_SIZE) * 8) self.entropy = self.entropy + result self.iv = result b, self.entropy = splitField(self.entropy, n) return b
def decodeDustmailInvitePacket(self, password, packet): self.salt, packet=splitField(packet, SALT_LENGTH) sk=pbkdf(password, self.salt) self.decodeDustPacket(sk, packet) self.pubkey, self.invite=splitField(self.data, PUBKEY_LENGTH)