| Andreas Huber | cf0db31 | 2012-04-03 14:15:05 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2012 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 | #include <utils/Errors.h> | 
|  | 18 |  | 
|  | 19 | #ifndef CRYPTO_API_H_ | 
|  | 20 |  | 
|  | 21 | #define CRYPTO_API_H_ | 
|  | 22 |  | 
|  | 23 | namespace android { | 
|  | 24 |  | 
| Andreas Huber | 383190e | 2012-04-19 12:55:36 -0700 | [diff] [blame] | 25 | struct AString; | 
| Andreas Huber | cf0db31 | 2012-04-03 14:15:05 -0700 | [diff] [blame] | 26 | struct CryptoPlugin; | 
|  | 27 |  | 
|  | 28 | struct CryptoFactory { | 
|  | 29 | CryptoFactory() {} | 
|  | 30 | virtual ~CryptoFactory() {} | 
|  | 31 |  | 
|  | 32 | virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]) const = 0; | 
|  | 33 |  | 
|  | 34 | virtual status_t createPlugin( | 
|  | 35 | const uint8_t uuid[16], const void *data, size_t size, | 
|  | 36 | CryptoPlugin **plugin) = 0; | 
|  | 37 |  | 
|  | 38 | private: | 
|  | 39 | CryptoFactory(const CryptoFactory &); | 
|  | 40 | CryptoFactory &operator=(const CryptoFactory &); | 
|  | 41 | }; | 
|  | 42 |  | 
|  | 43 | struct CryptoPlugin { | 
|  | 44 | enum Mode { | 
|  | 45 | kMode_Unencrypted = 0, | 
|  | 46 | kMode_AES_CTR     = 1, | 
|  | 47 |  | 
|  | 48 | // Neither key nor iv are being used in this mode. | 
|  | 49 | // Each subsample is encrypted w/ an iv of all zeroes. | 
|  | 50 | kMode_AES_WV      = 2,  // FIX constant | 
|  | 51 | }; | 
|  | 52 |  | 
|  | 53 | struct SubSample { | 
| Jeff Tinker | 03a0571 | 2014-07-01 14:54:45 -0700 | [diff] [blame] | 54 | uint32_t mNumBytesOfClearData; | 
|  | 55 | uint32_t mNumBytesOfEncryptedData; | 
| Andreas Huber | cf0db31 | 2012-04-03 14:15:05 -0700 | [diff] [blame] | 56 | }; | 
|  | 57 |  | 
|  | 58 | CryptoPlugin() {} | 
|  | 59 | virtual ~CryptoPlugin() {} | 
|  | 60 |  | 
|  | 61 | // If this method returns false, a non-secure decoder will be used to | 
|  | 62 | // decode the data after decryption. The decrypt API below will have | 
|  | 63 | // to support insecure decryption of the data (secure = false) for | 
|  | 64 | // media data of the given mime type. | 
|  | 65 | virtual bool requiresSecureDecoderComponent(const char *mime) const = 0; | 
|  | 66 |  | 
| Andreas Huber | 383190e | 2012-04-19 12:55:36 -0700 | [diff] [blame] | 67 | // If the error returned falls into the range | 
|  | 68 | // ERROR_DRM_VENDOR_MIN..ERROR_DRM_VENDOR_MAX, errorDetailMsg should be | 
|  | 69 | // filled in with an appropriate string. | 
|  | 70 | // At the java level these special errors will then trigger a | 
|  | 71 | // MediaCodec.CryptoException that gives clients access to both | 
|  | 72 | // the error code and the errorDetailMsg. | 
| Edwin Wong | e0daeb3 | 2012-07-10 19:57:26 -0700 | [diff] [blame] | 73 | // Returns a non-negative result to indicate the number of bytes written | 
|  | 74 | // to the dstPtr, or a negative result to indicate an error. | 
|  | 75 | virtual ssize_t decrypt( | 
| Andreas Huber | cf0db31 | 2012-04-03 14:15:05 -0700 | [diff] [blame] | 76 | bool secure, | 
|  | 77 | const uint8_t key[16], | 
|  | 78 | const uint8_t iv[16], | 
|  | 79 | Mode mode, | 
|  | 80 | const void *srcPtr, | 
|  | 81 | const SubSample *subSamples, size_t numSubSamples, | 
| Andreas Huber | 383190e | 2012-04-19 12:55:36 -0700 | [diff] [blame] | 82 | void *dstPtr, | 
|  | 83 | AString *errorDetailMsg) = 0; | 
| Andreas Huber | cf0db31 | 2012-04-03 14:15:05 -0700 | [diff] [blame] | 84 |  | 
|  | 85 | private: | 
|  | 86 | CryptoPlugin(const CryptoPlugin &); | 
|  | 87 | CryptoPlugin &operator=(const CryptoPlugin &); | 
|  | 88 | }; | 
|  | 89 |  | 
|  | 90 | }  // namespace android | 
|  | 91 |  | 
|  | 92 | extern "C" { | 
|  | 93 | extern android::CryptoFactory *createCryptoFactory(); | 
|  | 94 | } | 
|  | 95 |  | 
|  | 96 | #endif  // CRYPTO_API_H_ |