--- layout: post title: Logs for the Hardware Firmware Meeting Held on 2018-01-12 summary: Discussion of the firmware for the dedicated hardware wallet and a discussion of Ledger's approach tags: [community, crypto] author: dEBRUYNE / fluffypony --- # Logs **\** Hello all, it is time for our firmware meeting to start. I am not sure if it is not too early to have a meeting like this, but let's see. **\** Strange, there were so many people saying they have questions about code and now nobody is here:) So I will give a quick update on our project: **\** Ok here is the quick update: USB communications is working, alse we can generate wallet by using internal random number generator (thanks god for m2049r, nice job) **\** Maybe you have some recommendation how to move from here? My questions could look silly, but thats because I am personally just learning monero. **\** :) **\** On the other hand, there are other people working and maybe my questions could help also to them. **\** is there anyone here who is actually taking part in this meeting besides us two? **\** is the plan to use the same strategy that the ledger guy came up with, where private keys are sent (encrypted) from the device to the wallet? **\** CS noob looking to study xmr code this weekend. any design books/web guides to read like Huang's dissecting BTC? **\** m2049r[m]: I'm mostly passively participating, until that question **\** m2049r[m]: Most people will probably just read until they want to say something :p **\** hotoatmeal: We are here to speak about the plan.. I think if we want to do all the signing stuff in the device, we would need more memory.In case we need more memory, we will just setup a new device with bigger mcu. **\** i would like an implementation where the keys never ever leave the device - we have to see if thats possible with the hardware constraints we have. **\** I would like that too! **\** It is still organic and you have perfect opportunity to bend the way how it is being developped:) **\** Me too. **\** there may be multiple implementations, with different roads to success. **\** I don't yet understand how to find transaction outputs without revealing the view key **\** without having studies the code i think it should be possible to hook into the code and have the device take over when keys are in play. **\** if that's not possible, then the entire blockchain would have to be fed through the device over usb.... might be quite slow. **\** (into the wallet client code) **\** yes - but thats probably not a good idea - and were back to sending the keys to the client **\** yeah :/ **\** too bad homeomorphic encryption systems are so slow **\** otherwise you could trustlessly give the client an encrypted version of your view key, let it scan the blockchain for you, and provide the relevant txo's (also encrypted) **\** and have the device decrypt the computed result **\** i need to read up on how exactly the keys are used in the clients - any specific hint on where to get started? **\** cryptonote paper is where I got started **\** also looking at the ledger guy's patch **\** i am not sure the communication to & from the device needs to be encrypted - are you worried about usb sniffers? **\** hotoatmeal, can you link that patch? **\** and if yes, whats the attack? **\** so two separate things, both with different reasons for encryption **\** Thanks @hotoatmeal. I'll go dive into the cryptonote WP **\** cryptonote paper seems mostly vague **\** ledger guy's patch encrypts the communication because it's transferring raw key data **\** should be a no-brainer that that should be encrypted **\** Paper is pretty clear unless you want implementation specifics **\** heh yes **\** this other thing about H-E, is a separate idea, and that's to allow someone else to scan the blockchain on your behalf, without revealing your view key to them (losing your privacy) **\** paper is clear - i meant vague in the sense of implementation specifics **\** H-E? **\** I think you pretty much have to have client do the scanning **\** Not the hw **\** homeomorphic encryption **\** jbdatko: It's under open PRs on the monero repository **\** Unless you have some hw acceleration it's just too slow **\** luigi1111: yes but is there a way how to do it? **\** How to do which **\** i.e. someone else performs math on encrypted values that they can't see, and returns the result to you **\** how to let PC scan the whole blockchain and prepare outgoing tx in a way, that the are sent to device just for signing. **\** Sure **\** The cold wallet signing basically does this already **\** the problem is that H-E implementations of crypto algos are really really really slow **\** like hours for a single round of AES **\** That'd probably be slower than the device doing the scanning ^^ **\** :) **\** yeah **\** :( **\** but in terms of mathematical purity / elegance... I really want that kind of solution to work :) **\** jbdatko: https://github.com/monero-project/monero/pull/3095 **\** Ok, another question: If device did he whole scanning. How much memory we need on the device? I think that downlink from peers is usually slower than USB, so limitations is more in memory requirement at the device. **\** how big of a problem would it be to reveal the viewkey to the client? **\** Not memory **\** Cpu **\** I don't think it's an issue **\** I mean it isn't perfect **\** But it has the benefit of being workable **\** revealing to the client just means that you can't have a non-daemon client **\** Sure you can **\** yes but it is fine for now I think. **\** You could have a remote node **\** well, yeah **\** All the way to mymonero **\** the client wallet cache - is that encrypted? **\** Yes. **\** thought so - so the device would need to do that as well. **\** is it possible to give the client an image of the view key, and then have it search the blockchain for some subset of txo's that /might/ match (as a coarse filter)? **\** vtnerd **\** hotoatmeal, thank you **\** (reducing the amount of work the device has to do, but not giving up the full key data?) **\** how would that work? **\** AES accelerators on MCU are pretty good now, so depending on the MCU it might not be completely horrible (sorry I'm jumping in w/o knowing the full context) **\** hotoatmeal: mrl has been workin on this problem for some time **\** endogenic: anything I'm saying known not to be worth pursuing? (by proofs that it doesn't work, or somesuch) **\** we have space for secure elements on the board - things which can do aes and other things in hardware. **\** you need ed25519 acceleration **\** which I doubt exists **\** yeah, except that. **\** heh. now it needs an fpga **\** I don't really see any way around it **\** mymonero as a hw client would actually be quite desirable **\** and quite an upgrade **\** well it all depends on perspective :) **\** :) **\** the most secure/private arrangement would be user owned daemon -> wallet/client -> hw **\** but you can delegate the first two for privacy loss **\** well the first one isn't really privacy loss **\** our nordic semiconductor candidate has ed25519 hw block, but we still didnt get them. **\** or a different type or of privacy **\** i-a that's interesting **\** I'd be curious to see perf numbers **\** i-a but thats with an nda so we cant be open source, no? **\** for some usable ed25519 operation **\** luigi1111w: nRF52840, it has secure crypto cell or something like that. **\** Of course there are other problems, like a non open design and so on. **\** cryptocell is available without nda. **\** I mean something like signatures/sec **\** another question is if this cryptocell ed25519 is fast enough to be usable. **\** that was my only question :) **\** Unfortunately I dont know now. But I will try to find out. It seems like as-fast-as-possibe ed25529 od device is a must. **\** do you have a ballpark for how fast it would have to be to be usable? **\** cec1702 has the cuve too. **\** msvb-mob: nice, can we somehow determine their performance? **\** they sortof claim its 10x a software solution but dont show numbers **\** software solution on that power of hw? **\** IDK, something similar to an older cpu **\** i-a: I don't know how to measure performance without testing the devices on real hardware, unfortunately. **\** https://www.microchip.com/wwwproducts/en/CEC1702 **\** this is it \^ **\** thats the question luigi - its blabla **\** can we GET real hardware? **\** :) **\** msvb-mob: hmm:( are we going to have cec1702 to do some testing? **\** I think it would be really cool if such a device could be made **\** but I'm skeptical **\** m2049r[m]: I can send you a nRF52840-DK if you want. **\** we know the viewkey delegation works, at least **\** i-a: The nRF is easy (there's a devkit for that) but to test the CEC1702 we must make the boards ourselves first. **\** (mymonero and openmonero both use the exact same idea already) **\** I think the MCUs are already in my lab. **\** msvb-mob: that is not a big deal, if you know the are comming, i can send you a board asap. **\** (lets say gerbers on monday/tuesday) **\** msvb-mob: what about nda on this cec1702? Or do they have some problem? **\** The CEC1702 is not NDA encumbered. **\** perfect candidate -\_- **\** Yes, I think so too. **\** the CEC1702 & the nRF52840 would replace our MCU? **\** m2049r[m]: I think yes, because our mcu is lacking ed25519 **\** m2049r[m]: They are both Cortex-M4 MCUs so they could do so. If they aren't large enough to contain transactions in memory or code in program storage we could use them as coprocessors probably. **\** Would be a bit weird. **\** we have to see what they mean by ed25519. do we need just signing & verifying or do we also need curve arithmetic luigi1111w **\** signing and verifying sorta-mostly-ish include all the operations needed **\** I guess that's not really true **\** but the operations that need accelerated would be, mostly **\** the data sheets says: **\** Elliptic Curve point multiply with Curve25519 **\** The Edwards-curve Digital Signature Algorithm (EdDSA), using Curve25519 **\** (CEC1702) **\** ed25519 != Curve25519. **\** nRF does both i think **\** yes **\** but cec1702 doesn't have ed25519:( or I cannot find it in datasheet. **\** the nrf can create keys, sign & verify. "The generation is performed using EC Edwards ed25519 algorithm." **\** cec1702 has only Curve25519 **\** if they are going off of nacl or similar they have both **\** the signing is ed **\** and the box stuff is curve255 **\** i-a: No ECDSA on CEC1702? I don't have the documents with me now. **\** ok so to be clear: **\** The Elliptic Curve Digital Signature Algorit **\** hm (ECDSA), using all supported NIST curves **\** he Edwards-curve Digital Signatur **\** e Algorithm (EdDSA), using Curve25519 **\** that could be naming issues though :) **\** maybe ed25519 is hidden somewhere, but it isn explicitly mentioned, Curve25519 is mentioned. **\** \*isnt **\** yeah they are often bundled together **\** so you are saying we need new hardware in any case? **\** to attempt to "do everyone on device", yes (and I'm doubtful it's possible) **\** to do a client-delegated arrangement, no **\** these slides say they can do ~1400 ECDH's /s on a cortex A8: https://cr.yp.to/talks/2012.11.29/slides.pdf **\** i-a: The ED25519 API is on pages 60-61 of the CEC/MEC Family Devices ROM API Users Guide. **\** msvb-mob: thank you,) **\** For example ed25519\_valid\_sig (validate signature) is a function. **\** and Ed25519 was only a bit slower **\** what's the rough size of the blockchain, counted in txo's? **\** total size isn't that useful **\** size over past month much more so **\** growth rate too **\** yeah with some assumed groth **\** growth **\** 200k txs last month **\** so maybe 450k outputs **\** double that at least gets you 1mi/mo **\** checking an output is something like 2x ECDH **\** so it'll get slower by 20 mins, every month **\** ouch **\** if you don't use it **\** but yeah **\** (assuming you need to re-scan the entire chain each time... but maybe that can be cached) **\** there would be quite some catchup time **\** not sure if relevant, but this could be ECDSA performance on CEC device: https://imgur.com/a/WQKqp ? **\** if you leave it unplugged for some time **\** oh **\** I would sure assume you cache **\** if you don't it **\** it's pretty unworkable **\** yeah **\** you'd have to leave it plugged in a few hours before you could spend each time :) **\** the worst case of initializing a new device though is pretty bad **\** though I guess you could just sweep everything to it, and ignore all of the chain that happened before then **\** restored device **\** new device has no txs **\** right **\** at least the restore point is something you can make note of, encrypt, and then store like any other backup **\** are you suggesting we keep the chain/cache on the device? **\** no **\** definitely not the chain **\** I'm still skeptical it's workable at all, just exploring the idea **\** gottit **\** do bulletproofs change the costs here? **\** s.do.will. **\** do we have constraints about how big the device may be? **\** yes **\** hotoatmeal no **\** :P **\** m2049r[m] just tote a computer around **\** NP **\** "this is my hardware wallet" **\** what if we use a rpi3 to do all the work & store the caches for all the wallets onboard? **\** :) **\** now we're cookin with gas **\** it's pretty slow too **\** normal client scanning on computer seems pretty ok to me **\** how fast does it need to be? do we want full USB3 speeds? **\** by compromising your computer, the hacker now compromises just your privacy **\** rather than **\** you know **\** all your money **\** you can run node on rp3, so it probably isnt so slow..? **\** m2049r[m]: delegating the viewkey to the computer means it doesn't have to be very quick at all **\** i-a how long does initial sync take **\** (the device / usb, that is) **\** how long would it take to scan a restored wallet **\** that would have been the first path to explore **\** luigi1111w: ok, got it:/ **\** i-a no no that's just bc node is fast... because it's asynchronous (now it's my turn to troll) **\** is an rpi significantly better than a normal computer? **\** m2049r[m] if you slim the data down to close to minimum I don't think bandwidth is much concern **\** lemme see **\** so bottleneck is always computation then. and we want it fast so we dont take forever to sync up again. **\** I'd guess around 240 bytes per tx **\** if we keep cache on device (sdcard or whatnot) then it can be shared between clients. **\** so even .25MBps would overwhelm the device most likely **\** 240 either way? **\** no just computer->**device **\** another idea: put the viewkey on a separate device that's always connected to a computer **\** There have been some requests for SD cards, so it would be nice to try to put one on at least the developer edition board (since it has more space.) **\** yes - use a viewonly wallet. **\** m2049r[m]: Shift devices makes quite a nice hardware wallet (Bitbox) with a SD card. **\** do you guys suppose there's any reason why this isn't a match for the mymonero lightwallet server you run alongside the daemon? **\** I don't **\** i might be misunderstanding **\** I think it's great **\** it's also great for existing mymonero users (privacy issues notwithstanding, of course) **\** but I guess we're discussing the edge of what's possible **\** for having a device that does basically no delegation for maximal security and privacy in all cases **\** you are saying to have the device connect to an openmonero instance? **\** or maybe just rainbows and unicorns **\** m2049r[m]: no **\** i was envisioning some sort of stripped down protocol...vtnerd and i are working on that anyway in the api overhaul **\** ok, what are you saying? **\** he's talking about mymonero not openmonero **\** so if you're running your own local server **\** though in theory they are similar **\** which is written in C++ and in the monero-cli repo alongside the official daemon **\** it almost seems like it's more a question of protocol and transport **\** that is **\** if we really are talking about delegating scanning **\** of course you have the view key disclosure tradeoff but that's why you run your own server locally **\** i thought mymonero was closed source and not for anyone to run their own? **\** it is **\** but it won't be for much longer **\** supposedly :) **\** yep **\** vtnerd's prioritized it recently **\** heh **\** he hadnt been able to before **\** too many pesky users! **\** but anyway **\** this idea does seem to overlap with simplewallet/monero-gui's job too **\** the theory of mymonero locally vs gui/cli is pretty similar **\** yes **\** does that count as a jinx? **\** slow motion **\** mm **\** anyway, whatever software we need, we can build **\** might be a good idea to just ask what the ideal situation is for the capabilities we have on the hardware side then fill the gaps **\** we agree that we need lots of well-performing ed25519 operations on the device - no matter which road is taken? **\** and possibly some form of storage (sdcard,eMMC?) **\** m2049r[m] more is better **\** but it doesn't need to be "a lot" for the delegated road **\** which includes basically everything that's not "do it all on device" **\** whether local client or some mymonero type **\** signing would be on device for example - how large are the messages to be signed / verified? **\** it does need to be able to hash some KBs yes **\** 50 max, maybe **\** theoretically more, but shouldn't really happen anymore, in most cases **\** the cec1702 has 24k of "cryptographic ram" which seems to be the ram where cryptomagic happens. **\** "in most cases" - one case is enough to break it though - so for such cases we would need a software solution to kick in and have the hardware do 99% of cases. **\** (this is not a problem) **\** do you have a particular testcase i could run just to see how slow the current device is performing? **\** no I mean you can just disallow **\** would need some research to really know how annoying that would be though **\** (problem comes from having many inputs) **\** ((I guess mining to the wallet could cause it)) **\** m2049r[m] well if you have ed25519 code working on it **\** i do **\** a simple scalarmult **\** regardless of parameters? **\** random secret key **\** public key needs to be valid at least **\** or a simple scalarmult\_base if you have that **\** including convesion from/to 256-bit scalars or the mult by itself? **\** including **\** m2049r[m]: hotoatmeal: Yes All secret value are passed encrypted from device to PC. When PC need perform operation with those values, there are retransmitted to the device **\** https://github.com/monero-project/monero/blob/master/src/crypto/crypto.cpp#L127 **\** if you can match that **\** ok - like the operation need to make a public key out of a secret key (eg. viewkey)? **\** yes **\** that includes a conversion from fe to bytes at the end **\** i can do that. need to add time measuring stuff. **\** will do that tomorrow and get back with results. **\** cool **\** might as well do arbitrary base too if it's not much more work **\** https://github.com/monero-project/monero/blob/master/src/crypto/crypto.cpp#L127 **\** you can use any valid point for the pubkey param **\** I can give you one in hex if you want **\** or you can just gen one from the above function **\** will pm you for more details **\** cslashm: what encryption is used for the transmission of the keys over usb? **\** It will be AES128 **\** the key will new at each app usage and dedicated to session when transfer is performed **\** But I try to send even encrypted the view and spend key **\** *not send* **\** and the key exchange is DH? **\** which DH? The AES key never leave the device **\** maybe i dont understand aes. isnt that symmetric? how does the pc decode the ciphertext? **\** PC never decode, I try to explain **\** he's using the pc for encrypted cache only it sounds like **\** but I don't think you need to send spend key ever **\** device has enough memory for that, surely **\** voila. PC is just a encrypted holder **\** The advantage is that it keep the secret at the right place **\** a storage. **\** for exemple in RCT, it request n secret key, store in the right vector place, and when it use it, it resend the encrypted secret key to device, which decrypt and do the op **\** @luigi1111w: yes spend/view key never leave the device **\** I use special value 00..00 and FF...FF for them on PC side **\** ok, gotta go - it's been great :) **\** basic idea is to hav no memory restriction, on easly follow the PC code evolution with minimal code device modification **\** *and easly* (end of day in FR :) ) **\** cslashm: I've been wondering. Did you run any performance tests? For example, how long does it take to scan / refresh 10k blocks? **\** for now it's a OMG part **\** I start some perf test yes but didnot remenber **\** Approximately? :p **\** It is just impossible to rescan the whole blockchain **\** holdon, deep search in paper on my desk **\** Yeah, but that won't be necessary for 99% of the users :P **\** 10 min for 20 000 block, but app in -0O and level 4 log **\** wallet cli also in O0 **\** I see, that doesn't seem too bad tbh **\** that is scanning by cli, not ledger, right? **\** Its acceptable if you dont move in vacation for 1 month without refresh :D **\** no wallet cli scan the bc but delegate all keyderivation/keyimage computation to ledger to no disclose the view key **\** well, 1 month is 22k blocks give or take **\** So for each block, device compute some scalmul and hash **\** So that'd be 10 minutes wait **\** you can't really use blocks **\** you have to use txs **\** are those current numbers **\** what will it look like if usage goes up (which it historically has) **\** I personally don't really see a lot of benefit for disclosing the viewkey **\** yes for each txes. basically scan involves get\_key\_derivation and generate\_key\_image, those two op are done by the device. The rest is done by the PC as usual **\** view key is so never disclose **\** So, I need to leave. Be back on monday. you can mail, PM reddit or put githib issue if you need long tech desc