summaryrefslogtreecommitdiffstats
path: root/src/plugins/ila
AgeCommit message (Expand)AuthorFilesLines
2021-10-14misc: fix coverity warning in ila pluginKlement Sekera1-1/+1
2020-12-14misc: move to new pool_foreach macrosDamjan Marion1-3/+3
2019-12-04fib: Decouple source from priority and behaviourNeale Ranns1-3/+10
2019-09-25fib: fix some typos in fib/mtrieLijian.Zhang1-1/+1
2019-05-03plugins: clean up plugin descriptionsDave Wallace1-1/+1
2018-08-27cmake: Fix plugins .h includesMohsin Kazmi1-1/+7
2018-08-25cmake: improve add_vpp_plugin macroDamjan Marion1-1/+1
2018-08-17CMake as an alternative to autotools (experimental)Damjan Marion1-0/+15
2018-07-19Remove unused argument to vlib_feature_nextDamjan Marion1-3/+3
2017-04-13Remove unsed parameter from fib_table_entry_special_add() (only used in FIB t...Neale Ranns1-2/+1
2017-03-22vlib: add description field in plugin registrationDamjan Marion1-0/+1
2017-02-22VPP-635: CLI Memory leak with invalid parameterBilly McFall1-7/+18
2017-02-03Plugin infrastructure improvementsDamjan Marion1-8/+6
2016-12-28Reorganize source tree to use single autotools instanceDamjan Marion2-0/+1186
} /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * Copyright (c) 2020 Doc.ai and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <wireguard/wireguard_key.h>
#include <openssl/evp.h>

bool
curve25519_gen_shared (u8 shared_key[CURVE25519_KEY_SIZE],
		       const u8 secret_key[CURVE25519_KEY_SIZE],
		       const u8 basepoint[CURVE25519_KEY_SIZE])
{

  bool ret;
  EVP_PKEY_CTX *ctx;
  size_t key_len;

  EVP_PKEY *peerkey = NULL;
  EVP_PKEY *pkey =
    EVP_PKEY_new_raw_private_key (EVP_PKEY_X25519, NULL, secret_key,
				  CURVE25519_KEY_SIZE);

  ret = true;

  ctx = EVP_PKEY_CTX_new (pkey, NULL);
  if (EVP_PKEY_derive_init (ctx) <= 0)
    {
      ret = false;
      goto out;
    }

  peerkey =
    EVP_PKEY_new_raw_public_key (EVP_PKEY_X25519, NULL, basepoint,
				 CURVE25519_KEY_SIZE);
  if (EVP_PKEY_derive_set_peer (ctx, peerkey) <= 0)
    {
      ret = false;
      goto out;
    }

  key_len = CURVE25519_KEY_SIZE;
  if (EVP_PKEY_derive (ctx, shared_key, &key_len) <= 0)
    {
      ret = false;
    }

out:
  EVP_PKEY_CTX_free (ctx);
  EVP_PKEY_free (pkey);
  EVP_PKEY_free (peerkey);
  return ret;
}

bool
curve25519_gen_public (u8 public_key[CURVE25519_KEY_SIZE],
		       const u8 secret_key[CURVE25519_KEY_SIZE])
{
  size_t pub_len;
  EVP_PKEY *pkey =
    EVP_PKEY_new_raw_private_key (EVP_PKEY_X25519, NULL, secret_key,
				  CURVE25519_KEY_SIZE);
  pub_len = CURVE25519_KEY_SIZE;
  if (!EVP_PKEY_get_raw_public_key (pkey, public_key, &pub_len))
    {
      EVP_PKEY_free (pkey);
      return false;
    }
  EVP_PKEY_free (pkey);
  return true;
}

bool
curve25519_gen_secret (u8 secret_key[CURVE25519_KEY_SIZE])
{
  size_t secret_len;
  EVP_PKEY *pkey = NULL;
  EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id (EVP_PKEY_X25519, NULL);
  EVP_PKEY_keygen_init (pctx);
  EVP_PKEY_keygen (pctx, &pkey);
  EVP_PKEY_CTX_free (pctx);

  secret_len = CURVE25519_KEY_SIZE;
  if (!EVP_PKEY_get_raw_private_key (pkey, secret_key, &secret_len))
    {
      EVP_PKEY_free (pkey);
      return false;
    }
  EVP_PKEY_free (pkey);
  return true;
}

bool
key_to_base64 (const u8 * src, size_t src_len, u8 * out)
{
  if (!EVP_EncodeBlock (out, src, src_len))
    return false;
  return true;
}

bool
key_from_base64 (const u8 * src, size_t src_len, u8 * out)
{
  if (EVP_DecodeBlock (out, src, src_len - 1) <= 0)
    return false;
  return true;
}

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */