Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1613235 - Clang-format for: POWER ChaCha20 stream cipher vector a…
…cceleration r=beurdouche

Depends on D107221

Differential Revision: https://phabricator.services.mozilla.com/D107788

--HG--
extra : moz-landing-system : lando
  • Loading branch information
beurdouche committed Mar 10, 2021
1 parent 983a014 commit 4a0ac18
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
13 changes: 6 additions & 7 deletions cmd/bltest/blapitest.c
Expand Up @@ -803,7 +803,7 @@ struct bltestCipherInfoStr {
PRBool
is_symmkeyCipher(bltestCipherMode mode)
{
/* change as needed! */
/* change as needed! */
if (mode >= bltestDES_ECB && mode <= bltestCHACHA20_CTR)
return PR_TRUE;
return PR_FALSE;
Expand Down Expand Up @@ -1153,8 +1153,8 @@ aes_Decrypt(void *cx, unsigned char *output, unsigned int *outputLen,

SECStatus
chacha20_Encrypt(void *cx, unsigned char *output, unsigned int *outputLen,
unsigned int maxOutputLen, const unsigned char *input,
unsigned int inputLen)
unsigned int maxOutputLen, const unsigned char *input,
unsigned int inputLen)
{
if (maxOutputLen < inputLen) {
PORT_SetError(SEC_ERROR_OUTPUT_LEN);
Expand All @@ -1164,7 +1164,6 @@ chacha20_Encrypt(void *cx, unsigned char *output, unsigned int *outputLen,
*outputLen = inputLen;
return ChaCha20_Xor(output, input, inputLen, ctx->key, ctx->nonce,
ctx->counter);

}

SECStatus
Expand Down Expand Up @@ -1681,7 +1680,7 @@ bltest_chacha20_ctr_init(bltestCipherInfo *cipherInfo, PRBool encrypt)
sk->iv.buf.data, sk->iv.buf.len,
counter);

if (cipherInfo->cx == NULL){
if (cipherInfo->cx == NULL) {
PR_fprintf(PR_STDERR, "ChaCha20_CreateContext() returned NULL\n"
"key must be 32 bytes, iv must be 12 bytes\n");
return SECFailure;
Expand Down Expand Up @@ -2749,10 +2748,10 @@ getHighUnitBytes(PRInt64 res)
}
}

if (i==0)
if (i == 0)
return PR_smprintf("%d%s", spl[i], marks[i]);
else
return PR_smprintf("%d%s %d%s", spl[i], marks[i], spl[i-1], marks[i-1]);
return PR_smprintf("%d%s %d%s", spl[i], marks[i], spl[i - 1], marks[i - 1]);
}

static void
Expand Down
1 change: 0 additions & 1 deletion lib/freebl/blapi.h
Expand Up @@ -1061,7 +1061,6 @@ extern ChaCha20Context *ChaCha20_CreateContext(const unsigned char *key,

extern void ChaCha20_DestroyContext(ChaCha20Context *ctx, PRBool freeit);


/******************************************/
/*
** ChaCha20+Poly1305 AEAD
Expand Down
2 changes: 1 addition & 1 deletion lib/freebl/chacha20poly1305-ppc.c
Expand Up @@ -25,7 +25,7 @@

/* Forward declaration from chacha20-ppc64le.S */
void chacha20vsx(uint32_t len, uint8_t *output, uint8_t *block, uint8_t *k,
uint8_t *nonce, uint32_t ctr);
uint8_t *nonce, uint32_t ctr);

static inline void
poly1305_padded_32(uint64_t *ctx, uint32_t len, uint8_t *text)
Expand Down
22 changes: 11 additions & 11 deletions lib/freebl/chacha20poly1305.c
Expand Up @@ -71,7 +71,7 @@ Hacl_Chacha20Poly1305_32_aead_decrypt(uint8_t *k, uint8_t *n1, uint32_t aadlen,

// Forward declaration from chacha20-ppc64le.S
void chacha20vsx(uint32_t len, uint8_t *output, uint8_t *block, uint8_t *k,
uint8_t *nonce, uint32_t ctr);
uint8_t *nonce, uint32_t ctr);

// Forward declaration from chacha20poly1305-ppc.c
extern void
Expand Down Expand Up @@ -219,8 +219,8 @@ ChaCha20Xor(uint8_t *output, uint8_t *block, uint32_t len, uint8_t *k,
#endif
} else
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__) && \
!defined(NSS_DISABLE_ALTIVEC) && !defined(NSS_DISABLE_CRYPTO_VSX)
if (__builtin_cpu_supports ("vsx")) {
!defined(NSS_DISABLE_ALTIVEC) && !defined(NSS_DISABLE_CRYPTO_VSX)
if (__builtin_cpu_supports("vsx")) {
chacha20vsx(len, output, block, k, nonce, ctr);
} else
#endif
Expand Down Expand Up @@ -292,8 +292,8 @@ ChaCha20Poly1305_Seal(const ChaCha20Poly1305Context *ctx, unsigned char *output,
#endif
} else
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__) && \
!defined(NSS_DISABLE_ALTIVEC) && !defined(NSS_DISABLE_CRYPTO_VSX)
if (__builtin_cpu_supports ("vsx")) {
!defined(NSS_DISABLE_ALTIVEC) && !defined(NSS_DISABLE_CRYPTO_VSX)
if (__builtin_cpu_supports("vsx")) {
Chacha20Poly1305_vsx_aead_encrypt(
(uint8_t *)ctx->key, (uint8_t *)nonce, adLen, (uint8_t *)ad, inputLen,
(uint8_t *)input, output, output + inputLen);
Expand Down Expand Up @@ -361,8 +361,8 @@ ChaCha20Poly1305_Open(const ChaCha20Poly1305Context *ctx, unsigned char *output,
#endif
} else
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__) && \
!defined(NSS_DISABLE_ALTIVEC) && !defined(NSS_DISABLE_CRYPTO_VSX)
if (__builtin_cpu_supports ("vsx")) {
!defined(NSS_DISABLE_ALTIVEC) && !defined(NSS_DISABLE_CRYPTO_VSX)
if (__builtin_cpu_supports("vsx")) {
res = Chacha20Poly1305_vsx_aead_decrypt(
(uint8_t *)ctx->key, (uint8_t *)nonce, adLen, (uint8_t *)ad, ciphertextLen,
(uint8_t *)output, (uint8_t *)input, (uint8_t *)input + ciphertextLen);
Expand Down Expand Up @@ -417,8 +417,8 @@ ChaCha20Poly1305_Encrypt(const ChaCha20Poly1305Context *ctx,
(uint8_t *)input, output, outTag);
} else
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__) && \
!defined(NSS_DISABLE_ALTIVEC) && !defined(NSS_DISABLE_CRYPTO_VSX)
if (__builtin_cpu_supports ("vsx")) {
!defined(NSS_DISABLE_ALTIVEC) && !defined(NSS_DISABLE_CRYPTO_VSX)
if (__builtin_cpu_supports("vsx")) {
Chacha20Poly1305_vsx_aead_encrypt(
(uint8_t *)ctx->key, (uint8_t *)nonce, adLen, (uint8_t *)ad, inputLen,
(uint8_t *)input, output, outTag);
Expand Down Expand Up @@ -471,8 +471,8 @@ ChaCha20Poly1305_Decrypt(const ChaCha20Poly1305Context *ctx,
(uint8_t *)output, (uint8_t *)input, (uint8_t *)tagIn);
} else
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__) && \
!defined(NSS_DISABLE_ALTIVEC) && !defined(NSS_DISABLE_CRYPTO_VSX)
if (__builtin_cpu_supports ("vsx")) {
!defined(NSS_DISABLE_ALTIVEC) && !defined(NSS_DISABLE_CRYPTO_VSX)
if (__builtin_cpu_supports("vsx")) {
res = Chacha20Poly1305_vsx_aead_decrypt(
(uint8_t *)ctx->key, (uint8_t *)nonce, adLen, (uint8_t *)ad, ciphertextLen,
(uint8_t *)output, (uint8_t *)input, (uint8_t *)tagIn);
Expand Down
8 changes: 4 additions & 4 deletions lib/freebl/loader.c
Expand Up @@ -2160,10 +2160,10 @@ ChaCha20_Xor(unsigned char *output, const unsigned char *block, unsigned int len

SECStatus
ChaCha20_InitContext(ChaCha20Context *ctx, const unsigned char *key,
unsigned int keyLen,
const unsigned char *nonce,
unsigned int nonceLen,
PRUint32 ctr)
unsigned int keyLen,
const unsigned char *nonce,
unsigned int nonceLen,
PRUint32 ctr)
{
if (!vector && PR_SUCCESS != freebl_RunLoaderOnce())
return SECFailure;
Expand Down

0 comments on commit 4a0ac18

Please sign in to comment.