| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #include <assert.h> |
| 16 | #include <string.h> |
| 17 |
| 18 | #include <openssl/cipher.h> |
| 19 | #include <openssl/nid.h> |
| 20 | #include <openssl/rc4.h> |
| 21 |
| 22 | #include "../fipsmodule/cipher/internal.h" |
| 23 |
| 24 |
| 25 | static int rc4_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key, |
| 26 | const uint8_t *iv, int enc) { |
| 27 | RC4_KEY *rc4key = (RC4_KEY *)ctx->cipher_data; |
| 28 |
| 29 | RC4_set_key(rc4key, EVP_CIPHER_CTX_key_length(ctx), key); |
| 30 | return 1; |
| 31 | } |
| 32 |
| 33 | static int rc4_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in, |
| 34 | size_t in_len) { |
| 35 | RC4_KEY *rc4key = (RC4_KEY *)ctx->cipher_data; |
| 36 |
| 37 | RC4(rc4key, in_len, in, out); |
| 38 | return 1; |
| 39 | } |
| 40 |
| 41 | static const EVP_CIPHER rc4 = { |
| 42 | /*nid=*/NID_rc4, |
| 43 | /*block_size=*/1, |
| 44 | /*key_len=*/16, |
| 45 | /*iv_len=*/0, |
| 46 | /*ctx_size=*/sizeof(RC4_KEY), |
| 47 | /*flags=*/EVP_CIPH_VARIABLE_LENGTH, |
| 48 | /*init=*/rc4_init_key, |
| 49 | /*cipher=*/rc4_cipher, |
| 50 | /*cleanup=*/nullptr, |
| 51 | /*ctrl=*/nullptr, |
| 52 | }; |
| 53 |
| 54 | const EVP_CIPHER *EVP_rc4(void) { return &rc4; } |
| 55 |