mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-24 08:28:12 +00:00
db92b13f97
ed25519raw is moved back to trezorlib ed25519cosi is renamed to cosi, and has a couple more functions, with the expectation that TrezorClient.cosi_* methods will move there. Also most code shouldn't need ed25519raw for anything, so it might get renamed to "_ed25519" to indicate that it's a private implementation. For now, I added a "verify" method to cosi, so that you don't need to call into ed25519raw.checkvalid. But trezor-core's keyctl is also using ed25519raw.publickey. I'm not sure if that's worth replicating in cosi, or whether to just leave it be, so I'm leaving it be for now. Importantly, new function "sign_with_privkey" does that math thing that was part of the selftest and is also explicitly listed in keyctl. (it's called sign_with_privkey because I expect to have a "sign" method here that calls into Trezor)
81 lines
3.0 KiB
Python
81 lines
3.0 KiB
Python
# This file is part of the TREZOR project.
|
|
#
|
|
# Copyright (C) 2012-2016 Marek Palatinus <slush@satoshilabs.com>
|
|
# Copyright (C) 2012-2016 Pavol Rusnak <stick@satoshilabs.com>
|
|
#
|
|
# This library is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Lesser General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This library is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Lesser General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Lesser General Public License
|
|
# along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import pytest
|
|
from hashlib import sha256
|
|
|
|
from .common import TrezorTest
|
|
from trezorlib import cosi
|
|
|
|
from trezorlib.tools import parse_path
|
|
|
|
|
|
@pytest.mark.skip_t2
|
|
class TestCosi(TrezorTest):
|
|
|
|
def test_cosi_commit(self):
|
|
self.setup_mnemonic_pin_passphrase()
|
|
|
|
digest = sha256(b'this is a message').digest()
|
|
|
|
c0 = self.client.cosi_commit(parse_path("10018'/0'"), digest)
|
|
c1 = self.client.cosi_commit(parse_path("10018'/1'"), digest)
|
|
c2 = self.client.cosi_commit(parse_path("10018'/2'"), digest)
|
|
|
|
assert c0.pubkey != c1.pubkey
|
|
assert c0.pubkey != c2.pubkey
|
|
assert c1.pubkey != c2.pubkey
|
|
|
|
assert c0.commitment != c1.commitment
|
|
assert c0.commitment != c2.commitment
|
|
assert c1.commitment != c2.commitment
|
|
|
|
digestb = sha256(b'this is a different message').digest()
|
|
|
|
c0b = self.client.cosi_commit(parse_path("10018'/0'"), digestb)
|
|
c1b = self.client.cosi_commit(parse_path("10018'/1'"), digestb)
|
|
c2b = self.client.cosi_commit(parse_path("10018'/2'"), digestb)
|
|
|
|
assert c0.pubkey == c0b.pubkey
|
|
assert c1.pubkey == c1b.pubkey
|
|
assert c2.pubkey == c2b.pubkey
|
|
|
|
assert c0.commitment != c0b.commitment
|
|
assert c1.commitment != c1b.commitment
|
|
assert c2.commitment != c2b.commitment
|
|
|
|
def test_cosi_sign(self):
|
|
self.setup_mnemonic_pin_passphrase()
|
|
|
|
digest = sha256(b'this is a message').digest()
|
|
|
|
c0 = self.client.cosi_commit(parse_path("10018'/0'"), digest)
|
|
c1 = self.client.cosi_commit(parse_path("10018'/1'"), digest)
|
|
c2 = self.client.cosi_commit(parse_path("10018'/2'"), digest)
|
|
|
|
global_pk = cosi.combine_keys([c0.pubkey, c1.pubkey, c2.pubkey])
|
|
global_R = cosi.combine_keys([c0.commitment, c1.commitment, c2.commitment])
|
|
|
|
sig0 = self.client.cosi_sign(parse_path("10018'/0'"), digest, global_R, global_pk)
|
|
sig1 = self.client.cosi_sign(parse_path("10018'/1'"), digest, global_R, global_pk)
|
|
sig2 = self.client.cosi_sign(parse_path("10018'/2'"), digest, global_R, global_pk)
|
|
|
|
sig = cosi.combine_sig(global_R, [sig0.signature, sig1.signature, sig2.signature])
|
|
|
|
cosi.verify(sig, digest, global_pk)
|