Compare commits
8 Commits
simmel
...
crypto-aes
Author | SHA1 | Date |
---|---|---|
|
649d3371a8 | 2 years ago |
|
51dbe9109f | 2 years ago |
|
507e17fbf1 | 2 years ago |
|
ff9e388910 | 2 years ago |
|
c04e6d6f52 | 2 years ago |
|
3537ad4059 | 2 years ago |
|
33720af0c6 | 2 years ago |
|
3ed5b87b8f | 2 years ago |
27 changed files with 1655 additions and 12 deletions
@ -0,0 +1,184 @@
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
* |
||||
* The MIT License (MIT) |
||||
* |
||||
* Copyright (c) 2017 Glenn Ruben Bakke |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
* of this software and associated documentation files (the "Software"), to deal |
||||
* in the Software without restriction, including without limitation the rights |
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
* copies of the Software, and to permit persons to whom the Software is |
||||
* furnished to do so, subject to the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included in |
||||
* all copies or substantial portions of the Software. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
* THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include <stdint.h> |
||||
|
||||
extern uint32_t _estack; |
||||
extern uint32_t _sidata; |
||||
extern uint32_t _sdata; |
||||
extern uint32_t _edata; |
||||
extern uint32_t _sbss; |
||||
extern uint32_t _ebss; |
||||
|
||||
typedef void (*func)(void); |
||||
|
||||
#define _start main |
||||
|
||||
extern void _start(void) __attribute__((noreturn)); |
||||
extern void SystemInit(void); |
||||
|
||||
void Default_Handler(void) { |
||||
while (1); |
||||
} |
||||
|
||||
void Reset_Handler(void) { |
||||
uint32_t * p_src = &_sidata; |
||||
uint32_t * p_dest = &_sdata; |
||||
|
||||
while (p_dest < &_edata) { |
||||
*p_dest++ = *p_src++; |
||||
} |
||||
|
||||
uint32_t * p_bss = &_sbss; |
||||
uint32_t * p_bss_end = &_ebss; |
||||
while (p_bss < p_bss_end) { |
||||
*p_bss++ = 0ul; |
||||
} |
||||
|
||||
SystemInit(); |
||||
_start(); |
||||
} |
||||
|
||||
void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void HardFault_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void MemoryManagement_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void BusFault_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void UsageFault_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void DebugMon_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void PendSV_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void SysTick_Handler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
|
||||
void POWER_CLOCK_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void RADIO_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void UARTE0_UART0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void NFCT_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void GPIOTE_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void SAADC_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void TIMER0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void TIMER1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void TIMER2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void RTC0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void TEMP_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void RNG_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void ECB_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void CCM_AAR_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void WDT_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void RTC1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void QDEC_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void COMP_LPCOMP_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void SWI0_EGU0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void SWI1_EGU1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void SWI2_EGU2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void SWI3_EGU3_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void SWI4_EGU4_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void SWI5_EGU5_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void TIMER3_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void TIMER4_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void PWM0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void PDM_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void MWU_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void PWM1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void PWM2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void SPIM2_SPIS2_SPI2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void RTC2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void I2S_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void FPU_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void USBD_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void UARTE1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void PWM3_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
void SPIM3_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler"))); |
||||
|
||||
const func __Vectors[] __attribute__ ((used, section(".isr_vector"))) = { |
||||
(func)&_estack, |
||||
Reset_Handler, |
||||
NMI_Handler, |
||||
HardFault_Handler, |
||||
MemoryManagement_Handler, |
||||
BusFault_Handler, |
||||
UsageFault_Handler, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
SVC_Handler, |
||||
DebugMon_Handler, |
||||
0, |
||||
PendSV_Handler, |
||||
SysTick_Handler, |
||||
|
||||
/* External Interrupts */ |
||||
POWER_CLOCK_IRQHandler, |
||||
RADIO_IRQHandler, |
||||
UARTE0_UART0_IRQHandler, |
||||
SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler, |
||||
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler, |
||||
NFCT_IRQHandler, |
||||
GPIOTE_IRQHandler, |
||||
SAADC_IRQHandler, |
||||
TIMER0_IRQHandler, |
||||
TIMER1_IRQHandler, |
||||
TIMER2_IRQHandler, |
||||
RTC0_IRQHandler, |
||||
TEMP_IRQHandler, |
||||
RNG_IRQHandler, |
||||
ECB_IRQHandler, |
||||
CCM_AAR_IRQHandler, |
||||
WDT_IRQHandler, |
||||
RTC1_IRQHandler, |
||||
QDEC_IRQHandler, |
||||
COMP_LPCOMP_IRQHandler, |
||||
SWI0_EGU0_IRQHandler, |
||||
SWI1_EGU1_IRQHandler, |
||||
SWI2_EGU2_IRQHandler, |
||||
SWI3_EGU3_IRQHandler, |
||||
SWI4_EGU4_IRQHandler, |
||||
SWI5_EGU5_IRQHandler, |
||||
TIMER3_IRQHandler, |
||||
TIMER4_IRQHandler, |
||||
PWM0_IRQHandler, |
||||
PDM_IRQHandler, |
||||
0, |
||||
0, |
||||
MWU_IRQHandler, |
||||
PWM1_IRQHandler, |
||||
PWM2_IRQHandler, |
||||
SPIM2_SPIS2_SPI2_IRQHandler, |
||||
RTC2_IRQHandler, |
||||
I2S_IRQHandler, |
||||
FPU_IRQHandler, |
||||
USBD_IRQHandler, |
||||
UARTE1_IRQHandler, |
||||
0, |
||||
0, |
||||
0, |
||||
0, |
||||
PWM3_IRQHandler, |
||||
0, |
||||
SPIM3_IRQHandler, |
||||
}; |
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
* |
||||
* The MIT License (MIT) |
||||
* |
||||
* Copyright (c) 2018 Dan Halbert for Adafruit Industries |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
* of this software and associated documentation files (the "Software"), to deal |
||||
* in the Software without restriction, including without limitation the rights |
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
* copies of the Software, and to permit persons to whom the Software is |
||||
* furnished to do so, subject to the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included in |
||||
* all copies or substantial portions of the Software. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
* THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "py/obj.h" |
||||
#include "py/mphal.h" |
||||
#include "nrf/pins.h" |
||||
|
||||
const mcu_pin_obj_t pin_P0_00 = PIN(P0_00, 0, 0, 0); |
||||
const mcu_pin_obj_t pin_P0_01 = PIN(P0_01, 0, 1, 0); |
||||
const mcu_pin_obj_t pin_P0_02 = PIN(P0_02, 0, 2, SAADC_CH_PSELP_PSELP_AnalogInput0); |
||||
const mcu_pin_obj_t pin_P0_03 = PIN(P0_03, 0, 3, SAADC_CH_PSELP_PSELP_AnalogInput1); |
||||
const mcu_pin_obj_t pin_P0_04 = PIN(P0_04, 0, 4, SAADC_CH_PSELP_PSELP_AnalogInput2); |
||||
const mcu_pin_obj_t pin_P0_05 = PIN(P0_05, 0, 5, SAADC_CH_PSELP_PSELP_AnalogInput3); |
||||
const mcu_pin_obj_t pin_P0_06 = PIN(P0_06, 0, 6, 0); |
||||
const mcu_pin_obj_t pin_P0_07 = PIN(P0_07, 0, 7, 0); |
||||
const mcu_pin_obj_t pin_P0_08 = PIN(P0_08, 0, 8, 0); |
||||
const mcu_pin_obj_t pin_P0_09 = PIN(P0_09, 0, 9, 0); |
||||
const mcu_pin_obj_t pin_P0_10 = PIN(P0_10, 0, 10, 0); |
||||
const mcu_pin_obj_t pin_P0_11 = PIN(P0_11, 0, 11, 0); |
||||
const mcu_pin_obj_t pin_P0_12 = PIN(P0_12, 0, 12, 0); |
||||
const mcu_pin_obj_t pin_P0_13 = PIN(P0_13, 0, 13, 0); |
||||
const mcu_pin_obj_t pin_P0_14 = PIN(P0_14, 0, 14, 0); |
||||
const mcu_pin_obj_t pin_P0_15 = PIN(P0_15, 0, 15, 0); |
||||
const mcu_pin_obj_t pin_P0_16 = PIN(P0_16, 0, 16, 0); |
||||
const mcu_pin_obj_t pin_P0_17 = PIN(P0_17, 0, 17, 0); |
||||
const mcu_pin_obj_t pin_P0_18 = PIN(P0_18, 0, 18, 0); |
||||
const mcu_pin_obj_t pin_P0_19 = PIN(P0_19, 0, 19, 0); |
||||
const mcu_pin_obj_t pin_P0_20 = PIN(P0_20, 0, 20, 0); |
||||
const mcu_pin_obj_t pin_P0_21 = PIN(P0_21, 0, 21, 0); |
||||
const mcu_pin_obj_t pin_P0_22 = PIN(P0_22, 0, 22, 0); |
||||
const mcu_pin_obj_t pin_P0_23 = PIN(P0_23, 0, 23, 0); |
||||
const mcu_pin_obj_t pin_P0_24 = PIN(P0_24, 0, 24, 0); |
||||
const mcu_pin_obj_t pin_P0_25 = PIN(P0_25, 0, 25, 0); |
||||
const mcu_pin_obj_t pin_P0_26 = PIN(P0_26, 0, 26, 0); |
||||
const mcu_pin_obj_t pin_P0_27 = PIN(P0_27, 0, 27, 0); |
||||
const mcu_pin_obj_t pin_P0_28 = PIN(P0_28, 0, 28, SAADC_CH_PSELP_PSELP_AnalogInput4); |
||||
const mcu_pin_obj_t pin_P0_29 = PIN(P0_29, 0, 29, SAADC_CH_PSELP_PSELP_AnalogInput5); |
||||
const mcu_pin_obj_t pin_P0_30 = PIN(P0_30, 0, 30, SAADC_CH_PSELP_PSELP_AnalogInput6); |
||||
const mcu_pin_obj_t pin_P0_31 = PIN(P0_31, 0, 31, SAADC_CH_PSELP_PSELP_AnalogInput7); |
||||
const mcu_pin_obj_t pin_P1_00 = PIN(P1_00, 1, 0, 0); |
||||
const mcu_pin_obj_t pin_P1_01 = PIN(P1_01, 1, 1, 0); |
||||
const mcu_pin_obj_t pin_P1_02 = PIN(P1_02, 1, 2, 0); |
||||
const mcu_pin_obj_t pin_P1_03 = PIN(P1_03, 1, 3, 0); |
||||
const mcu_pin_obj_t pin_P1_04 = PIN(P1_04, 1, 4, 0); |
||||
const mcu_pin_obj_t pin_P1_05 = PIN(P1_05, 1, 5, 0); |
||||
const mcu_pin_obj_t pin_P1_06 = PIN(P1_06, 1, 6, 0); |
||||
const mcu_pin_obj_t pin_P1_07 = PIN(P1_07, 1, 7, 0); |
||||
const mcu_pin_obj_t pin_P1_08 = PIN(P1_08, 1, 8, 0); |
||||
const mcu_pin_obj_t pin_P1_09 = PIN(P1_09, 1, 9, 0); |
@ -0,0 +1,73 @@
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
* |
||||
* The MIT License (MIT) |
||||
* |
||||
* Copyright (c) 2018 by Dan Halbert for Adafruit Industries |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
* of this software and associated documentation files (the "Software"), to deal |
||||
* in the Software without restriction, including without limitation the rights |
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
* copies of the Software, and to permit persons to whom the Software is |
||||
* furnished to do so, subject to the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included in |
||||
* all copies or substantial portions of the Software. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
* THE SOFTWARE. |
||||
*/ |
||||
|
||||
#ifndef MICROPY_INCLUDED_NRF_PERIPHERALS_NRF52833_PINS_H |
||||
#define MICROPY_INCLUDED_NRF_PERIPHERALS_NRF52833_PINS_H |
||||
|
||||
extern const mcu_pin_obj_t pin_P0_00; |
||||
extern const mcu_pin_obj_t pin_P0_01; |
||||
extern const mcu_pin_obj_t pin_P0_02; |
||||
extern const mcu_pin_obj_t pin_P0_03; |
||||
extern const mcu_pin_obj_t pin_P0_04; |
||||
extern const mcu_pin_obj_t pin_P0_05; |
||||
extern const mcu_pin_obj_t pin_P0_06; |
||||
extern const mcu_pin_obj_t pin_P0_07; |
||||
extern const mcu_pin_obj_t pin_P0_08; |
||||
extern const mcu_pin_obj_t pin_P0_09; |
||||
extern const mcu_pin_obj_t pin_P0_10; |
||||
extern const mcu_pin_obj_t pin_P0_11; |
||||
extern const mcu_pin_obj_t pin_P0_12; |
||||
extern const mcu_pin_obj_t pin_P0_13; |
||||
extern const mcu_pin_obj_t pin_P0_14; |
||||
extern const mcu_pin_obj_t pin_P0_15; |
||||
extern const mcu_pin_obj_t pin_P0_16; |
||||
extern const mcu_pin_obj_t pin_P0_17; |
||||
extern const mcu_pin_obj_t pin_P0_18; |
||||
extern const mcu_pin_obj_t pin_P0_19; |
||||
extern const mcu_pin_obj_t pin_P0_20; |
||||
extern const mcu_pin_obj_t pin_P0_21; |
||||
extern const mcu_pin_obj_t pin_P0_22; |
||||
extern const mcu_pin_obj_t pin_P0_23; |
||||
extern const mcu_pin_obj_t pin_P0_24; |
||||
extern const mcu_pin_obj_t pin_P0_25; |
||||
extern const mcu_pin_obj_t pin_P0_26; |
||||
extern const mcu_pin_obj_t pin_P0_27; |
||||
extern const mcu_pin_obj_t pin_P0_28; |
||||
extern const mcu_pin_obj_t pin_P0_29; |
||||
extern const mcu_pin_obj_t pin_P0_30; |
||||
extern const mcu_pin_obj_t pin_P0_31; |
||||
extern const mcu_pin_obj_t pin_P1_00; |
||||
extern const mcu_pin_obj_t pin_P1_01; |
||||
extern const mcu_pin_obj_t pin_P1_02; |
||||
extern const mcu_pin_obj_t pin_P1_03; |
||||
extern const mcu_pin_obj_t pin_P1_04; |
||||
extern const mcu_pin_obj_t pin_P1_05; |
||||
extern const mcu_pin_obj_t pin_P1_06; |
||||
extern const mcu_pin_obj_t pin_P1_07; |
||||
extern const mcu_pin_obj_t pin_P1_08; |
||||
extern const mcu_pin_obj_t pin_P1_09; |
||||
|
||||
#endif // MICROPY_INCLUDED_NRF_PERIPHERALS_NRF52833_PINS_H
|
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
* |
||||
* The MIT License (MIT) |
||||
* |
||||
* Copyright (c) 2018 Dan Halbert for Adafruit Industries |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
* of this software and associated documentation files (the "Software"), to deal |
||||
* in the Software without restriction, including without limitation the rights |
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
* copies of the Software, and to permit persons to whom the Software is |
||||
* furnished to do so, subject to the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included in |
||||
* all copies or substantial portions of the Software. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
* THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "nrfx.h" |
||||
#include "hal/nrf_nvmc.h" |
||||
|
||||
void nrf_peripherals_power_init(void) { |
||||
// Set GPIO reference voltage to 3.3V if it isn't already. REGOUT0 will get reset to 0xfffffff
|
||||
// if flash is erased, which sets the default to 1.8V
|
||||
// This matters only when "high voltage mode" is enabled, which is true on the PCA10059,
|
||||
// and might be true on other boards.
|
||||
if (NRF_UICR->REGOUT0 == 0xffffffff && NRF_POWER->MAINREGSTATUS & 1) { |
||||
// Expand what nrf_nvmc_word_write() did.
|
||||
// It's missing from nrfx V2.0.0, and nrfx_nvmc_word_write() does bounds
|
||||
// checking which prevents writes to UICR.
|
||||
// Reported: https://devzone.nordicsemi.com/f/nordic-q-a/57243/nrfx_nvmc-h-api-cannot-write-to-uicr
|
||||
NRF_NVMC->CONFIG = NRF_NVMC_MODE_WRITE; |
||||
while (!(NRF_NVMC->READY & NVMC_READY_READY_Msk)) {} |
||||
NRF_UICR->REGOUT0 = UICR_REGOUT0_VOUT_3V3 << UICR_REGOUT0_VOUT_Pos; |
||||
__DMB(); |
||||
while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {} |
||||
NRF_NVMC->CONFIG = NRF_NVMC_MODE_READONLY; |
||||
|
||||
// Must reset to enable change.
|
||||
NVIC_SystemReset(); |
||||
} |
||||
} |
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
* |
||||
* The MIT License (MIT) |
||||
* |
||||
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
* of this software and associated documentation files (the "Software"), to deal |
||||
* in the Software without restriction, including without limitation the rights |
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
* copies of the Software, and to permit persons to whom the Software is |
||||
* furnished to do so, subject to the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included in |
||||
* all copies or substantial portions of the Software. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
* THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include <stdint.h> |
||||
|
||||
#include "py/obj.h" |
||||
#include "py/runtime.h" |
||||
|
||||
#include "__init__.h" |
||||
|
||||
//| :mod:`aes` --- AES encryption and decryption routines
|
||||
//| ========================================================
|
||||
//|
|
||||
//| .. module:: aes
|
||||
//| :synopsis: Routines for performing AES encryption and decryption
|
||||
//|
|
||||
//| The `audiocore` module contains core classes for audio IO
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t cipher_module_globals_table[] = { |
||||
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_Cipher)}, |
||||
{MP_OBJ_NEW_QSTR(MP_QSTR_AES), MP_ROM_PTR(&aes_module)}, |
||||
}; |
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(cipher_module_globals, cipher_module_globals_table); |
||||
|
||||
const mp_obj_module_t cipher_module = { |
||||
{&mp_type_module}, |
||||
.globals = (mp_obj_dict_t *)&cipher_module_globals, |
||||
}; |
||||
|
||||
STATIC const mp_rom_map_elem_t crypto_module_globals_table[] = { |
||||
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_Crypto)}, |
||||
{MP_OBJ_NEW_QSTR(MP_QSTR_Cipher), MP_ROM_PTR(&cipher_module)}, |
||||
}; |
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(crypto_module_globals, crypto_module_globals_table); |
||||
|
||||
const mp_obj_module_t crypto_module = { |
||||
.base = {&mp_type_module}, |
||||
.globals = (mp_obj_dict_t *)&crypto_module_globals, |
||||
}; |
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
* |
||||
* The MIT License (MIT) |
||||
* |
||||
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
* of this software and associated documentation files (the "Software"), to deal |
||||
* in the Software without restriction, including without limitation the rights |
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
* copies of the Software, and to permit persons to whom the Software is |
||||
* furnished to do so, subject to the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included in |
||||
* all copies or substantial portions of the Software. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
* THE SOFTWARE. |
||||
*/ |
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_CRYPTO_H |
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_CRYPTO_H |
||||
|
||||
#include "shared-module/crypto/__init__.h" |
||||
|
||||
extern const mp_obj_module_t crypto_module; |
||||
extern const mp_obj_module_t aes_module; |
||||
|
||||
void common_hal_aes_construct(aes_obj_t* self, |
||||
const uint8_t* key, |
||||
uint32_t key_length, |
||||
const uint8_t* iv, |
||||
int mode, |
||||
int counter); |
||||
void common_hal_aes_encrypt(aes_obj_t* self, |
||||
uint8_t* buffer, |
||||
size_t len); |
||||
void common_hal_aes_decrypt(aes_obj_t* self, |
||||
uint8_t* buffer, |
||||
size_t len); |
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_CRYPTO_H
|
@ -0,0 +1,207 @@
@@ -0,0 +1,207 @@
|
||||
#include <stdint.h> |
||||
#include <string.h> |
||||
|
||||
#include "py/obj.h" |
||||
#include "py/runtime.h" |
||||
|
||||
#include "shared-bindings/crypto/__init__.h" |
||||
|
||||
// Defined at the end of this file
|
||||
extern const mp_obj_type_t aescipher_type; |
||||
|
||||
STATIC mp_obj_t aescipher_make_new(size_t n_args, const mp_obj_t *pos_args, |
||||
mp_map_t *kw_args) { |
||||
enum { ARG_key, ARG_mode, ARG_IV, ARG_counter, ARG_segment_size }; |
||||
static const mp_arg_t allowed_args[] = { |
||||
{MP_QSTR_key, MP_ARG_OBJ | MP_ARG_REQUIRED}, |
||||
{MP_QSTR_mode, MP_ARG_INT}, |
||||
{MP_QSTR_IV, MP_ARG_OBJ}, |
||||
{MP_QSTR_counter, MP_ARG_OBJ}, |
||||
{MP_QSTR_segment_size, MP_ARG_INT}, |
||||
}; |
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; |
||||
// Set defaults. These will be overridden in mp_arg_parse_all() if an
|
||||
// argument is provided.
|
||||
args[ARG_mode].u_int = AES_MODE_ECB; |
||||
args[ARG_IV].u_obj = NULL; |
||||
args[ARG_counter].u_int = 0; |
||||
args[ARG_segment_size].u_int = |
||||
8; // Only useful in CFB mode, which we don't support
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), |
||||
allowed_args, args); |
||||
|
||||
aes_obj_t *self = m_new_obj(aes_obj_t); |
||||
self->base.type = &aescipher_type; |
||||
|
||||
mp_buffer_info_t bufinfo; |
||||
|
||||
const uint8_t *key = NULL; |
||||
uint32_t key_length = 0; |
||||
if (mp_get_buffer(args[ARG_key].u_obj, &bufinfo, MP_BUFFER_READ)) { |
||||
if ((bufinfo.len != 16) && (bufinfo.len != 24) && (bufinfo.len != 32)) { |
||||
mp_raise_TypeError(translate("key must be 16, 24, or 32 bytes long")); |
||||
} |
||||
key = bufinfo.buf; |
||||
key_length = bufinfo.len; |
||||
} else { |
||||
mp_raise_TypeError(translate("no key was specified")); |
||||
} |
||||
|
||||
int mode = args[ARG_mode].u_int; |
||||
switch (args[ARG_mode].u_int) { |
||||
case AES_MODE_CBC: /* CBC */ |
||||
break; |
||||
case AES_MODE_ECB: /* ECB */ |
||||
break; |
||||
case AES_MODE_CTR: /* CTR */ |
||||
break; |
||||
default: |
||||
mp_raise_TypeError(translate("requested AES mode is unsupported")); |
||||
} |
||||
|
||||
// IV is required for CBC mode and is ignored for other modes.
|
||||
const uint8_t *iv = NULL; |
||||
if (args[ARG_IV].u_obj != NULL && |
||||
mp_get_buffer(args[ARG_IV].u_obj, &bufinfo, MP_BUFFER_READ)) { |
||||
if (bufinfo.len != AES_BLOCKLEN) { |
||||
mp_raise_TypeError_varg(translate("iv must be %d bytes long"), |
||||
AES_BLOCKLEN); |
||||
} |
||||
iv = bufinfo.buf; |
||||
} |
||||
|
||||
common_hal_aes_construct(self, key, key_length, iv, mode, args[ARG_counter].u_int); |
||||
return MP_OBJ_FROM_PTR(self); |
||||
} |
||||
|
||||
// Used when constructing with `new AESCipher`
|
||||
STATIC mp_obj_t aescipher_make_new_new(const mp_obj_type_t *type, size_t n_args, |
||||
const mp_obj_t *pos_args, |
||||
mp_map_t *kw_args) { |
||||
return aescipher_make_new(n_args, pos_args, kw_args); |
||||
} |
||||
|
||||
STATIC byte *duplicate_data(const byte *src_buf, size_t len) { |
||||
byte *dest_buf = m_new(byte, len); |
||||
memcpy(dest_buf, src_buf, len); |
||||
return dest_buf; |
||||
} |
||||
|
||||
STATIC mp_obj_t aescipher_encrypt_in_place(mp_obj_t aes_obj, mp_obj_t buf) { |
||||
if (!MP_OBJ_IS_TYPE(aes_obj, &aescipher_type)) { |
||||
mp_raise_TypeError_varg(translate("Expected a %q"), aescipher_type.name); |
||||
} |
||||
// Convert parameters into expected types.
|
||||
aes_obj_t *aes = MP_OBJ_TO_PTR(aes_obj); |
||||
mp_buffer_info_t bufinfo; |
||||
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); |
||||
if ((bufinfo.len & (AES_BLOCKLEN - 1)) != 0) { |
||||
mp_raise_ValueError(translate("Buffer must be a multiple of 16 bytes")); |
||||
} |
||||
|
||||
common_hal_aes_encrypt(aes, (uint8_t *)bufinfo.buf, bufinfo.len); |
||||
return mp_const_none; |
||||
} |
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(aescipher_encrypt_in_place_obj, |
||||
aescipher_encrypt_in_place); |
||||
|
||||
STATIC mp_obj_t aescipher_encrypt(mp_obj_t aes_obj, mp_obj_t buf) { |
||||
if (!MP_OBJ_IS_TYPE(aes_obj, &aescipher_type)) { |
||||
mp_raise_TypeError_varg(translate("Expected a %q"), aescipher_type.name); |
||||
} |
||||
// Convert parameters into expected types.
|
||||
aes_obj_t *aes = MP_OBJ_TO_PTR(aes_obj); |
||||
mp_buffer_info_t bufinfo; |
||||
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); |
||||
if ((bufinfo.len & (AES_BLOCKLEN - 1)) != 0) { |
||||
mp_raise_ValueError(translate("Buffer must be a multiple of 16 bytes")); |
||||
} |
||||
|
||||
byte *dest_buf = duplicate_data((const byte *)bufinfo.buf, bufinfo.len); |
||||
common_hal_aes_encrypt(aes, (uint8_t *)dest_buf, bufinfo.len); |
||||
|
||||
return mp_obj_new_bytearray_by_ref(bufinfo.len, dest_buf); |
||||
} |
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(aescipher_encrypt_obj, aescipher_encrypt); |
||||
|
||||
STATIC mp_obj_t aescipher_decrypt_in_place(mp_obj_t aes_obj, mp_obj_t buf) { |
||||
if (!MP_OBJ_IS_TYPE(aes_obj, &aescipher_type)) { |
||||
mp_raise_TypeError_varg(translate("Expected a %q"), aescipher_type.name); |
||||
} |
||||
// Convert parameters into expected types.
|
||||
aes_obj_t *aes = MP_OBJ_TO_PTR(aes_obj); |
||||
mp_buffer_info_t bufinfo; |
||||
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); |
||||
if ((bufinfo.len & (AES_BLOCKLEN - 1)) != 0) { |
||||
mp_raise_ValueError(translate("Buffer must be a multiple of 16 bytes")); |
||||
} |
||||
common_hal_aes_decrypt(aes, (uint8_t *)bufinfo.buf, bufinfo.len); |
||||
return mp_const_none; |
||||
} |
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(aescipher_decrypt_in_place_obj, |
||||
aescipher_decrypt_in_place); |
||||
|
||||
STATIC mp_obj_t aescipher_decrypt(mp_obj_t aes_obj, mp_obj_t buf) { |
||||
if (!MP_OBJ_IS_TYPE(aes_obj, &aescipher_type)) { |
||||
mp_raise_TypeError_varg(translate("Expected a %q"), aescipher_type.name); |
||||
} |
||||
// Convert parameters into expected types.
|
||||
aes_obj_t *aes = MP_OBJ_TO_PTR(aes_obj); |
||||
mp_buffer_info_t bufinfo; |
||||
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); |
||||
if ((bufinfo.len & (AES_BLOCKLEN - 1)) != 0) { |
||||
mp_raise_ValueError(translate("Buffer must be a multiple of 16 bytes")); |
||||
} |
||||
|
||||
byte *dest_buf = duplicate_data((const byte *)bufinfo.buf, bufinfo.len); |
||||
common_hal_aes_decrypt(aes, (uint8_t *)dest_buf, bufinfo.len); |
||||
return mp_obj_new_bytearray_by_ref(bufinfo.len, dest_buf); |
||||
} |
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(aescipher_decrypt_obj, aescipher_decrypt); |
||||
|
||||
STATIC const mp_obj_tuple_t mp_crypto_aes_key_size_obj = { |
||||
{&mp_type_tuple}, |
||||
3, |
||||
{ |
||||
MP_OBJ_NEW_SMALL_INT(16), |
||||
MP_OBJ_NEW_SMALL_INT(24), |
||||
MP_OBJ_NEW_SMALL_INT(32), |
||||
}}; |
||||
|
||||
STATIC const mp_rom_map_elem_t aescipher_locals_dict_table[] = { |
||||
// Methods
|
||||
{MP_ROM_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_AES)}, |
||||
{MP_ROM_QSTR(MP_QSTR_encrypt), (mp_obj_t)&aescipher_encrypt_obj}, |
||||
{MP_ROM_QSTR(MP_QSTR_decrypt), (mp_obj_t)&aescipher_decrypt_obj}, |
||||
{MP_ROM_QSTR(MP_QSTR_encrypt_in_place), |
||||
(mp_obj_t)&aescipher_encrypt_in_place_obj}, |
||||
{MP_ROM_QSTR(MP_QSTR_decrypt_in_place), |
||||
(mp_obj_t)&aescipher_decrypt_in_place_obj}, |
||||
|
||||
}; |
||||
STATIC MP_DEFINE_CONST_DICT(aescipher_locals_dict, aescipher_locals_dict_table); |
||||
|
||||
const mp_obj_type_t aescipher_type = { |
||||
{&mp_type_type}, |
||||
.name = MP_QSTR_AESCipher, |
||||
.make_new = aescipher_make_new_new, |
||||
.locals_dict = (mp_obj_dict_t *)&aescipher_locals_dict, |
||||
}; |
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(aescipher_make_new_obj, 1, aescipher_make_new); |
||||
|
||||
STATIC const mp_rom_map_elem_t aes_module_globals_table[] = { |
||||
{MP_ROM_QSTR(MP_QSTR_MODE_ECB), MP_ROM_INT(AES_MODE_ECB)}, |
||||
{MP_ROM_QSTR(MP_QSTR_MODE_CBC), MP_ROM_INT(AES_MODE_CBC)}, |
||||
{MP_ROM_QSTR(MP_QSTR_MODE_CTR), MP_ROM_INT(AES_MODE_CTR)}, |
||||
{MP_ROM_QSTR(MP_QSTR_block_size), MP_ROM_INT(AES_BLOCKLEN)}, |
||||
{MP_ROM_QSTR(MP_QSTR_key_size), (mp_obj_t)&mp_crypto_aes_key_size_obj}, |
||||
{MP_ROM_QSTR(MP_QSTR_new), MP_ROM_PTR(&aescipher_make_new_obj)}, |
||||
}; |
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(aes_module_globals, aes_module_globals_table); |
||||
|
||||
const mp_obj_module_t aes_module = { |
||||
{&mp_type_module}, |
||||
.globals = (mp_obj_dict_t *)&aes_module_globals, |
||||
}; |
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
#include <string.h> |
||||
|
||||
#include "py/runtime.h" |
||||
|
||||
#include "shared-module/crypto/__init__.h" |
||||
|
||||
void common_hal_aes_construct(aes_obj_t* self, |
||||
const uint8_t* key, |
||||
uint32_t key_length, |
||||
const uint8_t* iv, |
||||
int mode, |
||||
int counter) { |
||||
memset(&self->ctx, 0, sizeof(self->ctx)); |
||||
if (iv != NULL) { |
||||
AES_init_ctx_iv(&self->ctx, key, key_length, iv); |
||||
} else { |
||||
AES_init_ctx(&self->ctx, key, key_length); |
||||
} |
||||
self->mode = mode; |
||||
self->counter = counter; |
||||
} |
||||
|
||||
void common_hal_aes_encrypt(aes_obj_t* self, |
||||
uint8_t* buffer, |
||||
size_t length) { |
||||
switch (self->mode) { |
||||
case AES_MODE_ECB: |
||||
if (length != 16) |
||||
mp_raise_msg(&mp_type_ValueError, translate("ecb only operates on 16 bytes at a time")); |
||||
AES_ECB_encrypt(&self->ctx, buffer); |
||||
break; |
||||
case AES_MODE_CBC: |
||||
if ((length & 15) != 0) |
||||
mp_raise_msg(&mp_type_ValueError, translate("cbc blocks must be multiples of 16 bytes")); |
||||
AES_CBC_encrypt_buffer(&self->ctx, buffer, length); |
||||
break; |
||||
case AES_MODE_CTR: |
||||
AES_CTR_xcrypt_buffer(&self->ctx, buffer, length); |
||||
break; |
||||
default: |
||||
mp_raise_msg(&mp_type_ValueError, translate("unknown encryption mode")); |
||||
} |
||||
} |
||||
|
||||
void common_hal_aes_decrypt(aes_obj_t* self, |
||||
uint8_t* buffer, |
||||
size_t length) { |
||||
switch (self->mode) { |
||||
case AES_MODE_ECB: |
||||
if (length != 16) |
||||
mp_raise_msg(&mp_type_ValueError, translate("ecp only operates on 16 bytes at a time")); |
||||
AES_ECB_decrypt(&self->ctx, buffer); |
||||
break; |
||||
case AES_MODE_CBC: |
||||
if ((length & 15) != 0) |
||||
mp_raise_msg(&mp_type_ValueError, translate("cbc blocks must be multiples of 16 bytes")); |
||||
AES_CBC_decrypt_buffer(&self->ctx, buffer, length); |
||||
break; |
||||
case AES_MODE_CTR: |
||||
AES_CTR_xcrypt_buffer(&self->ctx, buffer, length); |
||||
break; |
||||
default: |
||||
mp_raise_msg(&mp_type_ValueError, translate("unknown encryption mode")); |
||||
} |
||||
} |
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
* |
||||
* The MIT License (MIT) |
||||
* |
||||
* Copyright (c) 2018 Dan Halbert for Adafruit Industries |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
* of this software and associated documentation files (the "Software"), to deal |
||||
* in the Software without restriction, including without limitation the rights |
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
* copies of the Software, and to permit persons to whom the Software is |
||||
* furnished to do so, subject to the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included in |
||||
* all copies or substantial portions of the Software. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
* THE SOFTWARE. |
||||
*/ |
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_MODULE_CRYPTO__INIT__H |
||||
#define MICROPY_INCLUDED_SHARED_MODULE_CRYPTO__INIT__H |
||||
|
||||
#include <stdbool.h> |
||||
#include <stdint.h> |
||||
|
||||
#include "py/obj.h" |
||||
#include "py/proto.h" |
||||
|
||||
#include "shared-module/crypto/aes.h" |
||||
|
||||
enum AES_MODE { |
||||
AES_MODE_ECB = 1, |
||||
AES_MODE_CBC = 2, |
||||
AES_MODE_CTR = 6, |
||||
}; |
||||
|
||||
typedef struct { |
||||
mp_obj_base_t base; |
||||
|
||||
// The tinyaes context
|
||||
struct AES_ctx ctx; |
||||
|
||||
// Which AES mode this instance of the object is configured to use
|
||||
enum AES_MODE mode; |
||||
|
||||
// Counter for running in CTR mode
|
||||
uint32_t counter; |
||||
} aes_obj_t; |
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_MODULE_CRYPTO__INIT__H
|
@ -0,0 +1,608 @@
@@ -0,0 +1,608 @@
|
||||
/*
|
||||
|
||||
This is an implementation of the AES algorithm, specifically ECB, CTR and CBC mode. |
||||
Block size can be chosen in aes.h - available choices are AES128, AES192, AES256. |
||||
|
||||
The implementation is verified against the test vectors in: |
||||
National Institute of Standards and Technology Special Publication 800-38A 2001 ED |
||||
|
||||
ECB-AES128 |
||||
---------- |
||||
|
||||
plain-text: |
||||
6bc1bee22e409f96e93d7e117393172a |
||||
ae2d8a571e03ac9c9eb76fac45af8e51 |
||||
30c81c46a35ce411e5fbc1191a0a52ef |
||||
f69f2445df4f9b17ad2b417be66c3710 |
||||
|
||||
key: |
||||
2b7e151628aed2a6abf7158809cf4f3c |
||||
|
||||
resulting cipher |
||||
3ad77bb40d7a3660a89ecaf32466ef97 |
||||
f5d3d58503b9699de785895a96fdbaaf |
||||
43b1cd7f598ece23881b00e3ed030688 |
||||
7b0c785e27e8ad3f8223207104725dd4 |
||||
|
||||
|
||||
NOTE: String length must be evenly divisible by 16byte (str_len % 16 == 0) |
||||
You should pad the end of the string with zeros if this is not the case. |
||||
For AES192/256 the key size is proportionally larger. |
||||
|
||||
*/ |
||||
|
||||
/*****************************************************************************/ |
||||
/* Includes: */ |
||||
/*****************************************************************************/ |
||||
#include <string.h> // CBC mode, for memset |