gpg: fixup imports

nistp521
Roman Zeyde 8 years ago
parent 5506310239
commit 76ce25fab1

@ -2,8 +2,8 @@
import argparse
import functools
import logging
import re
import os
import re
import subprocess
import sys
import time

@ -4,8 +4,8 @@ import base64
import io
import logging
import decode
import util
from . import decode
from .. import util
log = logging.getLogger(__name__)

@ -1,11 +1,9 @@
#!/usr/bin/env python
import sys
import subprocess as sp
import time
import logging
import os
import subprocess as sp
import sys
import signer
from . import signer
log = logging.getLogger(__name__)

@ -9,11 +9,9 @@ import struct
import subprocess
import time
import decode
import trezor_agent.client
import trezor_agent.formats
import trezor_agent.util
import util
from . import decode
from .. import client, factory, formats
from .. import util
log = logging.getLogger(__name__)
@ -79,23 +77,24 @@ def _dump_nist256(vk):
def _dump_ed25519(vk):
return mpi((0x40 << 256) |
trezor_agent.util.bytes2num(vk.to_bytes()))
util.bytes2num(vk.to_bytes()))
SUPPORTED_CURVES = {
trezor_agent.formats.CURVE_NIST256: {
formats.CURVE_NIST256: {
# https://tools.ietf.org/html/rfc6637#section-11
'oid': b'\x2A\x86\x48\xCE\x3D\x03\x01\x07',
'algo_id': 19,
'dump': _dump_nist256
},
trezor_agent.formats.CURVE_ED25519: {
formats.CURVE_ED25519: {
'oid': b'\x2B\x06\x01\x04\x01\xDA\x47\x0F\x01',
'algo_id': 22,
'dump': _dump_ed25519
}
}
def find_curve_by_algo_id(algo_id):
curve_name, = [name for name, info in SUPPORTED_CURVES.items()
if info['algo_id'] == algo_id]
@ -106,19 +105,19 @@ class Signer(object):
def __init__(self, user_id, created, curve_name):
self.user_id = user_id
assert curve_name in trezor_agent.formats.SUPPORTED_CURVES
assert curve_name in formats.SUPPORTED_CURVES
self.curve_name = curve_name
self.client_wrapper = trezor_agent.factory.load()
self.client_wrapper = factory.load()
self.identity = self.client_wrapper.identity_type()
self.identity.proto = 'gpg'
self.identity.host = user_id
addr = trezor_agent.client.get_address(self.identity)
addr = client.get_address(self.identity)
public_node = self.client_wrapper.connection.get_public_node(
n=addr, ecdsa_curve_name=self.curve_name)
self.verifying_key = trezor_agent.formats.decompress_pubkey(
self.verifying_key = formats.decompress_pubkey(
pubkey=public_node.node.public_key,
curve_name=self.curve_name)
@ -185,6 +184,7 @@ class Signer(object):
data_to_sign=msg, hashed_subpackets=hashed_subpackets)
return packet(tag=2, blob=blob)
def _make_signature(self, visual, data_to_sign,
hashed_subpackets, sig_type=0):
curve_info = SUPPORTED_CURVES[self.curve_name]
@ -210,8 +210,8 @@ class Signer(object):
ecdsa_curve_name=self.curve_name)
assert result.signature[:1] == b'\x00'
sig = result.signature[1:]
sig = [trezor_agent.util.bytes2num(sig[:32]),
trezor_agent.util.bytes2num(sig[32:])]
sig = [util.bytes2num(sig[:32]),
util.bytes2num(sig[32:])]
hash_prefix = digest[:2] # used for decoder's sanity check
signature = mpi(sig[0]) + mpi(sig[1]) # actual ECDSA signature

@ -1,18 +0,0 @@
import struct
def crc24(blob):
CRC24_INIT = 0xB704CEL
CRC24_POLY = 0x1864CFBL
crc = CRC24_INIT
for octet in bytearray(blob):
crc ^= (octet << 16)
for _ in range(8):
crc <<= 1
if crc & 0x1000000:
crc ^= CRC24_POLY
assert 0 <= crc < 0x1000000
crc_bytes = struct.pack('>L', crc)
assert crc_bytes[0] == b'\x00'
return crc_bytes[1:]

@ -75,3 +75,20 @@ def frame(*msgs):
res.write(msg)
msg = res.getvalue()
return pack('L', len(msg)) + msg
def crc24(blob):
CRC24_INIT = 0xB704CEL
CRC24_POLY = 0x1864CFBL
crc = CRC24_INIT
for octet in bytearray(blob):
crc ^= (octet << 16)
for _ in range(8):
crc <<= 1
if crc & 0x1000000:
crc ^= CRC24_POLY
assert 0 <= crc < 0x1000000
crc_bytes = struct.pack('>L', crc)
assert crc_bytes[0] == b'\x00'
return crc_bytes[1:]

Loading…
Cancel
Save