Home | History | Annotate | Download | only in keymaster
      1 /*
      2  * Copyright 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef SYSTEM_KEYMASTER_KEY_EXCHANGE_H_
     18 #define SYSTEM_KEYMASTER_KEY_EXCHANGE_H_
     19 
     20 #include <openssl/ec.h>
     21 
     22 #include <keymaster/serializable.h>
     23 
     24 namespace keymaster {
     25 
     26 /**
     27  * KeyExchange is an abstract class that provides an interface to a
     28  * key-exchange primitive.
     29  */
     30 class KeyExchange {
     31   public:
     32     virtual ~KeyExchange() {}
     33 
     34     /**
     35      * CalculateSharedKey computes the shared key between the local private key
     36      * (which is implicitly known by a KeyExchange object) and a public value
     37      * from the peer.
     38      */
     39     virtual bool CalculateSharedKey(const Buffer& peer_public_value, Buffer* shared_key) const = 0;
     40     virtual bool CalculateSharedKey(const uint8_t* peer_public_value, size_t peer_public_value_len,
     41                                     Buffer* shared_key) const = 0;
     42 
     43     /**
     44      * public_value writes to |public_value| the local public key which can be
     45      * sent to a peer in order to complete a key exchange.
     46      */
     47     virtual bool public_value(Buffer* public_value) const = 0;
     48 };
     49 
     50 }  // namespace keymaster
     51 
     52 #endif  // SYSTEM_KEYMASTER_KEY_EXCHANGE_H_
     53