Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

alistair23
Copy link
Contributor

@alistair23 alistair23 commented Sep 29, 2023

Pull Request Overview

The ATECC508A is an interesting Cryptographic Co-Processor.

It connects to an MCU via I2C and can then provide crypto features, including

  • Creating and securely storing unique asymmetric key pairs based on Elliptic Curve Cryptography (FIPS186-3).
  • Creating and verifying 64-byte digital signatures (from 32-bytes of message data).
  • Creating a shared secret key on a public channel via Elliptic Curve Diffie-Hellman Algorithm.
  • Creating and verifying 64-byte digital signatures (from 32-bytes of message data).
  • Internal high quality FIPS random number generator.

The ATECC608A (different chip, but backwards compatible) even supports AES encryption/decryption. The ATECC608A is aimed at TLS support and secure booting, both of which are interesting use cases for Tock.

The ATECC508A/ATECC608A is useful for Tock boards as it provides crypto operations and entropy sources for boards that otherwise wouldn't have any. The hope is that co-processors like this can help expand Tock's crypto support and develop generic HILs and capsules. It would also be great to implement a measured boot in Tock.

Testing Strategy

This PR can lock the device and retrieve random numbers from it.

TODO or Help Wanted

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

@alevy
Copy link
Member

alevy commented Oct 20, 2023

Generally, I think it absolutely makes sense to include/use cryptographic peripherals.

First, while having the cipher/plaintext exposed over, e.g. I2C that could be sniffed with physical access is a bummer, but fine under some threat models (e.g. TPMs often have this "flaw" at a higher level). Second, it's really not the place of the Tock, IMO, to dictate which threat models are or are not acceptable.

One caveat would be if there is a significant architectural or performance/overhead cost to support multiple cases, we might want to optimize for the case that is either more common or "better."

In this case, since cryptographic accelerators, whether on or off die, are very likely to be asynchronous anyway (we're not talking about an AESNI instruction or something, but co-processors in both cases), I don't forsee that being an issue here.

@radnvlad
Copy link

First, while having the cipher/plaintext exposed over, e.g. I2C that could be sniffed with physical access is a bummer, but fine under some threat models (e.g. TPMs often have this "flaw" at a higher level).

I know I'm kind of necroing this and just leaving a drive-by reply, but the ATECC608A is capable of having a symmetric key on the MCU and on the secure element and you can encrypt the I2C communication, in order to mitigate this issue.

@alistair23 alistair23 force-pushed the alistair/atecc508a branch 2 times, most recently from 0e4e20c to ad8df50 Compare May 1, 2024 05:33
@alistair23 alistair23 marked this pull request as ready for review May 1, 2024 05:38
@alistair23 alistair23 force-pushed the alistair/atecc508a branch from ad8df50 to eb19bc2 Compare May 1, 2024 05:38
@alistair23
Copy link
Contributor Author

Ready to go now

@alistair23 alistair23 requested a review from ppannuto May 1, 2024 05:38
@alistair23
Copy link
Contributor Author

Ping!

1 similar comment
@alistair23
Copy link
Contributor Author

Ping!

@alistair23 alistair23 force-pushed the alistair/atecc508a branch 2 times, most recently from b5e1764 to 379f453 Compare June 24, 2024 11:14
@alistair23
Copy link
Contributor Author

Ping!

Copy link
Member

@lschuermann lschuermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a cool chip to support.

The wakeup function indeed seems less than elegant, but I don't have any hard feelings about this code so long as it's in the board crate, and I wouldn't want to block on that.

Some other (minor) remarks. This is yet another component that illustrates that we need some form of configuration framework, instead of sprinkling cfgs here and there. For now, configuration boards seem to be the best approximation of that, and I can see that working well here too.

As I don't own this chip myself I can't really test any of the capsule code. From skimming over it, nothing stood out to me though.

Comment on lines 26 to 36
# This feature enables support for the ATECC508A Cryptographic Co-Processor
# Breakout. If you connect one of these
# (https://www.sparkfun.com/products/15573) via the I2C Qwiic connector you
# should enable this feature.
atecc508a = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a great use of our newly established configuration boards concept. You can convert the lora_things_plus board into a bin+lib crate, and then create a configuration board which extends this base board with your peripheral.

I'm personally not opposed to cfgs in boards as much as I am for all other crates, but even here the fact that we don't test all (or actually, any) permutations of features means this is subject to bit rot.

And seeing that you have global use statements depend on this cfg makes me really skittish. Those are really hard to keep in sync & free of warnings without CI that tests all permutations of features.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to avoid a configuration board for this. I think there are good use cases for the config boards, but I don't feel this is one of them.

In this case we are just enabling an off board peripheral. As it's only additive I feel it's a good use for a cfg. It also will hopefully allow adding things in the future. On top of that a cfg board is extra maintenance and the 3 apollo3 boards are already hard to keep in sync.

I agree about not being tested though. What if I ensure they are tested in the CI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tested in the CI now

return;
}

debug!("This can not be undone!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that we're permanently locking a config without user input. Imagine a user doesn't have their serial port open -- they may easily just leave it connected after flashing. Is locking required to use the device, and if so, how is this test/function even run? Adding some docs here, and perhaps waiting until a button is pushed would be good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locking is required to use the device at all. The test is run as part of the usual make test process.

I can add some more docs to explain that as well. The board does have a button, but mine doesn't work (no idea why) so I can't easily test waiting on a button

Copy link
Member

@lschuermann lschuermann Jul 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's unfortunate. I guess waiting for a character on the UART is too hard in the kernel?

I mis-burned some expensive clock chips before by accident, and it's incredibly frustrating when fuses / configs are burnt without explicit, all-caps, triple-checked user confirmation. In the best case it's "whatever", worse it means re-ordering and waiting for a new chip, and for some people the $4.95 + shipping might also be a not-insignificant amount of money.

So I really would like to see us have some form of user input beforehand. 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair... But I don't really have a easy way to ask for input before running the kernel tests.

My feeling at the moment is that a user must explicitly enable this feature and plug the device into the board. At which point hopefully they know we have to lock the device otherwise nothing on it works

@alistair23 alistair23 force-pushed the alistair/atecc508a branch from 379f453 to 263e34b Compare July 8, 2024 05:53
@alevy
Copy link
Member

alevy commented Jul 17, 2024

I think this is exposing some warts in the otherwise ideally clean separation of concerns, but is otherwise close to good, modulo @lschuermann's comments

@alistair23 alistair23 force-pushed the alistair/atecc508a branch from 66555c5 to 05cd985 Compare July 17, 2024 21:49
@alistair23
Copy link
Contributor Author

Updated, I think that should address all of the comments

@alistair23
Copy link
Contributor Author

Ping!

alistair23 and others added 3 commits August 19, 2024 18:59
Signed-off-by: Alistair Francis <[email protected]>
If we read the interrupt state again during the interrupt handler we can
miss important information, such as a Nack event. So don't handle the
interrupts that occur while processing an interrupt and instead wait for
the interrupt handler to be called again.

Signed-off-by: Alistair Francis <[email protected]>
@alistair23
Copy link
Contributor Author

Ping!

@alevy
Copy link
Member

alevy commented Aug 19, 2024

@lschuermann I think your concerns are addressed.

@lschuermann lschuermann added the last-call Final review period for a pull request. label Aug 19, 2024
@alevy alevy added this pull request to the merge queue Aug 19, 2024
Merged via the queue into tock:master with commit 73d27f3 Aug 19, 2024
12 checks passed
@alistair23 alistair23 deleted the alistair/atecc508a branch August 19, 2024 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component last-call Final review period for a pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants