Cov txheej txheem:
- Khoom siv
- Kauj ruam 1: Kauj ruam los ntawm Kauj Ruam
- Kauj Ruam 2: Ceeb Toom Txog Atecc608a
- Kauj Ruam 3: 1. Desing of the Circuit
- Kauj Ruam 4: 2. Kev teeb tsa ntawm Chip (Atecc608a)
- Kauj Ruam 5: 3. Kev siv AES CBC Module
- Kauj Ruam 6: 5. Vim Li Cas Koj Thiaj Li Yuav Tsum Siv Cov Chip no
- Kauj Ruam 7: Xaus
Video: Kev Ruaj Ntseg Nrog Arduino: Atecc608a: 7 Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:25
Cov ncauj lus
Nyob zoo sawv daws!
Nov yog kuv thawj Cov Lus Qhia Qhia yog li kuv vam tias nws yuav nthuav rau koj txhua tus.
Hauv kab lus no, kuv yuav piav qhia koj yuav siv lub micro chip hu ua "ATECC608A" uas muab ntau yam cuab yeej ruaj ntseg.
Cov nti no tau tsim los ntawm MicroChip thiab nws yog qhov kawg ntawm "CryptoAuthentication chip". Ua ntej cov ntawv no, muaj "ATSHA204A" thiab "ATECC508A".
Vim li cas kuv thiaj txiav txim siab siv lub xeem version thiab tsis yog version dhau los?
Cov ntawv no yog cov txheej txheem tshaj plaws thiab tau txais kev ua haujlwm uas lub qub version tsis muaj (Piv txwv: AES module, IO tiv thaiv tus qauv …).
Vim li cas qhov project no?
Kuv ua haujlwm hauv thaj tsam ntawm CyberSecurity thiab zoo li txhua tus neeg kuv nyiam lub cajmeem thiab khoom siv hluav taws xob. Thaum kuv kawm, kuv tau txais kev sablaj nrog tus kws tshaj lij ntawm IoT Security uas tau qhia peb tias Kev Lag Luam tsis siv Kev Ruaj Ntseg hauv lawv cov khoom IoT. Kuv tau qhia peb lub ntsuas phoo uas tuaj yeem qhib nrog koj lub smartphone los ntawm Bluetooth. Ntawm lub ntsuas phoo, kab lus hais tias "Lub ntsuas phoo no muaj kev nyab xeeb tshaj li lub ntsuas phoo tseem ceeb!". Kab lus no ua rau nws luag ntxhi thiab nws hloov kho kab lus "Qhov ntsuas phoo no yog lub ntsuas phoo phem tshaj plaws uas tau tsim!".
Nws tau qhia peb nrog nws tus kheej lub PC thiab Bluetooth sniffer uas txhua qhov lus txib xa los ntawm lub xov tooj ntawm tes yog tib yam txhua lub sijhawm thiab nws yooj yim heev rau luam cov lus txib no thiab xa nrog koj lub xov tooj. Nws piav qhia peb tias "Kev Ruaj Ntseg" rau "Industrial" tsis yog qhov teeb meem loj. Nws qhia peb cov chips (tsawg dua 0.60 $) uas tuaj yeem ntxiv txheej kev ruaj ntseg rau cov khoom no.
Tom qab qhov kev ua qauv qhia no, kuv tau sim nrhiav qee qhov Qhib qhov project uas ntxiv txheej kev nyab xeeb rau IoT cov khoom tab sis kuv yeej tsis pom nws.
Yog li kuv txiav txim siab los ua haujlwm ntawm txoj haujlwm uas siv txheej kev nyab xeeb rau kev sib txuas lus ntawm ob yam khoom IoT.
Kuv lub tswv yim yog dab tsi?
Thaum sib tham ntawm ob lub hom phiaj IoT, muaj ntau qhov kev tawm tsam tuaj yeem muaj: Tus txiv neej ntawm qhov muag me me, Luam cov ntaub ntawv thiab ntau ntxiv.. Yog li kuv lub tswv yim yooj yim heev:
- Kev siv cov ntaub ntawv encrypted ntawm ob lossis ntau dua IoT khoom.
- Cov khoom siv qis
- Ua haujlwm nrog Arduino UNO
Tam sim no kuv yuav piav qhia koj li cas kuv siv daim duab tsis paub daws teeb no nrog Arduino thiab Atecc608a nti. Hauv kab lus no, kuv yuav piav qhia koj yuav siv Arduino UNO nrog ATECC608A li cas.
Kuv yuav sau ib tsab xov xwm hais txog kev sib txuas lus ntawm ob yam khoom tom ntej.
Khoom siv
Koj xav tau qee yam qee yam rau txoj haujlwm no:
- Arduino UNO lossis MEGA (Chip yuav tsum yog Atmega 328 lossis ATMEGA 2560)
- Atecc608A nti (raug nqi tsawg dua 0.80 $ txhua, yooj yim mus nrhiav ntawm koj lub vev xaib khoom lag luam)
- 8-Pin SOIC Adapter
- Qee cov xov hlau thiab cov resistors
Cov ntawv ntawm cov ntawv dhau los ntawm cov nti no (Atecc508a) muaj nyob ntawm no -> Cov Ntawv Teev Npe Atecc508a
Kauj ruam 1: Kauj ruam los ntawm Kauj Ruam
Hauv kab lus no, kuv yuav qhia koj yuav hloov kho kev teeb tsa ntawm cov nti no thiab tom qab yuav ua li cas encrypt cov ntaub ntawv siv AES CBC Algorithme.
Peb yuav ua raws cov theem no:
- Tsim ntawm Circuit Court
- Kev teeb tsa ntawm cov nti no
- Kev siv ntawm AES CBC tus qauv
- Vim li cas koj thiaj yuav tsum tau siv cov nti no
Rau txhua qib, kuv yuav qhia txhua yam rau koj. Tsis tas li, Kuv tau ntxiv kuv cov cai hauv kuv Github nrog cov lus rau txhua qhov haujlwm. Yog tias koj muaj qee lo lus nug txog kuv cov cai lossis txoj haujlwm no, Kuv yuav zoo siab los teb nws.
Kuv Github: Kuv Github
Kauj Ruam 2: Ceeb Toom Txog Atecc608a
Atecc608a nti tsis yog "yooj yim" nti.
Ua ntej, cov ntaub ntawv ntawm cov nti no nyob hauv NDA yog li koj yuav tsis pom nws ua tiav hauv Is Taws Nem. Tab sis tsis muaj teeb meem rau qhov no, cov ntaub ntawv ntawm cov ntawv dhau los muaj nyob hauv Internet Cov Ntawv Teev Npe Ua tiav ATECC508A.
Qhov thib ob, thaum koj siv cov nti no koj yuav tsum tau xauv nws cov teeb tsa thiab nws tsis tuaj yeem hloov kho lub teeb tsa ntawm lub nti yog tias nws tau xauv. Yog li ceev faj thaum koj yuav xauv lub Config Zone thiab Data Zone.
Thib peb, lub tsev qiv ntawv sau hauv C yog qhov loj heev thiab ua tiav, yog li koj yuav tsum nyeem cov ntaub ntawv ntawm cov haujlwm uas koj yuav siv ua ntej.
Plaub, lub tsev qiv ntawv sau rau lub nti no tsis ua haujlwm rau Arduino UNO, tab sis Nws ntxiv cov haujlwm uas xav tau nws ua haujlwm nrog Arduino UNO.
Cov nti ATECC608A
Koj tuaj yeem sib tham nrog cov nti no los ntawm I2C. Qhov chaw nyob ntawm cov nti no tuaj yeem hloov kho hauv kev teeb tsa.
Cov nti no muaj 16 qhov sib txawv uas tuaj yeem muaj ntau hom ntaub ntawv:
- ECC Key (ntiag tug lossis pej xeem)
- AES Key
- Lwm cov ntaub ntawv (zoo li Sha hash lossis tsuas yog lo lus)
Hauv peb qhov xwm txheej, peb yuav khaws AES Key hauv ib qhov.
Kauj Ruam 3: 1. Desing of the Circuit
1. Tsim ntawm Circuit Court
Cov txheej txheem ntawm qhov Circuit Court no yooj yim heev!
Koj yuav tsum siv lub zog 3.3V vim tias qhov kev pom zoo yog nruab nrab ntawm 2.0V thiab 5.5V tab sis kuv nyiam siv 3.3V.
Rau cov nti no, ib txwm koj muaj tus lej nyob ntawm kaum ntawm lub nti, qhov no yog tus Pin 1 ntawm lub rooj tsavxwm no. Kuv ntxiv Sab saum toj saib ntawm Atecc608a nrog tus lej PIN vim tias nws yog 8-Lead SOIC yog li cov nti me me heev.
- ARDUINO 3.3V -> PIN 8 (Atecc608a)
- ARDUINO GND -> PIN 4 (Atecc608a)
- ARDUINO A4 (SDL) -> PIN 5 (Atecc608a)
- ARDUINO A5 (SCL) -> PIN 6 (Atecc608a)
Koj yuav tsum siv lub zog 3.3V vim tias qhov kev pom zoo yog nruab nrab ntawm 2.0V thiab 5.5V tab sis kuv nyiam siv 3.3V.
Kuv ntxiv Sab saum toj saib ntawm Atecc608a vim tias nws yog 8-Lead SOIC yog li cov nti me me. Yog tias koj xav tau, yog li cov neeg muag khoom tsim qee lub rooj tsavxwm nrog cov laug cam, nws tuaj yeem yooj yim rau koj.
Ceeb Toom: Hauv kuv qhov xwm txheej, kuv yuav tsum ntxiv tus tiv thaiv ntawm SDA ntawm Arduino thiab Chip (tseem rau SDL). Kuv ntxiv 4.7Kohm resistor rau txhua tus.
Kauj Ruam 4: 2. Kev teeb tsa ntawm Chip (Atecc608a)
Ua ntej siv lub luag haujlwm ntawm encryption lossis decryption koj yuav tsum teeb tsa lub nti. Hauv cov kauj ruam no, Kuv yuav qhia meej txhua kauj ruam uas koj yuav tsum tau ua rau kev teeb tsa ntawm cov nti no.
Ceeb toom: cov kauj ruam no yog ntshuam heev thiab yog tias koj xauv thaj tsam ua ntej kawg koj tsis tuaj yeem hloov kho lawv.
Raws li tau piav qhia ua ntej, cov nti no tau txais ob cheeb tsam:
- Kho thaj tsam
- Cheeb Tsam Cov Ntaub Ntawv
Kev teeb tsa Thaj Chaw tau txais qhov loj me ntawm 128 bytes tab sis thawj 16 bytes tsis tuaj yeem hloov kho.
Txhawm rau teeb tsa lub nti no, koj xav tau ob qho ua raws cov kauj ruam no. Nws yog ib qho tseem ceeb heev kom ua raws txhua kauj ruam hauv kev txiav txim lossis koj kev teeb tsa yuav tsis ua haujlwm, thiab koj lub nti yuav raug kaw thiab siv tsis tau. Cov kauj ruam yog:
- Tsim tus qauv teeb tsa
- Sau daim ntawv no rau tus nti
- Xauv qhov Config Zone
- Sau koj tus lej AES (128 Khoom) hauv qhov qhib
- Xauv Cov Ntaub Ntawv Thaj Tsam
Ntaub ntawv
Hauv qab no kuv qhia txhua kauj ruam ntawm kev tsim nrog kuv cov cai, tab sis tsis muaj kev txhawj xeeb, Kuv tau ntxiv ib qho piv txwv ntawm kev teeb tsa hauv kuv Github. Kuv muab cov lus pom ntawm txhua qhov haujlwm, thiab * *.ino cov ntaub ntawv muaj nyob nrog txhua kauj ruam txhawm rau koj.
- Kuv Github: Kuv Github
- Txoj hauv kev piv txwv Kev teeb tsa: configuration_example.ino
Thawj kauj ruam: Tsim cov qauv teeb tsa
Raws li tau piav qhia ua ntej, thaj chaw teeb tsa tau txais qhov loj me ntawm 128 khoom, tab sis thawj 16 khoom tsis tuaj yeem hloov pauv. Thaj tsam no suav nrog ntau ntu, tab sis koj yuav tsum paub tsuas yog 3 ntu ntawm thaj chaw teeb tsa no rau txoj haujlwm no:
- Tus Bytes 16 -> Nov yog I2C chaw nyob ntawm lub nti
- Tus Bytes 20 txog 51 -> Koj tuaj yeem hloov kho ntawm no yam Hom Qhov rau 16 qhov qhib ntawm cov nti no
- Bytes 96 txog 127 -> Koj tuaj yeem teeb tsa no Hom Hom lossis cov ntaub ntawv siv hauv txhua qhov.
(Yog tias koj xav tau kev piav qhia ntxiv ntawm txhua cheeb tsam no, thov nyeem cov ntaub ntawv (nplooj 13, ntu 2.2))
Ntawm no, Kuv muab cov ntsiab lus txhua Bytes/Tshooj ntawm 112 bytes ntawm kev teeb tsa ntawm Chip. Nov yog qhov piv txwv, txhua tus nti yuav tuaj yeem muaj kev teeb tsa sib txawv:
0xC0, // I2C chaw nyob
0x00, 0x00, 0x00, 0x83, 0x20, // Slot Config Slot 1 0x85, 0x20, // Slot Config Slot 2 0x8F, 0x20, // Slot Config Slot 3 0xC4, 0x8F, // Slot Config Slot 4 0x8F, 0x8F, // Qhov Chaw Config Qhov 5 0x8F, 0x8F, // Qhov Config Slot 6 0x9F, 0x8F, // Qhov Config Slot 7 0x0F, 0x0F, // Slot Config Slot 8 0x8F, 0x0F, // Slot Config Slot 9 0x8F, 0x0F, // Qhov Config Qhov 10 10 0x8F, 0x0F, // Qhov Config Slot 11 0x8F, 0x0F, // Qhov Config Qhov Qhov 12 0x8F, 0x0F, // Slot Config Slot 13 0x00, 0x00, // Slot Config Slot 14 0x00, 0x00, // Slot Config Slot 15 0xAF, 0x8F, // Slot Config Slot 16 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x00, // Qhov tseem ceeb Config qhov 1 0x33, 0x00, // Qhov tseem ceeb Config qhov 2 0x33, 0x00, // Qhov tseem ceeb Config qhov 3 0x1C, 0x00, // Qhov tseem ceeb Config qhov 4 0x1C, 0x00, // Qhov tseem ceeb Config qhov 5 0x 1C, 0x00, // Qhov Ntsuas Config Qhov 6 0x1C, 0x00, // Qhov Ntsuas Config Qhov 7 0x3C, 0x00, // Qhov Ntsuas Config Qhov 8 0x1A, 0x00, // Qhov Ntsuas Config Qhov 9 0x3A, 0x00, // Qhov Ntsuas Config Qhov 10 0x1A, 0x00, // Qhov Ntsuas Config Qhov 11 11x3x3, 0x00, // Qhov Ntsuas Config Qhov 12 0x3A, 0x00, // Qhov Ntsuas Config Qhov 13 0x3C, 0x00, // Qhov Ntsuas Config Qhov 14 0x3C, 0x00, // Qhov Ntsuas Config Qhov 15 0x1C, 0x00 // Qhov tseem ceeb Config qhov 16
Raws li pom, kuv muab qee cov lus pom hauv cov cai no kom nkag siab ntau qhov kev teeb tsa no.
Hauv koj qhov xwm txheej yuav tsum nkag siab tsuas yog peb yam:
- Tus Bytes 16 -> Nov yog I2C chaw nyob ntawm lub nti
- Tus Bytes 20 txog 51 -> Koj tuaj yeem hloov kho ntawm no yam Hom Qhov rau 16 qhov qhib ntawm cov nti no
- Tus Byte 96 txog 127 -> Koj tuaj yeem teeb tsa no Hom Hom lossis cov ntaub ntawv siv hauv txhua qhov.
Kuv yuav tsis piav qhia hom kev teeb tsa thiab vim li cas kuv thiaj siv qhov no thiab tsis yog lwm qhov vim tias nws nyuaj rau piav qhia txhua yam. Yog tias koj xav tau cov ntaub ntawv ntau ntxiv mus rau cov ntaub ntawv, nplooj 16 ntu 2.2.1 rau "SlotConfig" thiab nplooj 19 ntu 2.2.5 rau "KeyConfig"
Rau qhov ua piv txwv no, koj yuav siv lub qhov 9 los khaws tus yuam sij AES.
Txog qhov no, peb yuav tsum tso (yog tias koj xav tau, koj tuaj yeem luam qhov piv txwv saum toj no, kev hloov kho tau ua tiav hauv nws):
- Byte 36 = 0x8F
- Peb 37 = 0x0F
- Byte 112 = 0x1A
- Peb 113 = 0x00
Vim li cas kuv thiaj teeb tsa qhov kev teeb tsa no: Rau txhua qhov ntawm cov nti no, koj tuaj yeem teeb tsa tsis hais rau lub nti seb hom ntaub ntawv twg yuav khaws cia. Koj muaj ntau yam tsis:
- Qhov tuaj yeem sau lossis nyeem (meej lossis zais qhov kev ua)
- Hom ntaub ntawv khaws tseg (ECC qhov tseem ceeb, Tus lej pej xeem, SHA Hash, AES Key…)
- Qhov qhib tuaj yeem kaw tau
- Kev tsim cov yuam sij raug tso cai
- …
Nrog tus lej 36 thiab 37 teeb tsa rau "0x0F8F":
- Cov ntaub ntawv tuaj yeem sau rau hauv Clear
- Cov ntsiab lus ntawm qhov qhib no yog qhov zais thiab tsis tuaj yeem nyeem
- Qhov tsis tuaj yeem siv rau CheckMac Copy hais kom ua
Nrog lub byte 112 thiab 113 teeb tsa rau "0x001A":
Qhov qhib tuaj yeem khaws txog plaub AES 128-ntsis symmetric keys (KeyType = 0x6)
Kauj ruam ob: Sau qhov kev teeb tsa no
Cov kauj ruam no tseem ceeb heev vim tias peb yuav teeb tsa lub nti nrog peb teeb tsa thiab yog tias kev teeb tsa no tsis zoo, koj yuav siv cov nti no.
Tab sis tsis muaj kev txhawj xeeb, tsuav tus Configuration tsis raug kaw, koj tuaj yeem hloov kho koj li kev teeb tsa.
Ntawm no, tus lej no siv los sau kev teeb tsa rau lub nti:
/** / luv luv Sau qhov teeb tsa tshiab rau lub nti.
* / param [hauv] cfg Logical interface teeb tsa. Qee qhov ua ntej * kev teeb tsa tuaj yeem pom hauv atca_cfgs.h * / param [hauv] teeb tsa Array uint8_t ntawm kev teeb tsa (ntev 112) * / param [hauv] len Qhov loj ntawm kev teeb tsa teeb tsa * / rov qab ATCA_SUCCESS ntawm kev ua tiav, txwv tsis pub ua yuam kev. */ ATCA_STATUS sau_configuration (ATCAIfaceCfg *cfg, uint8_t *teeb tsa, size_t len) {yog (len! = 112) rov qab ATCA_BAD_PARAM; ATCA_STATUS xwm txheej; xwm txheej = atcab_init (cfg); yog tias (xwm txheej == ATCA_SUCCESS) {// Sau qhov teeb tsa Array rau lub nti // Padding ntawm 16 byte (16 thawj bytes tsis tuaj yeem sau) xwm txheej = atcab_write_bytes_zone (ATCA_ZONE_CONFIG, 0, 16, (uint8_t *) teeb tsa, len); rov qab los xwm txheej; } rov qab xwm txheej; }
Txoj haujlwm no yuav sau koj cov teeb tsa hauv lub nti.
Kauj ruam thib peb: ntsuas thaj tsam teeb tsa
Lus ceeb toom: ceev faj nrog cov kauj ruam no, yog tias koj xauv thaj tsam no thiab koj lub teeb tsa tsis zoo, nti tsis siv thiab koj tsis tuaj yeem hloov kho thaj tsam no
Rau qhov kev nqis tes ua no, peb yuav siv txoj haujlwm no:
/** / luv Txheeb xyuas yog tias DATA_ZONE lossis CONFIG_ZONE raug kaw
* / param [hauv] cfg Logical interface teeb tsa. Qee qhov kev teeb tsa ua ntej tuaj yeem nrhiav pom hauv atca_cfgs.h * / param [hauv] cheeb tsam LOCK_ZONE_DATA lossis LOCK_ZONE_CONFIG * / xa ATCA_SUCCESS ntawm kev ua tiav, txwv tsis pub ua yuam kev. */ ATCA_STATUS check_lock_zone (ATCAIfaceCfg *cfg, uint8_t tsam) {ATCA_STATUS xwm txheej; bool lock = tsis tseeb; yog (cheeb tsam! = (uint8_t) LOCK_ZONE_CONFIG && cheeb tsam! = (uint8_t) LOCK_ZONE_DATA) rov ATCA_BAD_PARAM; xwm txheej = atcab_init (cfg); yog (xwm txheej == ATCA_SUCCESS) {yog (ATCA_SUCCESS! = (xwm txheej = atcab_is_locked (cheeb tsam, & ntsuas phoo))) {rov ATCA_FUNC_FAIL; } yog (! xauv) {rov ATCA_NOT_LOCKED; } rov qab ATCA_SUCCESS; } rov qab ATCA_BAD_PARAM; } check_lock_zone (& cfg, LOCK_ZONE_CONFIG);
Kauj ruam plaub: Sau koj tus lej AES rau hauv qhov qhib
Hauv ntu no koj yuav teeb koj tus kheej AES tus yuam sij hauv qhov uas koj tau hais tseg hauv kev teeb tsa ntawm lub nti.
Rau qhov ua piv txwv no, Kuv yuav siv tus lej lej 9 ntawm lub nti.
Koj yuav tsum paub: Qhov tshwj xeeb ntawm cov nti no yog koj tuaj yeem sau cov ntaub ntawv hauv qhov tsuas yog 4 bytes lossis 32 bytes. Rau AES peb xav tau 128 ntsis Ntsiab li 16 bytes ntawm cov ntaub ntawv. Yog li kuv txiav txim siab sau mus rau qhov tseem ceeb ntawm 16 bytes txhua qhov hauv qhov no kom muaj 32 bytes cov ntaub ntawv.
Tam sim no, kuv yuav qhia koj cov cai siv:
/** / luv Sau AES qhov tseem ceeb hauv qhov muab rau. * / param [hauv] cfg Logical interface teeb tsa. Qee qhov ua ntej * kev teeb tsa tuaj yeem pom hauv atca_cfgs.h * / param [hauv] qhov tseem ceeb tus lej naj npawb * / param [hauv] datakey qhov tseem ceeb array uint8_t * / param [hauv] len Qhov loj ntawm qhov tseem ceeb array * / xa ATCA_SUCCESS ntawm kev ua tiav, txwv tsis pub ua yuam kev. */ ATCA_STATUS write_key_slot (ATCAIfaceCfg *cfg, uint8_t qhov tseem ceeb, uint8_t *datakey, size_t len) {yog (qhov tseem ceeb 16) rov qab ATCA_BAD_PARAM; yog (len! = 32) rov ATCA_BAD_PARAM; ATCA_STATUS xwm txheej = atcab_init (cfg); yog (xwm txheej == ATCA_SUCCESS) {xwm txheej = atcab_write_zone (ATCA_ZONE_DATA, (uint16_t) qhov tseem ceeb, 0, 0, datakey, 32); yog (xwm txheej! = ATCA_SUCCESS) rov muaj xwm txheej; } rov qab xwm txheej; }
Txog qhov piv txwv no, Kuv yuav siv ob lub AES Keys ntawm 16 bytes txhua:
// Piv txwv ntawm AES KEY (len 32) uint8_t example_of_key [32] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; write_key_slot (& cfg, 9, example_of_key, sizeof (piv txwv_of_key));
Yog tias qhov kev nqis tes no yog qhov zoo, tam sim no, koj yuav tsum dhau qib kawg "xauv thaj tsam cov ntaub ntawv"
Kauj ruam kawg: xauv Cov Ntaub Ntawv Thaj Chaw
Lus ceeb toom: ceev faj nrog cov kauj ruam no, yog tias koj xauv cheeb tsam no thiab koj cov ntaub ntawv tsis tau teeb tsa, nti tsis siv thiab koj tsis tuaj yeem hloov kho thaj tsam no
Rau qhov kev nqis tes ua no, peb yuav siv txoj haujlwm no:
/** / luv Txheeb xyuas yog tias DATA_ZONE lossis CONFIG_ZONE raug kaw
* / param [hauv] cfg Logical interface teeb tsa. Qee qhov kev teeb tsa ua ntej tuaj yeem nrhiav pom hauv atca_cfgs.h * / param [hauv] cheeb tsam LOCK_ZONE_DATA lossis LOCK_ZONE_CONFIG * / xa ATCA_SUCCESS ntawm kev ua tiav, txwv tsis pub ua yuam kev. */ ATCA_STATUS check_lock_zone (ATCAIfaceCfg *cfg, uint8_t tsam) {ATCA_STATUS xwm txheej; bool lock = tsis tseeb; yog (cheeb tsam! = (uint8_t) LOCK_ZONE_CONFIG && cheeb tsam! = (uint8_t) LOCK_ZONE_DATA) rov ATCA_BAD_PARAM; xwm txheej = atcab_init (cfg); yog (xwm txheej == ATCA_SUCCESS) {yog (ATCA_SUCCESS! = (xwm txheej = atcab_is_locked (cheeb tsam, & ntsuas phoo))) {rov ATCA_FUNC_FAIL; } yog (! xauv) {rov ATCA_NOT_LOCKED; } rov qab ATCA_SUCCESS; } rov qab ATCA_BAD_PARAM; } check_lock_zone (& cfg, LOCK_ZONE_DATA);
Yog tias qhov kev nqis tes no yog qhov zoo, koj lub nti tau npaj los siv
Kauj Ruam 5: 3. Kev siv AES CBC Module
Kuv yuav piav qhia yuav ua li cas encrypt thiab decrypt cov ntaub ntawv nrog lub algorithm AES CBC thiab nti Atecc608a.
Nco ntsoov: Ua ntej siv txoj haujlwm no, koj yuav tsum teeb tsa lub nti. Rau qhov no, ua raws cov kauj ruam 2 ntawm kab lus no
Cov nti no tau txais ntau hom AES module (AES 128 khoom), tsuas yog AES 128 khoom yog ua tau:
- AES normal
- AES CWB
- AES GCM (nrog GFM hash) (saib wikipedia kom paub meej ntxiv)
Txhawm rau ua kom yooj yim siv, Kuv tsim ob txoj haujlwm:
- aes_cbc_encrypt
- aes_cbc_decrypt
Ob txoj haujlwm no muaj nyob ntawm kuv Github.
Piav qhia
Kuv xaiv siv AES CBC Algorithm vim tias nws muaj kev nyab xeeb dua li qhov yooj yim AES 128 khoom. Cov txheej txheem no siv Tus Thawj Vector los zais koj cov ntaub ntawv.
Ntaub ntawv
Hauv qab no kuv piav qhia txhua kauj ruam ntawm kev encryption thiab decryption method. Tab sis kuv tau sau cov cai rau Arduino uas siv ob txoj haujlwm no. Koj tuaj yeem pom tus lej no hauv kuv Github:
- Github: Kuv Github
- Piv txwv ntawm txoj cai "Encrypt/Decrypt": AES_crypto_example.ino
Thawj kauj ruam: Nkag mus rau koj cov ntaub ntawv
Hauv ntu no, Kuv yuav qhia koj yuav ua li cas encrypt koj cov ntaub ntawv.
Ua ntej koj yuav xav tau txoj haujlwm no:
/** / luv luv Encrypt cov ntaub ntawv siv AES CBC algorithme* / param [hauv] cfg Logical interface teeb tsa. Qee qhov kev teeb tsa ua ntej * tuaj yeem pom hauv atca_cfgs.h * / param [hauv] cov ntaub ntawv Cov lus rau encypt (yuav tsum tau muab faib los ntawm 16, qhov ntev tshaj 240) * / param [hauv] ntev ntev ntawm Cov Lus rau encypt (yuav tsum tau muab faib ua 16, qhov ntev tshaj 240) * / param [tawm] iv Pib Vector siv hauv AES CBC (xa cov vector hauv qhov no) * / param [tawm] ciphertext rov los ntawm no Cypher ntawv * / param [hauv] qhov tseem ceeb Tus lej ntawm key * / xa ATCA_SUCCESS ntawm kev ua tiav, txwv tsis pub ua yuam kev. */ ATCA_STATUS aes_cbc_encrypt (ATCAIfaceCfg *cfg, uint8_t *cov ntaub ntawv, int len, uint8_t *iv, uint8_t *ciphertext, uint8_t qhov tseem ceeb) {atca_aes_cbc_ctx_t ctx; yog (len> LIMIT_DATA_SIZE_CBC && len % 16! = 0) {Serial.print (F ("YOOJ YIM: ATCA_BAD_PARAM")); xa ATCA_BAD_PARAM; } uint8_t tmp_iv [IV_LENGTH_CBC]; uint8_t tmp_data [len]; ATCA_STATUS xwm txheej = atcab_init (cfg); yog (xwm txheej == ATCA_SUCCESS) {xwm txheej = atcab_aes_cbc_init (& ctx, qhov tseem ceeb, 0, tmp_iv); yog (xwm txheej! = ATCA_SUCCESS) {Serial.print (F ("ERROR Encrypt: atcab_aes_cbc_init, Code Error 0x")); Serial.println (xwm txheej, HEX); rov qab; } memcpy (iv, tmp_iv, IV_LENGTH_CBC); memcpy (tmp_data, cov ntaub ntawv, len); int max = len / 16; rau (int j = 0; j <max; j ++) {status = atcab_aes_cbc_encrypt_block (& ctx, & tmp_data [j * 16], & ciphertext [j * 16]); } yog (xwm txheej! = ATCA_SUCCESS) {Serial.print (F ("ERROR Encrypt: atcab_aes_cbc_encrypt_block, Code Error 0x")); Serial.println (xwm txheej, HEX); } rov qab xwm txheej; } rov qab xwm txheej; }
Txoj haujlwm no yooj yim siv, koj yuav tsum teeb tsa ob yam:
- Ib qho khoob IV (Pib Vector) ntawm 16 Bytes
- Cov ntaub ntawv rau encrypt (qhov loj me me 240 Bytes)
Nov yog qhov piv txwv "yuav siv lub luag haujlwm no li cas".
Kuv xav encrypt lo lus "AAAAAAAAAAAAAAAAA", nrog kuv tus yuam sij sau hauv tus lej "9":
ATCA_STATUS xwm txheej = atcab_init (& cfg); yog (xwm txheej! = ATCA_SUCCESS) {Serial.println (F ("atcab_init () ua tsis tiav: Code -> 0x")); Serial.println (xwm txheej, HEX); } uint8_t plaintext [16] = "AAAAAAAAAAAAAAAAA"; // Cov ntawv qub uint8_t iv [IV_LENGTH_CBC]; // Pib Vector uint8_t cypherdata [sizeof (plaintext)]; // Cov ntaub ntawv encrypted xwm txheej = aes_cbc_encrypt (& cfg, plaintext, sizeof (plaintext), iv, cypherdata, 9);
Yog tias qhov ua tau zoo, koj yuav muaj cov ntaub ntawv encrypted hauv qhov sib txawv "cypherdata" thiab Initial Vector hauv qhov sib txawv "IV".
Khaws ob qhov sib txawv los txiav txim siab koj cov ntawv!
Kauj ruam thib ob: decrypt koj cov ntaub ntawv
Txhawm rau decrypt koj cov ntaub ntawv koj yuav xav tau ob yam:
- Thawj Vector
- Cov ntaub ntawv Cypher (cov ntaub ntawv encrypted)
Txhawm rau decrypt koj cov ntaub ntawv, koj yuav xav tau txoj haujlwm no:
/** luv luv Decrypt cov ntaub ntawv siv AES CBC algorithme* / param [hauv] cfg Logical interface teeb tsa. Qee qhov kev teeb tsa ua ntej tuaj yeem nrhiav pom hauv atca_cfgs.h * / param [hauv] ciphertext Cov lus rau decypt (yuav tsum tau muab faib los ntawm 16, qhov siab tshaj 240) * / param [hauv] len ntev ntawm Cov Lus rau decypt (yuav tsum tau muab faib ua 16, max ntev 240) * / param [in] iv Pib Vector siv rau hauv AES CBC * / param [tawm] cov lus ntsiab lus rov los ntawm no cov ntawv txiav txim siab * / param [hauv] qhov tseem ceeb Tus lej ntawm tus yuam sij * / rov qab ATCA_SUCCESS ntawm kev ua tiav, txwv tsis pub yuam kev. */ ATCA_STATUS aes_cbc_decrypt (ATCAIfaceCfg *cfg, uint8_t *ciphertext, int len, uint8_t *iv, uint8_t *plaintext, uint8_t qhov tseem ceeb) {atca_aes_cbc_ctx_t ctx; yog (len> LIMIT_DATA_SIZE_CBC || len % 16! = 0) {Serial.print (F ("ERROR Decrypt: ATCA_BAD_PARAM")); xa ATCA_BAD_PARAM; } ATCA_STATUS xwm txheej = atcab_init (cfg); yog (xwm txheej == ATCA_SUCCESS) {xwm txheej = atcab_aes_cbc_init (& ctx, qhov tseem ceeb, 0, iv); yog (xwm txheej! = ATCA_SUCCESS) {Serial.print (F ("ERROR Decrypt: atcab_aes_cbc_init, Code Error 0x")); Serial.println (xwm txheej, HEX); rov qab; } int max = len / 16; rau (int j = 0; j <max; j ++) {status = atcab_aes_cbc_decrypt_block (& ctx, & ciphertext [j * 16], & plaintext [j * 16]); } yog (xwm txheej! = ATCA_SUCCESS) {Serial.print (F ("ERROR Decrypt: atcab_aes_cbc_encrypt_block, Code Error 0x")); Serial.println (xwm txheej, HEX); } rov qab xwm txheej; } rov qab xwm txheej; }
Kuv xav decrypt kuv cov ntaub ntawv yav dhau los (saib hauv qab no, Thawj kauj ruam). Rau qhov no kuv yuav ua qhov no:
uint8_t plaintext [16] = "AAAAAAAAAAAAAAAAA"; uint8_t iv [IV_LENGTH_CBC]; uint8_t cypherdata [sizeof (cov ntsiab lus)]; uint8_t decryptdata [sizeof (cov ntsiab lus)]; xwm txheej = aes_cbc_decrypt (& cfg, cypherdata, sizeof (cypherdata), iv, decryptdata, 9); yog tias (xwm txheej == ATCA_SUCCESS) {Serial.print ("Cov ntawv sau rov qab yog:"); rau (size_t i = 0; i <sizeof (decryptdata); i ++) {Serial.print ((char) decryptdata ); } Serial.println (""); } lwm tus {// Saib cov ntaub ntawv atca_status.h rau cov lej yuam kev Serial.print (F ("Tsis yooj yim sua ua decryption | Code yuam kev 0x")); Serial.println (xwm txheej, HEX); rov qab; }
Yog tias qhov kev ua tau zoo, koj yuav muaj cov ntaub ntawv decrypted hauv qhov sib txawv "decryptdata".
Tam sim no koj paub yuav siv encryption thiab decryption nrog nti Atecc608a
Kauj Ruam 6: 5. Vim Li Cas Koj Thiaj Li Yuav Tsum Siv Cov Chip no
Cov ntaub ntawv encrypted muaj txiaj ntsig zoo vim tias koj tuaj yeem zais koj cov ntaub ntawv thiab xa nws los ntawm Wireless lossis tsuas yog khaws nws.
Nov yog qee qhov piv txwv ntawm kev siv:
- Khaws cov ntaub ntawv mus rau EEPROM sab nraud: Koj tuaj yeem ruaj ntseg cov ntaub ntawv ntawm EEPROM sab nraud thiab yog tias ib tus neeg tseem EEPROM no, nws yuav xav tau Tus lej thiab IV rau kev txiav txim siab.
- Xa Cov Ntaub Ntawv Wireless: Koj tuaj yeem xa cov ntaub ntawv no encrypted los ntawm Wireless (nrf24L01, RFM95W …) thiab yog tias leej twg cuam tshuam koj cov ntaub ntawv, cov ntaub ntawv no yuav ruaj ntseg
- Khaws tus password
- …
Koj tuaj yeem ua ntau yam nrog cov nti no. Nws tuaj yeem siv hauv ntau qhov haujlwm. Yog tias koj muaj sijhawm, hais rau kuv hauv qhov haujlwm twg koj yuav siv cov nti no?
Ib qho lus qhia zaum kawg, yog tias koj tsim qee qhov haujlwm wireless lossis khaws qee cov ntaub ntawv nyoos, ceev faj, kev nyab xeeb tseem ceeb heev thiab yog tias koj paub nws yooj yim npaum li cas rau "noob" txhawm rau cuam tshuam lossis nyiag koj cov ntaub ntawv. Tam sim no nrog Is Taws Nem, txhua tus tuaj yeem muaj cov ntawv sau tso rau hauv lawv lub computer tsuas yog "hack" koj!
Kauj Ruam 7: Xaus
Kuv vam tias tsab xov xwm no yuav muaj txiaj ntsig zoo rau koj. Thov txim yog tias kuv ua yuam kev hauv kuv cov ntawv tab sis lus Askiv tsis yog kuv hom lus thiab kuv hais tau zoo dua li kuv sau.
Ua tsaug rau kev nyeem txhua yam.
Txaus siab rau nws.
Pom zoo:
IOT Kev Ruaj Ntseg Tsev Ruaj Ntseg: 3 Kauj Ruam
IOT Kev Ruaj Ntseg Hauv Tsev: Ib qho ntawm cov ntawv thov IoT uas muaj txiaj ntsig tshaj plaws yog kev nyab xeeb hauv tsev. Xav txog ib tus tub sab txiav koj lub koob yees duab kev ruaj ntseg xaim thaum sim tsoo rau hauv koj lub tsev, qhov no yuav tsis tshwm sim yog tias koj lub kaw lus kev nyab xeeb mus wireless thiab ntse
DIY Cheep/Cov Dej Ruaj Ruaj Ruaj Ruaj Ruaj Ruaj Ruaj Ruaj Zoo rau Tsiaj: 7 Kauj Ruam
DIY Cheep/Cov Dej Rhaub Dej Zoo rau Cov Tsiaj Tsiaj: Yog li koj tab tom khaws aub/luav/miv/… sab nraum thiab lawv cov dej ua kom khov thaum lub caij ntuj no. Tam sim no ib txwm koj yuav coj lawv mus sab hauv lossis yuav cov tais diav ua kom sov, tab sis cov tsiaj no tej zaum muaj ntxhiab tsw, koj tsis muaj chav nyob, thiab koj tsis tuaj yeem them $ 4
Txhim Kho Kev Ruaj Ntseg Ruaj Ntseg los ntawm Arduino & Fingerprint Sensor: 6 Cov Kauj Ruam
Txhim Kho Kev Ruaj Ntseg Ruaj Ntseg los ntawm Arduino & Fingerprint Sensor: Hauv kab lus no peb xav qhia koj yuav ua li cas txhim kho kev nyab xeeb ntawm koj cov ntaub ntawv digital khaws cia hauv lub hard drive los ntawm tus ntiv tes luam ntawv sensor thiab Arduino. Qhov kawg ntawm kab lus no koj: Yuav kawm paub siv ntiv tes ntsuas lub ntsej muag.Ua li ua kom muaj kev nyab xeeb ntxiv rau f
Nab hab sej Kev Ruaj Ntseg Kev Ruaj Ntseg/Kev Txiav Txim Siab Software: 3 Kauj Ruam
Python Kev Nyab Xeeb Kev Nyab Xeeb/Kev Nyab Xeeb Kev Nyab Xeeb Software: Hauv Cov Lus Qhia Kuv yuav qhia koj li cas nrog qee qhov Python yooj yim, koj tuaj yeem khaws koj cov ntaub ntawv ruaj ntseg siv kev lag luam tus qauv AES.Requirements:- Python 3.7- PyAesCrypt library- hashlib libraryIf koj tsis muaj cov tsev qiv ntawv no, koj tuaj yeem teeb tsa tau yooj yim los ntawm
Tsho Ruaj Ntseg Ruaj Ntseg: Kev Ruaj Ntseg Ris Tsho LED Tsho: 11 Cov Kauj Ruam (nrog Duab)
Ris tsho Ruaj Ntseg Ruaj Ntseg: Kev Ruaj Ntseg Zoo LED Jacket: Txhim kho lub teeb yuag thiab siv tau cov khoom siv hluav taws xob tau qhib qhov muaj peev xwm tshiab rau kev siv thev naus laus zis mus rau hauv lub tebchaws thiab siv nws los ua kom muaj kev nyab xeeb ntawm cov neeg tshawb nrhiav. Txog rau qhov haujlwm no, Kuv kos kuv tus kheej kev paub nrog kev tawm sab nraud