Skip to content

Commit e750a12

Browse files
committed
char -> unsigned char fix
1 parent 32fe08c commit e750a12

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed

src/Cape.h

+12-8
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,27 @@ class Cape {
2727
public:
2828
unsigned char salt; // Salt used for encryption (exchange encrypted)
2929
/* Instantiate Cape passing a key, its length (max 65535) and salt: */
30-
Cape(char *key, uint16_t length, uint8_t s = 0) {
30+
Cape(unsigned char *key, uint16_t length, uint8_t s = 0) {
3131
salt = s;
3232
_key = key;
3333
_key_length = length;
3434
compute_reduced_key(key, length);
3535
};
3636

3737
/* Compute a 1 byte version of the encryption key */
38-
void compute_reduced_key(char *key, uint16_t length) {
38+
void compute_reduced_key(unsigned char *key, uint16_t length) {
3939
_reduced_key = 0;
4040
// Reduced key computation
4141
for(uint16_t i = 0; i < length; i++)
4242
_reduced_key ^= (key[i] << (i % 8));
4343
};
4444

4545
/* Decrypt data: (max length 65535 characters) */
46-
void decrypt(char *source, char *destination, uint16_t length) {
46+
void decrypt(
47+
unsigned char *source,
48+
unsigned char *destination,
49+
uint16_t length
50+
) {
4751
uint16_t index = length - 1;
4852
// 1 Compute salty reduced key or srk
4953
unsigned char srk = salt ^ _reduced_key;
@@ -57,8 +61,8 @@ class Cape {
5761
/* Stream cipher, private key, initialization vector based encryption
5862
algorithm (max length 65534 characters): */
5963
void encrypt(
60-
char *source,
61-
char *destination,
64+
unsigned char *source,
65+
unsigned char *destination,
6266
uint16_t length,
6367
uint8_t iv
6468
) {
@@ -73,7 +77,7 @@ class Cape {
7377

7478
/* Symmetric cipher using private key and salty reduced key:
7579
(max 65535 characters) */
76-
void hash(char *source, char *destination, uint16_t length) {
80+
void hash(unsigned char *source, unsigned char *destination, uint16_t length) {
7781
// 1 Compute salty reduced key or srk
7882
unsigned char srk = salt ^ _reduced_key;
7983
// 2 Hash data
@@ -84,14 +88,14 @@ class Cape {
8488
};
8589

8690
/* Set or Change encryption key (max 65534 characters): */
87-
void set_key(char *key, uint16_t length) {
91+
void set_key(unsigned char *key, uint16_t length) {
8892
_key = key;
8993
_key_length = length;
9094
compute_reduced_key(key, length);
9195
};
9296

9397
private:
94-
char * _key; // Keep private and safe
98+
unsigned char * _key; // Keep private and safe
9599
uint16_t _key_length; // Keep private and safe
96100
unsigned char _reduced_key; // Keep private and safe
97101
};

src/Cape_c.h

+29-19
Original file line numberDiff line numberDiff line change
@@ -26,45 +26,55 @@ not be applied in production. */
2626
#pragma once
2727

2828
typedef struct {
29-
char salt; // Salt used for encryption
30-
char *key; // Key
29+
unsigned char salt; // Salt used for encryption
30+
unsigned char *key; // Key
3131
uint16_t length; // Keep these private and safe
32-
char reduced_key; // Computed reduced key
32+
unsigned char reduced_key; // Computed reduced key
3333
} cape_t;
3434

35-
void cape_init(cape_t *cape, char *key, uint16_t length, uint8_t salt);
35+
void cape_init(
36+
cape_t *cape,
37+
unsigned char *key,
38+
uint16_t length,
39+
uint8_t salt
40+
);
3641

3742
void cape_hash(
3843
cape_t *cape,
39-
char *source,
40-
char *destination,
44+
unsigned char *source,
45+
unsigned char *destination,
4146
uint16_t length
4247
);
4348

4449
void cape_encrypt(
4550
cape_t *cape,
46-
char *source,
47-
char *destination,
51+
unsigned char *source,
52+
unsigned char *destination,
4853
uint16_t length,
4954
uint8_t iv
5055
);
5156

5257
void cape_decrypt(
5358
cape_t *cape,
54-
char *source,
55-
char *destination,
59+
unsigned char *source,
60+
unsigned char *destination,
5661
uint16_t length
5762
);
5863

5964
/* Compute a 1 byte version of the encryption key */
60-
char cape_compute_reduced_key(char *key, uint16_t length) {
61-
char reduced_key = 0;
65+
char cape_compute_reduced_key(unsigned char *key, uint16_t length) {
66+
unsigned char reduced_key = 0;
6267
for(uint16_t i = 0; i < length; i++) // Reduced key computation
6368
reduced_key ^= (key[i] << (i % 8));
6469
return reduced_key;
6570
};
6671

67-
void cape_init(cape_t *cape, char *key, uint16_t length, uint8_t salt = 0) {
72+
void cape_init(
73+
cape_t *cape,
74+
unsigned char *key,
75+
uint16_t length,
76+
uint8_t salt = 0
77+
) {
6878
cape->salt = salt;
6979
cape->key = key;
7080
cape->length = length;
@@ -75,8 +85,8 @@ void cape_init(cape_t *cape, char *key, uint16_t length, uint8_t salt = 0) {
7585
(max 65534 characters) */
7686
void cape_decrypt(
7787
cape_t *cape,
78-
char *source,
79-
char *destination,
88+
unsigned char *source,
89+
unsigned char *destination,
8090
uint16_t length
8191
) {
8292
uint16_t index = length - 1;
@@ -95,8 +105,8 @@ void cape_decrypt(
95105
algorithm (max 65534 characters): */
96106
void cape_encrypt(
97107
cape_t *cape,
98-
char *source,
99-
char *destination,
108+
unsigned char *source,
109+
unsigned char *destination,
100110
uint16_t length,
101111
uint8_t iv
102112
) {
@@ -115,8 +125,8 @@ void cape_encrypt(
115125
(max 65534 characters) */
116126
void cape_hash(
117127
cape_t *cape,
118-
char *source,
119-
char *destination,
128+
unsigned char *source,
129+
unsigned char *destination,
120130
uint16_t length
121131
) {
122132
uint8_t srk = cape->salt ^ cape->reduced_key;

0 commit comments

Comments
 (0)