xref: /third_party/openssl/crypto/des/ecb_enc.c (revision e1051a39)
1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci *
4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci */
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci/*
11e1051a39Sopenharmony_ci * DES low level APIs are deprecated for public use, but still ok for internal
12e1051a39Sopenharmony_ci * use.
13e1051a39Sopenharmony_ci */
14e1051a39Sopenharmony_ci#include "internal/deprecated.h"
15e1051a39Sopenharmony_ci
16e1051a39Sopenharmony_ci#include "des_local.h"
17e1051a39Sopenharmony_ci#include <openssl/opensslv.h>
18e1051a39Sopenharmony_ci#include <openssl/bio.h>
19e1051a39Sopenharmony_ci
20e1051a39Sopenharmony_ci
21e1051a39Sopenharmony_ciconst char *DES_options(void)
22e1051a39Sopenharmony_ci{
23e1051a39Sopenharmony_ci    static int init = 1;
24e1051a39Sopenharmony_ci    static char buf[12];
25e1051a39Sopenharmony_ci
26e1051a39Sopenharmony_ci    if (init) {
27e1051a39Sopenharmony_ci        if (sizeof(DES_LONG) != sizeof(long))
28e1051a39Sopenharmony_ci            OPENSSL_strlcpy(buf, "des(int)", sizeof(buf));
29e1051a39Sopenharmony_ci        else
30e1051a39Sopenharmony_ci            OPENSSL_strlcpy(buf, "des(long)", sizeof(buf));
31e1051a39Sopenharmony_ci        init = 0;
32e1051a39Sopenharmony_ci    }
33e1051a39Sopenharmony_ci    return buf;
34e1051a39Sopenharmony_ci}
35e1051a39Sopenharmony_ci
36e1051a39Sopenharmony_civoid DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
37e1051a39Sopenharmony_ci                     DES_key_schedule *ks, int enc)
38e1051a39Sopenharmony_ci{
39e1051a39Sopenharmony_ci    register DES_LONG l;
40e1051a39Sopenharmony_ci    DES_LONG ll[2];
41e1051a39Sopenharmony_ci    const unsigned char *in = &(*input)[0];
42e1051a39Sopenharmony_ci    unsigned char *out = &(*output)[0];
43e1051a39Sopenharmony_ci
44e1051a39Sopenharmony_ci    c2l(in, l);
45e1051a39Sopenharmony_ci    ll[0] = l;
46e1051a39Sopenharmony_ci    c2l(in, l);
47e1051a39Sopenharmony_ci    ll[1] = l;
48e1051a39Sopenharmony_ci    DES_encrypt1(ll, ks, enc);
49e1051a39Sopenharmony_ci    l = ll[0];
50e1051a39Sopenharmony_ci    l2c(l, out);
51e1051a39Sopenharmony_ci    l = ll[1];
52e1051a39Sopenharmony_ci    l2c(l, out);
53e1051a39Sopenharmony_ci    l = ll[0] = ll[1] = 0;
54e1051a39Sopenharmony_ci}
55