Skip to content

Instantly share code, notes, and snippets.

View VNovytskyi's full-sized avatar
🏠
Working from home

Vladyslav Novytskyi VNovytskyi

🏠
Working from home
  • Kyiv, Ukraine
View GitHub Profile
@VNovytskyi
VNovytskyi / arduino-avr-ethernet-dns-resolve.ino
Created June 9, 2022 13:35
AVR Ethernet DNS example: hostname => IP
#include <SPI.h>
#include <Dns.h>
#include <Ethernet.h>
uint8_t mac[6];
void setup() {
Serial.begin(115200);
Serial.println(F("System initialization start..."));
@VNovytskyi
VNovytskyi / arduino-esp32-dns-resolve.ino
Created June 9, 2022 10:14
ESP32 DNS example: hostname => IP
#include <WiFi.h>
#define WIFI_SSID ""
#define WIFI_PASS ""
#define DNS_TEST_DOMAIN "google.com"
void setup() {
Serial.begin(115200);
Serial.printf("\n\nStart initialization...\n");
@VNovytskyi
VNovytskyi / w5500_socket_test.c
Created June 1, 2022 18:14
Test socket connect W5500
static void socket_test(void) {
int8_t ret = socket(MQTT_SOCKET, Sn_MR_TCP, 3, 0);
if (ret != MQTT_SOCKET) {
LOG_E("Fail to create socket: %d\n", ret);
return;
}
LOG_I("Socket has been created\n");
uint16_t port = 1883;
uint8_t mqtt_server_ip[4] = {192, 168, 0, 156};
@VNovytskyi
VNovytskyi / aes-gcm-dec-auth.cpp
Created March 12, 2022 12:00
Arduino ESP32 AES-GCM decryption with Tag
#include "base64_app.h"
#include "mbedtls/gcm.h"
#define AES_GCM_APP_AES_TAG_SIZE_BYTES 16
const char *key_p = "u56TiiWSiQ76L/t6X5C98TbATFDeUvTh5PfJsZv7H84=";
const char *iv_p = "Zidvdg8Z0bvmzr6K/hd7UQ==";
const char *ciphertext_p = "70iQkg0mqML48Y1A0Mh5TROe+qD4jX7f5jjSwo0p/MVLuG4O";
const char *plaintext_test_p = "Hello world from JS!";
@VNovytskyi
VNovytskyi / aes-gcm-enc-auth.cpp
Created March 12, 2022 11:33
Arduino ESP32 AES-GCM encryption with Tag
#include "base64_app.h"
#include "mbedtls/gcm.h"
#include "mbedtls/error.h"
#define AES_GCM_APP_AES_TAG_SIZE_BYTES 16
mbedtls_gcm_context aes;
const char *key_base64_p = "1BpsjPJ1Hiob0BZ1F491UpvPKiyxjRlUIibijcgEHPg=";
@VNovytskyi
VNovytskyi / rsa-oaep-dec-b64.cpp
Created March 12, 2022 11:13
Arduino ESP32 RSA OAEP decryption with Base64 decoding
#include "mbedtls/pk.h"
#include "mbedtls/rsa.h"
#include "mbedtls/error.h"
#include "mbedtls/base64.h"
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#define PERS "rsa_encrypt"
const char* esp_pub_key_pem_test = "-----BEGIN PUBLIC KEY-----\n\
@VNovytskyi
VNovytskyi / rsa-oaep-enc-b64.cpp
Last active March 12, 2022 11:18
Arduino ESP32 RSA OAEP encryption with Base64 encoding
#include "mbedtls/pk.h"
#include "mbedtls/rsa.h"
#include "mbedtls/error.h"
#include "mbedtls/base64.h"
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#define PERS "rsa_encrypt"
mbedtls_pk_context public_key;
@VNovytskyi
VNovytskyi / parse_rsa_pub_key_pem_str.cpp
Created March 12, 2022 10:33
Arduino ESP32 Parsing RSA public key in PEM format from string
#include "mbedtls/pk.h"
#include "mbedtls/error.h"
mbedtls_pk_context pk;
const char* esp_pub_key_pem_test = "-----BEGIN PUBLIC KEY-----\n\
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXn7jOg8QBSKJNmN4FqWtXa/+9\n\
BbOpHdtN7k9ij95xQmLPV/DptPPKgM6mhK4k7va3ftD+Gv7LcmPELCPMqIvq2aLf\n\
tgAb80HyHorfk6zQfNcyyJ0fblpyVschCMtO3qD4wahLlUcECf7uyVRFBHPxVrwi\n\
UmK6TCiIjnSF2QahywIDAQAB\n\
@VNovytskyi
VNovytskyi / decode_base64_mbedtls.cpp
Created March 12, 2022 10:28
Arduino ESP32 Base64 decoding with MBedTLS
#include "mbedtls/base64.h"
#include "mbedtls/error.h"
size_t get_decoded_size(const char *base64_str_p) {
if (base64_str_p == NULL) {
return 0;
}
size_t pad_char_count = 0;
size_t base64_str_len = strlen(base64_str_p);
@VNovytskyi
VNovytskyi / encode_base64_mbedtls.cpp
Last active March 11, 2022 19:45
Arduino ESP32 Base64 encoding with MBedTLS
#include "mbedtls/base64.h"
#include "mbedtls/error.h"
size_t get_encoded_size(size_t plain_data_size) {
return (4 * ceil((double)plain_data_size / 3)) + 1;
}
void setup() {
const char *test_data_p = "Hello world";