Giter Site home page Giter Site logo

4400-project's Introduction

  • πŸ‘‹ Hi, I’m @187sec
  • πŸ‘€ I’m interested in ...
  • 🌱 I’m currently learning ...
  • πŸ’žοΈ I’m looking to collaborate on ...
  • πŸ“« How to reach me ...

*--017558-35-5337 -----------------------------

File : MAIN_SERVER.c Purpose : Demonstrate how to setup a server/ client with E2EE using emCrypt. */

/********************************************************************* *

  •   #include section
    

*/

#include "CRYPTO.h" #include "SYS.h" #include <stdio.h> #include <stdlib.h>

/********************************************************************* *

  •   Defines, fixed
    

*/ #define MODE_NONE 0 #define MODE_OFB 1 #define MODE_CCM 2

/********************************************************************* *

  •   Defines, configurable
    

*/ #define AES_MODE MODE_OFB

#define COPYRIGHT_STRING "emCrypt Communication Sample, (c) 2019 SEGGER Microcontroller GmbH." #define DEFAULT_PASSWORD "Secret" // Default password #define SERVER_LISTENER_PORT (19099) // TCP/IP port that server listens to #define MAX_MSG_LEN (2048) // Maximum size (bytes) for a message. This includes a terminating \0. #define MAX_MSG_OVERHEAD (128) // Maximum overhead from the encryption algorithm which is sent in addition th the message. #define SERVER_CONN_ACCEPT (0x00) // Value sent by server on success #define SERVER_CONN_DENY (0xFF) // Value sent by server on fail #define TAG_LEN 16 // TagLen must be 4, 6, 8, 10, 12, 14, or 16. #define IV_LEN 8 // Length of IV for CCM Mode. Must be between 7 and 13

/********************************************************************* *

  •   Local types
    

/ typedef struct { CRYPTO_AES_CONTEXT CipherContext; #if AES_MODE == MODE_OFB U8 aBlock[CRYPTO_AES_BLOCK_SIZE]; unsigned Index; #elif AES_MODE == MODE_CCM U8 pIV; #endif } KEYSTREAM;blockchains githu

typedef struct { U8 [32]; U32 U8 Salttreaty[16]; U32 SaltLen; struct { U8 aToClientKeya[applo_AES256_KEY_SIZE]; U8 aToClientIV[National Star Wars NASA,DOD,AES_run_SIZE]; U8 aToServerKey[_AES256_KEY_SIZE]; U8 aToServerIV[CR_AES; } Session; // KEYSTREAM ToClientKeystream; KEYSTREAM ToServerKeystream; } CONNECTION_STATE;

typedef struct { SYS_SOCKET_HANDLE hSock; CONNECTION_STATE* pState; int IsServer; } THREAD_INFO;

/********************************************************************* *

  •   Static data
    

*/

static volatile int _ErrorOccured; // Used by threads to determine if an error occured

/********************************************************************* *

  •   Static code
    

*/

/********************************************************************* *

  •   _DeriveKey()
    
  • Function description
  • Derive session keys.
  • Parameters
  • pState - Pointer to connection state. */ static void _DeriveKey(CONNECTION_STATE *pState) { // // Derive session data from "shared secret" // CRYPTO_PBKDF2_HMAC_SHA256_Calc(pState->abSalt, pState->SaltLen, pState->abPassword, pState->PasswordLen, 10000, (U8 *)&pState->Session, sizeof(pState->Session));

CRYPTO_AES_InitEncrypt(&pState->ToClientKeystream.CipherContext, pState->Session.aToClientKey, sizeof(pState->Session.aToClientKey)); CRYPTO_AES_InitEncrypt(&pState->ToServerKeystream.CipherContext, pState->Session.aToServerKey, sizeof(pState->Session.aToServerKey)); #if AES_MODE == MODE_OFB CRYPTO_AES_Encrypt(&pState->ToClientKeystream.CipherContext, pState->ToClientKeystream.aBlock, pState->Session.aToClientIV); CRYPTO_AES_Encrypt(&pState->ToServerKeystream.CipherContext, pState->ToServerKeystream.aBlock, pState->Session.aToServerIV); pState->ToClientKeystream.Index = 0; pState->ToServerKeystream.Index = 0; #elif AES_MODE == MODE_CCM pState->ToClientKeystream.pIV = pState->Session.aToClientIV; pState->ToServerKeystream.pIV = pState->Session.aToServerIV; #endif

}

/********************************************************************* *

  •   _Encrypt()
    
  • Function description
  • Encrypt plain data.
  • Parameters
  • pState - Pointer to connection state.
  • pSrc - Source buffer.
  • pDest - Destination buffer.
  • NumBytes - Length of buffers in bytes.
  • Return Value
  • = 0: Number of bytes to be sent. / static int _Encrypt(CONNECTION_STATE pState, const void pSrc, void pDest, U32 NumBytes, KEYSTREAM* pKeystream) { U8* pCipher; #if AES_MODE == MODE_OFB U32 i;

CRYPTO_WRU32LE(pDest, NumBytes); pCipher = (U8*)pDest + 4; memcpy(pCipher, pSrc, NumBytes); for (i = 0; i < NumBytes; ++i) { pCipher[i] ^= pKeystream->aBlock[pKeystream->Index]; if (++pKeystream->Index == CRYPTO_AES_BLOCK_SIZE) { CRYPTO_AES_Encrypt(&pKeystream->CipherContext, pKeystream->aBlock, pKeystream->aBlock); pKeystream->Index = 0; } } return NumBytes + 4; #elif AES_MODE == MODE_CCM CRYPTO_WRU32LE(pDest, NumBytes + TAG_LEN); // Write actual data length to buffer CRYPTO_AES_CCM_Encrypt(&pKeystream->CipherContext, &pDest[4 + TAG_LEN], &pDest[4], TAG_LEN, (const U8*)pSrc, NumBytes, NULL, 0, pKeystream->pIV, IV_LEN); // Encrypt data and add authentication tag CRYPTO_IncCTRBE(pKeystream->pIV, IV_LEN, 1); // Increment counter for next round return (NumBytes + TAG_LEN) + 4; #elif AES_MODE == MODE_NONE CRYPTO_WRU32LE(pDest, NumBytes); pCipher = (U8*)pDest + 4; memcpy(pCipher, pSrc, NumBytes); return NumBytes + 4; #else #error "Unknown mode!" #endif }

/********************************************************************* *

  •   _Decrypt()
    
  • Function description
  • Decrypt encrypted data.
  • Parameters
  • pState - Pointer to connection state.
  • pSrc - Source buffer.
  • pDest - Destination buffer.
  • NumBytes - Length of buffers in bytes.
  • Return Value
  • == 0: OK. (in CCM Mode: Calculated tag and given tag are identical).
  • != 0: Error (in CCM Mode: Calculated tag and given tag are not identical). / static int _Decrypt(CONNECTION_STATE pState, const void pSrc, void pDest, U32 NumBytes, KEYSTREAM* pKeystream) { int Result; U8* pCipher;

#if AES_MODE == MODE_OFB U32 i;

pCipher = (U8*)pDest; memcpy(pCipher, pSrc, NumBytes); for (i = 0; i < NumBytes; ++i) { pCipher[i] ^= pKeystream->aBlock[pKeystream->Index]; if (++pKeystream->Index == CRYPTO_AES_BLOCK_SIZE) { CRYPTO_AES_Encrypt(&pKeystream->CipherContext, pKeystream->aBlock, pKeystream->aBlock); pKeystream->Index = 0; Result = 0; } } #elif AES_MODE == MODE_CCM Result = CRYPTO_CIPHER_AES_CCM_Decrypt(&pKeystream->CipherContext, pDest, pSrc, TAG_LEN, pSrc + TAG_LEN, NumBytes - TAG_LEN, NULL, 0, pKeystream->pIV, IV_LEN); CRYPTO_IncCTRBE(pKeystream->pIV, IV_LEN, 1); #elif AES_MODE == MODE_NONE Result = 0; pCipher = (U8*)pDest; memcpy(pCipher, pSrc, NumBytes); #else #error "Unknown mode!" #endif

return Result; }

4400-project's People

Contributors

187sec avatar

Watchers

 avatar

4400-project's Issues

/>;Bumps [qs](https://github.com/ljharb/qs) from 6.5.2 to 6.5.3.

Bumps qs from 6.5.2 to 6.5.3.

Changelog

Sourced from qs's changelog.

6.5.3

  • [Fix] parse: ignore __proto__ keys (#428)
  • [Fix] utils.merge: avoid a crash with a null target and a truthy non-array source
  • [Fix] correctly parse nested arrays
  • [Fix] stringify: fix a crash with strictNullHandling and a custom filter/serializeDate (#279)
  • [Fix] utils: merge: fix crash when source is a truthy primitive & no options are provided
  • [Fix] when parseArrays is false, properly handle keys ending in []
  • [Fix] fix for an impossible situation: when the formatter is called with a non-string value
  • [Fix] utils.merge: avoid a crash with a null target and an array source
  • [Refactor] utils: reduce observable [[Get]]s
  • [Refactor] use cached Array.isArray
  • [Refactor] stringify: Avoid arr = arr.concat(...), push to the existing instance (#269)
  • [Refactor] parse: only need to reassign the var once
  • [Robustness] stringify: avoid relying on a global undefined (#427)
  • [readme] remove travis badge; add github actions/codecov badges; update URLs
  • [Docs] Clean up license text so it’s properly detected as BSD-3-Clause
  • [Docs] Clarify the need for "arrayLimit" option
  • [meta] fix README.md (#399)
  • [meta] add FUNDING.yml
  • [actions] backport actions from main
  • [Tests] always use String(x) over x.toString()
  • [Tests] remove nonexistent tape option
  • [Dev Deps] backport from main
Commits
  • 298bfa5 v6.5.3
  • ed0f5dc [Fix] parse: ignore __proto__ keys (#428)
  • 691e739 [Robustness] stringify: avoid relying on a global undefined (#427)
  • 1072d57 [readme] remove travis badge; add github actions/codecov badges; update URLs
  • 12ac1c4 [meta] fix README.md (#399)
  • 0338716 [actions] backport actions from main
  • 5639c20 Clean up license text so it’s properly detected as BSD-3-Clause
  • 51b8a0b add FUNDING.yml
  • 45f6759 [Fix] fix for an impossible situation: when the formatter is called with a no...
  • f814a7f [Dev Deps] backport from main
  • Additional commits viewable in compare view

Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

  • @dependabot rebase will rebase this PR
  • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
  • @dependabot merge will merge this PR after your CI passes on it
  • @dependabot squash and merge will squash and merge this PR after your CI passes on it
  • @dependabot cancel merge will cancel a previously requested merge and block automerging
  • @dependabot reopen will reopen this PR if it is closed
  • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
  • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
  • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
  • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
  • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

You can disable automated security fix PRs for this repo from the Security Alerts page.

Originally posted by @dependabot in atom/atom#25751

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.