Skip to content

Commit

Permalink
feat(decrypto): add decrypto interface
Browse files Browse the repository at this point in the history
impl avAESDecrypt and OpenSSAESDecrypt

Signed-off-by: pingkai <pingkai010@gmail.com>
  • Loading branch information
pingkai committed Feb 24, 2020
1 parent a68fb45 commit 970750f
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 1 deletion.
2 changes: 1 addition & 1 deletion framework/demuxer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ set(SOURCE_FILES demuxer_service.cpp
sample_decrypt/SampleDecryptDemuxer.h
sample_decrypt/sampleDecryptDec.c
sample_decrypt/ISampleDecrypt2c.cpp
sample_decrypt/ISampleDecrypt2c.h)
sample_decrypt/ISampleDecrypt2c.h decrypto/IAESDecrypt.h decrypto/avAESDecrypt.cpp decrypto/avAESDecrypt.h decrypto/OpenSSAESDecrypt.cpp decrypto/OpenSSAESDecrypt.h)

include_directories(
#${CICADA_FRAMEWORK_DIR}/inc
Expand Down
28 changes: 28 additions & 0 deletions framework/demuxer/decrypto/IAESDecrypt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Created by moqi on 2020/2/20.
//

#ifndef CICADAMEDIA_IAESDECRYPT_H
#define CICADAMEDIA_IAESDECRYPT_H

#include <cstdint>


namespace Cicada {
class IAESDecrypt {
public:
const static int BLOCK_SIZE = 16;

IAESDecrypt() = default;

virtual ~IAESDecrypt() = default;

virtual int setKey(const uint8_t *key, int key_bits) = 0;

virtual void decrypt(uint8_t *dst, const uint8_t *src, int count, uint8_t *iv) = 0;

};
}


#endif //CICADAMEDIA_IAESDECRYPT_H
22 changes: 22 additions & 0 deletions framework/demuxer/decrypto/OpenSSAESDecrypt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Created by moqi on 2020/2/20.
//

#include <openssl/aes.h>
#include "OpenSSAESDecrypt.h"

using namespace Cicada;

OpenSSAESDecrypt::OpenSSAESDecrypt() = default;

OpenSSAESDecrypt::~OpenSSAESDecrypt() = default;

int OpenSSAESDecrypt::setKey(const uint8_t *key, int key_bits)
{
return AES_set_decrypt_key(key, 8 * AES_BLOCK_SIZE/*128*/, &mAesKey);
}

void OpenSSAESDecrypt::decrypt(uint8_t *dst, const uint8_t *src, int count, uint8_t *iv)
{
AES_cbc_encrypt(src, dst, count * AES_BLOCK_SIZE, &mAesKey, iv, AES_DECRYPT);
}
28 changes: 28 additions & 0 deletions framework/demuxer/decrypto/OpenSSAESDecrypt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Created by moqi on 2020/2/20.
//

#ifndef CICADAMEDIA_OPENSSAESDECRYPT_H
#define CICADAMEDIA_OPENSSAESDECRYPT_H

#include "IAESDecrypt.h"

namespace Cicada {
class OpenSSAESDecrypt : public IAESDecrypt {
public:
OpenSSAESDecrypt();

~OpenSSAESDecrypt() override;

int setKey(const uint8_t *key, int key_bits) override;

void decrypt(uint8_t *dst, const uint8_t *src, int count, uint8_t *iv) override;

private:
AES_KEY mAesKey{};

};
}


#endif //CICADAMEDIA_OPENSSAESDECRYPT_H
31 changes: 31 additions & 0 deletions framework/demuxer/decrypto/avAESDecrypt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Created by moqi on 2020/2/20.
//
extern "C" {
#include <libavutil/mem.h>
#include <libavutil/aes.h>
}

#include "avAESDecrypt.h"

using namespace Cicada;

avAESDecrypt::avAESDecrypt()
{
mAes = av_aes_alloc();
}

avAESDecrypt::~avAESDecrypt()
{
av_free(mAes);
}

void avAESDecrypt::decrypt(uint8_t *dst, const uint8_t *src, int count, uint8_t *iv)
{
av_aes_crypt(mAes, dst, src, count, iv, 1);
}

int avAESDecrypt::setKey(const uint8_t *key, int key_bits)
{
return av_aes_init(mAes, key, key_bits, 1);
}
28 changes: 28 additions & 0 deletions framework/demuxer/decrypto/avAESDecrypt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Created by moqi on 2020/2/20.
//

#ifndef CICADAMEDIA_AVAESDECRYPT_H
#define CICADAMEDIA_AVAESDECRYPT_H

#include "IAESDecrypt.h"

namespace Cicada {
class avAESDecrypt : public IAESDecrypt {
public:
avAESDecrypt();

~avAESDecrypt() override;

int setKey(const uint8_t *key, int key_bits) override;

void decrypt(uint8_t *dst, const uint8_t *src, int count, uint8_t *iv) override;

private:
struct AVAES *mAes{nullptr};

};
}


#endif //CICADAMEDIA_AVAESDECRYPT_H

0 comments on commit 970750f

Please sign in to comment.