summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot2018-04-05 02:26:25 -0500
committerandroid-build-team Robot2018-04-05 02:26:25 -0500
commit4872521089b0498fb543c0ce09a07cccc99b33a6 (patch)
treeebd7df338c4b176995ea3224717ec77ebaa9ca6a
parent88839af1d666a4bb71a2a0975c1d071b53663dfd (diff)
parent44f8b71874191d34ea07a7247364432f368ee2fb (diff)
downloadplatform-hardware-interfaces-4872521089b0498fb543c0ce09a07cccc99b33a6.tar.gz
platform-hardware-interfaces-4872521089b0498fb543c0ce09a07cccc99b33a6.tar.xz
platform-hardware-interfaces-4872521089b0498fb543c0ce09a07cccc99b33a6.zip
Snap for 4701683 from 44f8b71874191d34ea07a7247364432f368ee2fb to pi-release
Change-Id: I8922f95718bae50bdb665db2db313668799b1d31
-rw-r--r--camera/device/3.4/default/ExternalCameraDeviceSession.cpp118
-rw-r--r--camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDeviceSession.h8
-rw-r--r--keymaster/4.0/vts/functional/KeymasterHidlTest.cpp3
-rw-r--r--keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp50
4 files changed, 126 insertions, 53 deletions
diff --git a/camera/device/3.4/default/ExternalCameraDeviceSession.cpp b/camera/device/3.4/default/ExternalCameraDeviceSession.cpp
index 7015bcb4..bb11d7cd 100644
--- a/camera/device/3.4/default/ExternalCameraDeviceSession.cpp
+++ b/camera/device/3.4/default/ExternalCameraDeviceSession.cpp
@@ -51,10 +51,12 @@ constexpr int MAX_RETRY = 15; // Allow retry some ioctl failures a few times to
51 // webcam showing temporarily ioctl failures. 51 // webcam showing temporarily ioctl failures.
52constexpr int IOCTL_RETRY_SLEEP_US = 33000; // 33ms * MAX_RETRY = 5 seconds 52constexpr int IOCTL_RETRY_SLEEP_US = 33000; // 33ms * MAX_RETRY = 5 seconds
53 53
54// Constants for tryLock during dumpstate
55static constexpr int kDumpLockRetries = 50;
56static constexpr int kDumpLockSleep = 60000;
57
54bool tryLock(Mutex& mutex) 58bool tryLock(Mutex& mutex)
55{ 59{
56 static const int kDumpLockRetries = 50;
57 static const int kDumpLockSleep = 60000;
58 bool locked = false; 60 bool locked = false;
59 for (int i = 0; i < kDumpLockRetries; ++i) { 61 for (int i = 0; i < kDumpLockRetries; ++i) {
60 if (mutex.tryLock() == NO_ERROR) { 62 if (mutex.tryLock() == NO_ERROR) {
@@ -66,6 +68,19 @@ bool tryLock(Mutex& mutex)
66 return locked; 68 return locked;
67} 69}
68 70
71bool tryLock(std::mutex& mutex)
72{
73 bool locked = false;
74 for (int i = 0; i < kDumpLockRetries; ++i) {
75 if (mutex.try_lock()) {
76 locked = true;
77 break;
78 }
79 usleep(kDumpLockSleep);
80 }
81 return locked;
82}
83
69} // Anonymous namespace 84} // Anonymous namespace
70 85
71// Static instances 86// Static instances
@@ -163,7 +178,6 @@ void ExternalCameraDeviceSession::dumpState(const native_handle_t* handle) {
163 bool streaming = false; 178 bool streaming = false;
164 size_t v4L2BufferCount = 0; 179 size_t v4L2BufferCount = 0;
165 SupportedV4L2Format streamingFmt; 180 SupportedV4L2Format streamingFmt;
166 std::unordered_set<uint32_t> inflightFrames;
167 { 181 {
168 bool sessionLocked = tryLock(mLock); 182 bool sessionLocked = tryLock(mLock);
169 if (!sessionLocked) { 183 if (!sessionLocked) {
@@ -172,12 +186,25 @@ void ExternalCameraDeviceSession::dumpState(const native_handle_t* handle) {
172 streaming = mV4l2Streaming; 186 streaming = mV4l2Streaming;
173 streamingFmt = mV4l2StreamingFmt; 187 streamingFmt = mV4l2StreamingFmt;
174 v4L2BufferCount = mV4L2BufferCount; 188 v4L2BufferCount = mV4L2BufferCount;
175 inflightFrames = mInflightFrames; 189
176 if (sessionLocked) { 190 if (sessionLocked) {
177 mLock.unlock(); 191 mLock.unlock();
178 } 192 }
179 } 193 }
180 194
195 std::unordered_set<uint32_t> inflightFrames;
196 {
197 bool iffLocked = tryLock(mInflightFramesLock);
198 if (!iffLocked) {
199 dprintf(fd,
200 "!! ExternalCameraDeviceSession mInflightFramesLock may be deadlocked !!\n");
201 }
202 inflightFrames = mInflightFrames;
203 if (iffLocked) {
204 mInflightFramesLock.unlock();
205 }
206 }
207
181 dprintf(fd, "External camera %s V4L2 FD %d, cropping type %s, %s\n", 208 dprintf(fd, "External camera %s V4L2 FD %d, cropping type %s, %s\n",
182 mCameraId.c_str(), mV4l2Fd.get(), 209 mCameraId.c_str(), mV4l2Fd.get(),
183 (mCroppingType == VERTICAL) ? "vertical" : "horizontal", 210 (mCroppingType == VERTICAL) ? "vertical" : "horizontal",
@@ -457,6 +484,7 @@ void ExternalCameraDeviceSession::cleanupInflightFences(
457} 484}
458 485
459int ExternalCameraDeviceSession::waitForV4L2BufferReturnLocked(std::unique_lock<std::mutex>& lk) { 486int ExternalCameraDeviceSession::waitForV4L2BufferReturnLocked(std::unique_lock<std::mutex>& lk) {
487 ATRACE_CALL();
460 std::chrono::seconds timeout = std::chrono::seconds(kBufferWaitTimeoutSec); 488 std::chrono::seconds timeout = std::chrono::seconds(kBufferWaitTimeoutSec);
461 mLock.unlock(); 489 mLock.unlock();
462 auto st = mV4L2BufferReturned.wait_for(lk, timeout); 490 auto st = mV4L2BufferReturned.wait_for(lk, timeout);
@@ -612,7 +640,10 @@ Status ExternalCameraDeviceSession::processOneCaptureRequest(const CaptureReques
612 halBuf.acquireFence = allFences[i]; 640 halBuf.acquireFence = allFences[i];
613 halBuf.fenceTimeout = false; 641 halBuf.fenceTimeout = false;
614 } 642 }
615 mInflightFrames.insert(halReq->frameNumber); 643 {
644 std::lock_guard<std::mutex> lk(mInflightFramesLock);
645 mInflightFrames.insert(halReq->frameNumber);
646 }
616 // Send request to OutputThread for the rest of processing 647 // Send request to OutputThread for the rest of processing
617 mOutputThread->submitRequest(halReq); 648 mOutputThread->submitRequest(halReq);
618 mFirstRequest = false; 649 mFirstRequest = false;
@@ -670,7 +701,7 @@ Status ExternalCameraDeviceSession::processCaptureRequestError(
670 701
671 // update inflight records 702 // update inflight records
672 { 703 {
673 Mutex::Autolock _l(mLock); 704 std::lock_guard<std::mutex> lk(mInflightFramesLock);
674 mInflightFrames.erase(req->frameNumber); 705 mInflightFrames.erase(req->frameNumber);
675 } 706 }
676 707
@@ -724,7 +755,7 @@ Status ExternalCameraDeviceSession::processCaptureResult(std::shared_ptr<HalRequ
724 755
725 // update inflight records 756 // update inflight records
726 { 757 {
727 Mutex::Autolock _l(mLock); 758 std::lock_guard<std::mutex> lk(mInflightFramesLock);
728 mInflightFrames.erase(req->frameNumber); 759 mInflightFrames.erase(req->frameNumber);
729 } 760 }
730 761
@@ -2149,6 +2180,13 @@ int ExternalCameraDeviceSession::configureV4l2StreamLocked(
2149 } 2180 }
2150 uint32_t bufferSize = fmt.fmt.pix.sizeimage; 2181 uint32_t bufferSize = fmt.fmt.pix.sizeimage;
2151 ALOGI("%s: V4L2 buffer size is %d", __FUNCTION__, bufferSize); 2182 ALOGI("%s: V4L2 buffer size is %d", __FUNCTION__, bufferSize);
2183 uint32_t expectedMaxBufferSize = kMaxBytesPerPixel * fmt.fmt.pix.width * fmt.fmt.pix.height;
2184 if ((bufferSize == 0) || (bufferSize > expectedMaxBufferSize)) {
2185 ALOGE("%s: V4L2 buffer size: %u looks invalid. Expected maximum size: %u", __FUNCTION__,
2186 bufferSize, expectedMaxBufferSize);
2187 return -EINVAL;
2188 }
2189 mMaxV4L2BufferSize = bufferSize;
2152 2190
2153 const double kDefaultFps = 30.0; 2191 const double kDefaultFps = 30.0;
2154 double fps = 1000.0; 2192 double fps = 1000.0;
@@ -2278,6 +2316,7 @@ sp<V4L2Frame> ExternalCameraDeviceSession::dequeueV4l2FrameLocked(/*out*/nsecs_t
2278 } 2316 }
2279 } 2317 }
2280 2318
2319 ATRACE_BEGIN("VIDIOC_DQBUF");
2281 v4l2_buffer buffer{}; 2320 v4l2_buffer buffer{};
2282 buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 2321 buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2283 buffer.memory = V4L2_MEMORY_MMAP; 2322 buffer.memory = V4L2_MEMORY_MMAP;
@@ -2285,6 +2324,7 @@ sp<V4L2Frame> ExternalCameraDeviceSession::dequeueV4l2FrameLocked(/*out*/nsecs_t
2285 ALOGE("%s: DQBUF fails: %s", __FUNCTION__, strerror(errno)); 2324 ALOGE("%s: DQBUF fails: %s", __FUNCTION__, strerror(errno));
2286 return ret; 2325 return ret;
2287 } 2326 }
2327 ATRACE_END();
2288 2328
2289 if (buffer.index >= mV4L2BufferCount) { 2329 if (buffer.index >= mV4L2BufferCount) {
2290 ALOGE("%s: Invalid buffer id: %d", __FUNCTION__, buffer.index); 2330 ALOGE("%s: Invalid buffer id: %d", __FUNCTION__, buffer.index);
@@ -2296,6 +2336,12 @@ sp<V4L2Frame> ExternalCameraDeviceSession::dequeueV4l2FrameLocked(/*out*/nsecs_t
2296 // TODO: try to dequeue again 2336 // TODO: try to dequeue again
2297 } 2337 }
2298 2338
2339 if (buffer.bytesused > mMaxV4L2BufferSize) {
2340 ALOGE("%s: v4l2 buffer bytes used: %u maximum %u", __FUNCTION__, buffer.bytesused,
2341 mMaxV4L2BufferSize);
2342 return ret;
2343 }
2344
2299 if (buffer.flags & V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC) { 2345 if (buffer.flags & V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC) {
2300 // Ideally we should also check for V4L2_BUF_FLAG_TSTAMP_SRC_SOE, but 2346 // Ideally we should also check for V4L2_BUF_FLAG_TSTAMP_SRC_SOE, but
2301 // even V4L2_BUF_FLAG_TSTAMP_SRC_EOF is better than capture a timestamp now 2347 // even V4L2_BUF_FLAG_TSTAMP_SRC_EOF is better than capture a timestamp now
@@ -2316,21 +2362,18 @@ sp<V4L2Frame> ExternalCameraDeviceSession::dequeueV4l2FrameLocked(/*out*/nsecs_t
2316 2362
2317void ExternalCameraDeviceSession::enqueueV4l2Frame(const sp<V4L2Frame>& frame) { 2363void ExternalCameraDeviceSession::enqueueV4l2Frame(const sp<V4L2Frame>& frame) {
2318 ATRACE_CALL(); 2364 ATRACE_CALL();
2319 { 2365 frame->unmap();
2320 // Release mLock before acquiring mV4l2BufferLock to avoid potential 2366 ATRACE_BEGIN("VIDIOC_QBUF");
2321 // deadlock 2367 v4l2_buffer buffer{};
2322 Mutex::Autolock _l(mLock); 2368 buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2323 frame->unmap(); 2369 buffer.memory = V4L2_MEMORY_MMAP;
2324 v4l2_buffer buffer{}; 2370 buffer.index = frame->mBufferIndex;
2325 buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 2371 if (TEMP_FAILURE_RETRY(ioctl(mV4l2Fd.get(), VIDIOC_QBUF, &buffer)) < 0) {
2326 buffer.memory = V4L2_MEMORY_MMAP; 2372 ALOGE("%s: QBUF index %d fails: %s", __FUNCTION__,
2327 buffer.index = frame->mBufferIndex; 2373 frame->mBufferIndex, strerror(errno));
2328 if (TEMP_FAILURE_RETRY(ioctl(mV4l2Fd.get(), VIDIOC_QBUF, &buffer)) < 0) { 2374 return;
2329 ALOGE("%s: QBUF index %d fails: %s", __FUNCTION__,
2330 frame->mBufferIndex, strerror(errno));
2331 return;
2332 }
2333 } 2375 }
2376 ATRACE_END();
2334 2377
2335 { 2378 {
2336 std::lock_guard<std::mutex> lk(mV4l2BufferLock); 2379 std::lock_guard<std::mutex> lk(mV4l2BufferLock);
@@ -2383,13 +2426,17 @@ Status ExternalCameraDeviceSession::configureStreams(
2383 return status; 2426 return status;
2384 } 2427 }
2385 2428
2386 Mutex::Autolock _l(mLock); 2429
2387 if (!mInflightFrames.empty()) { 2430 {
2388 ALOGE("%s: trying to configureStreams while there are still %zu inflight frames!", 2431 std::lock_guard<std::mutex> lk(mInflightFramesLock);
2389 __FUNCTION__, mInflightFrames.size()); 2432 if (!mInflightFrames.empty()) {
2390 return Status::INTERNAL_ERROR; 2433 ALOGE("%s: trying to configureStreams while there are still %zu inflight frames!",
2434 __FUNCTION__, mInflightFrames.size());
2435 return Status::INTERNAL_ERROR;
2436 }
2391 } 2437 }
2392 2438
2439 Mutex::Autolock _l(mLock);
2393 // Add new streams 2440 // Add new streams
2394 for (const auto& stream : config.streams) { 2441 for (const auto& stream : config.streams) {
2395 if (mStreamMap.count(stream.id) == 0) { 2442 if (mStreamMap.count(stream.id) == 0) {
@@ -2689,14 +2736,17 @@ status_t ExternalCameraDeviceSession::fillCaptureResult(
2689 const uint8_t ae_lock = ANDROID_CONTROL_AE_LOCK_OFF; 2736 const uint8_t ae_lock = ANDROID_CONTROL_AE_LOCK_OFF;
2690 UPDATE(md, ANDROID_CONTROL_AE_LOCK, &ae_lock, 1); 2737 UPDATE(md, ANDROID_CONTROL_AE_LOCK, &ae_lock, 1);
2691 2738
2692 bool afTrigger = mAfTrigger; 2739 bool afTrigger = false;
2693 if (md.exists(ANDROID_CONTROL_AF_TRIGGER)) { 2740 {
2694 Mutex::Autolock _l(mLock); 2741 std::lock_guard<std::mutex> lk(mAfTriggerLock);
2695 camera_metadata_entry entry = md.find(ANDROID_CONTROL_AF_TRIGGER); 2742 afTrigger = mAfTrigger;
2696 if (entry.data.u8[0] == ANDROID_CONTROL_AF_TRIGGER_START) { 2743 if (md.exists(ANDROID_CONTROL_AF_TRIGGER)) {
2697 mAfTrigger = afTrigger = true; 2744 camera_metadata_entry entry = md.find(ANDROID_CONTROL_AF_TRIGGER);
2698 } else if (entry.data.u8[0] == ANDROID_CONTROL_AF_TRIGGER_CANCEL) { 2745 if (entry.data.u8[0] == ANDROID_CONTROL_AF_TRIGGER_START) {
2699 mAfTrigger = afTrigger = false; 2746 mAfTrigger = afTrigger = true;
2747 } else if (entry.data.u8[0] == ANDROID_CONTROL_AF_TRIGGER_CANCEL) {
2748 mAfTrigger = afTrigger = false;
2749 }
2700 } 2750 }
2701 } 2751 }
2702 2752
diff --git a/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDeviceSession.h b/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDeviceSession.h
index 53150970..14e5c9a4 100644
--- a/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDeviceSession.h
+++ b/camera/device/3.4/default/include/ext_device_v3_4_impl/ExternalCameraDeviceSession.h
@@ -108,6 +108,7 @@ struct ExternalCameraDeviceSession : public virtual RefBase {
108 108
109 static const int kMaxProcessedStream = 2; 109 static const int kMaxProcessedStream = 2;
110 static const int kMaxStallStream = 1; 110 static const int kMaxStallStream = 1;
111 static const uint32_t kMaxBytesPerPixel = 2;
111 112
112protected: 113protected:
113 114
@@ -299,6 +300,9 @@ protected:
299 const std::vector<SupportedV4L2Format> mSupportedFormats; 300 const std::vector<SupportedV4L2Format> mSupportedFormats;
300 const CroppingType mCroppingType; 301 const CroppingType mCroppingType;
301 const std::string& mCameraId; 302 const std::string& mCameraId;
303
304 // Not protected by mLock, this is almost a const.
305 // Setup in constructor, reset in close() after OutputThread is joined
302 unique_fd mV4l2Fd; 306 unique_fd mV4l2Fd;
303 307
304 // device is closed either 308 // device is closed either
@@ -319,12 +323,15 @@ protected:
319 std::mutex mV4l2BufferLock; // protect the buffer count and condition below 323 std::mutex mV4l2BufferLock; // protect the buffer count and condition below
320 std::condition_variable mV4L2BufferReturned; 324 std::condition_variable mV4L2BufferReturned;
321 size_t mNumDequeuedV4l2Buffers = 0; 325 size_t mNumDequeuedV4l2Buffers = 0;
326 uint32_t mMaxV4L2BufferSize = 0;
322 327
323 // Not protected by mLock (but might be used when mLock is locked) 328 // Not protected by mLock (but might be used when mLock is locked)
324 sp<OutputThread> mOutputThread; 329 sp<OutputThread> mOutputThread;
325 330
326 // Stream ID -> Camera3Stream cache 331 // Stream ID -> Camera3Stream cache
327 std::unordered_map<int, Stream> mStreamMap; 332 std::unordered_map<int, Stream> mStreamMap;
333
334 std::mutex mInflightFramesLock; // protect mInflightFrames
328 std::unordered_set<uint32_t> mInflightFrames; 335 std::unordered_set<uint32_t> mInflightFrames;
329 336
330 // buffers currently circulating between HAL and camera service 337 // buffers currently circulating between HAL and camera service
@@ -336,6 +343,7 @@ protected:
336 // Stream ID -> circulating buffers map 343 // Stream ID -> circulating buffers map
337 std::map<int, CirculatingBuffers> mCirculatingBuffers; 344 std::map<int, CirculatingBuffers> mCirculatingBuffers;
338 345
346 std::mutex mAfTriggerLock; // protect mAfTrigger
339 bool mAfTrigger = false; 347 bool mAfTrigger = false;
340 348
341 static HandleImporter sHandleImporter; 349 static HandleImporter sHandleImporter;
diff --git a/keymaster/4.0/vts/functional/KeymasterHidlTest.cpp b/keymaster/4.0/vts/functional/KeymasterHidlTest.cpp
index 37d8c425..e266a86e 100644
--- a/keymaster/4.0/vts/functional/KeymasterHidlTest.cpp
+++ b/keymaster/4.0/vts/functional/KeymasterHidlTest.cpp
@@ -462,6 +462,7 @@ void KeymasterHidlTest::CheckTripleDesTestVector(KeyPurpose purpose, BlockMode b
462 auto authset = AuthorizationSetBuilder() 462 auto authset = AuthorizationSetBuilder()
463 .TripleDesEncryptionKey(key.size() * 7) 463 .TripleDesEncryptionKey(key.size() * 7)
464 .BlockMode(block_mode) 464 .BlockMode(block_mode)
465 .Authorization(TAG_NO_AUTH_REQUIRED)
465 .Padding(padding_mode); 466 .Padding(padding_mode);
466 if (iv.size()) authset.Authorization(TAG_CALLER_NONCE); 467 if (iv.size()) authset.Authorization(TAG_CALLER_NONCE);
467 ASSERT_EQ(ErrorCode::OK, ImportKey(authset, KeyFormat::RAW, key)); 468 ASSERT_EQ(ErrorCode::OK, ImportKey(authset, KeyFormat::RAW, key));
@@ -535,7 +536,7 @@ string KeymasterHidlTest::EncryptMessage(const string& message, BlockMode block_
535 EXPECT_EQ(1U, out_params.size()); 536 EXPECT_EQ(1U, out_params.size());
536 auto ivVal = out_params.GetTagValue(TAG_NONCE); 537 auto ivVal = out_params.GetTagValue(TAG_NONCE);
537 EXPECT_TRUE(ivVal.isOk()); 538 EXPECT_TRUE(ivVal.isOk());
538 *iv_out = ivVal.value(); 539 if (ivVal.isOk()) *iv_out = ivVal.value();
539 return ciphertext; 540 return ciphertext;
540} 541}
541 542
diff --git a/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp b/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp
index 602355b7..bc33b2bf 100644
--- a/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp
+++ b/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp
@@ -1819,24 +1819,26 @@ TEST_F(ImportKeyTest, HmacKeySuccess) {
1819} 1819}
1820 1820
1821auto wrapped_key = hex2str( 1821auto wrapped_key = hex2str(
1822 "30820173020100048201006F5C273914D9E7EAB667FE62456A57DE64BED4A57DB3EFBB77E6907C82CC36B0BD12CB8A" 1822 "3082017902010004820100A0E69B1395D382354FC0E7F74AC068C5818279D76D46745C7274997D045BAA8B9763B3F3"
1823 "85F3F8BC08A26C58186DB5C35636063388A04AE5579D3BDC057F9BB0EB6FDDA5E836DBB1F18A4546A64BA06E3D0132" 1823 "09E5E59ECA99273AAAE0A37449DA9B1E67B66EC4E42BB62C25346683A43A9F2ACBCA6D350B25551CC53CE0721D29BE"
1824 "AAA3306676638C786FAF0722E6E4145E0C91B009C422691F9F42F9F179DA93E16E7793DE5960E77A387433F0B43E49" 1824 "90F60686877478F82B3BB111C5EAC0BAE9310D7AD11F5A82948B31C322820F24E20DDB0FBD07D1566DAEAA058D4645"
1825 "3A7CF77ECA25BA724CC02F916D5792CAA76BC0756D3DB5D110D209B8B30285E9653D91FD89E953F351D82ACE1422CC" 1825 "2607352699E1F631D2ABAF60B13E41ED5EDBB90D252331BDB9CDB1B672E871F37CAC009FE9028B3B1E0ACE8F6F0678"
1826 "A146F8BD0C2F4CC32D1F81D894F4650043DB46109869696319A1A011BB003F2EBD8FA20B4A43F3226C1F182A39AE81" 1826 "3F581B860620BDD478969EDE3101AAEFF65C6DB03E143E586167DC87D0CCE39E9119782F7B60A7A1CF2B7EE234E013"
1827 "A35B9B7590A48B6A6874C9CC0EE0CD9528FB908688B4111932DF478CD7A92B50040CD796B02C370F1FA4CC0124F130" 1827 "E3DE6C56F0D51F30C389D31FA37C5F2875ACB44434E82EF40B316C93DE129BA0040CD796B02C370F1FA4CC0124F130"
1828 "280201033023A1083106020100020101A203020120A30402020100A4053103020101A60531030201400420CCD54085" 1828 "2E0201033029A1083106020100020101A203020120A30402020100A4053103020101A6053103020140BF8377020500"
1829 "5F833A5E1480BFD2D36FAF3AEEE15DF5BEABE2691BC82DDE2A7AA91004107CB81BDDCD09E8F4DF575726279F3229"); 1829 "0420CCD540855F833A5E1480BFD2D36FAF3AEEE15DF5BEABE2691BC82DDE2A7AA910041064C9F689C60FF6223AB6E6"
1830 "999E0EB6E5");
1830 1831
1831auto wrapped_key_masked = hex2str( 1832auto wrapped_key_masked = hex2str(
1832 "30820173020100048201009059BB6E48F8036ABE1800D9C74F3DB5F20448F035C2C78AFBCC28AF26581061298CAC78" 1833 "30820179020100048201001EF5320D3C920D7614688A439409ACE4318C48395ABB7247A68671BD4B7156A7773B31A4"
1833 "A8CA5B79721B60B74490555168488ED696C8930D00463C6FC81BF0B6E4E26C93E018D0E3DC8754C6B261E0A7C3A6DA" 1834 "4459B73858625988A312E4D8855138F555678F525E4C52D91444FDC936BE6AEB63FD73FD84201EF46F88A0B622F528"
1834 "1A223EB59ACA8E13348F14B9E944AF3C224906C1ABFE21ADDEE81FC641D45E092C6B0A75A9BA56C05529AE47ECA0D5" 1835 "956C92C9C731EB65BCBC6A03BEAB45959B54A768E2842D2CE174EE542EF2A15DCAA7542F3574BEEB1A991F95439466"
1835 "CD3568501CF04D47391FC695EDE19A3022B347D1BDC6C792A08AA014F87DD4BBD44777B14D7D2273191DDCFE4E8512" 1836 "E1960A9CE9E4CBC77DB23765191E4758C850908BCC74E158B77AB774141F171262C1AC771FDFA2E942F2F7633E97E8"
1836 "EFA677A14E68E5D820C5513331D687C08B6317FA64D404231D05C74CDD9AEB89D253FBE07154B2080CF4ACA5E1EFCB" 1837 "0BD492C3E821361AC6B4F568DE351C816C8C997212C707F728FB3BCAAA796EA6B8E7A80BE010970B380122940277E9"
1837 "53EB193E8A01DD5F9634B65EF9B49899003E245FDA6A3B137FAC1263E55A6E1D040C6D9721D08589581AB49204A330" 1838 "4C5E9288F7CB6878A4C4CC1E83AB85A81FD68E43B14F1F81AD21E0D3545D70EE040C6D9721D08589581AB49204A330"
1838 "280201033023A1083106020100020101A203020120A30402020100A4053103020101A60531030201400420A61C6E24" 1839 "2E0201033029A1083106020100020101A203020120A30402020100A4053103020101A6053103020140BF8377020500"
1839 "7E25B3E6E69AA78EB03C2D4AC20D1F99A9A024A76F35C8E2CAB9B68D04101FF7A0E793B9EE4AECEBB9AC4C545254"); 1840 "0420A61C6E247E25B3E6E69AA78EB03C2D4AC20D1F99A9A024A76F35C8E2CAB9B68D04102560C70109AE67C030F00B"
1841 "98B512A670");
1840 1842
1841auto wrapping_key = hex2str( 1843auto wrapping_key = hex2str(
1842 "308204be020100300d06092a864886f70d0101010500048204a8308204a40201000282010100aec367931d8900ce56" 1844 "308204be020100300d06092a864886f70d0101010500048204a8308204a40201000282010100aec367931d8900ce56"
@@ -3226,11 +3228,10 @@ TEST_F(EncryptionOperationsTest, AesGcmCorruptTag) {
3226 * Verifies that 3DES is basically functional. 3228 * Verifies that 3DES is basically functional.
3227 */ 3229 */
3228TEST_F(EncryptionOperationsTest, TripleDesEcbRoundTripSuccess) { 3230TEST_F(EncryptionOperationsTest, TripleDesEcbRoundTripSuccess) {
3229 std::cout << "Hello" << std::endl;
3230
3231 auto auths = AuthorizationSetBuilder() 3231 auto auths = AuthorizationSetBuilder()
3232 .TripleDesEncryptionKey(168) 3232 .TripleDesEncryptionKey(168)
3233 .BlockMode(BlockMode::ECB) 3233 .BlockMode(BlockMode::ECB)
3234 .Authorization(TAG_NO_AUTH_REQUIRED)
3234 .Padding(PaddingMode::NONE); 3235 .Padding(PaddingMode::NONE);
3235 3236
3236 ASSERT_EQ(ErrorCode::OK, GenerateKey(auths)); 3237 ASSERT_EQ(ErrorCode::OK, GenerateKey(auths));
@@ -3259,6 +3260,7 @@ TEST_F(EncryptionOperationsTest, TripleDesEcbNotAuthorized) {
3259 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder() 3260 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
3260 .TripleDesEncryptionKey(168) 3261 .TripleDesEncryptionKey(168)
3261 .BlockMode(BlockMode::CBC) 3262 .BlockMode(BlockMode::CBC)
3263 .Authorization(TAG_NO_AUTH_REQUIRED)
3262 .Padding(PaddingMode::NONE))); 3264 .Padding(PaddingMode::NONE)));
3263 3265
3264 auto inParams = AuthorizationSetBuilder().BlockMode(BlockMode::ECB).Padding(PaddingMode::NONE); 3266 auto inParams = AuthorizationSetBuilder().BlockMode(BlockMode::ECB).Padding(PaddingMode::NONE);
@@ -3274,6 +3276,7 @@ TEST_F(EncryptionOperationsTest, TripleDesEcbPkcs7Padding) {
3274 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder() 3276 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
3275 .TripleDesEncryptionKey(168) 3277 .TripleDesEncryptionKey(168)
3276 .BlockMode(BlockMode::ECB) 3278 .BlockMode(BlockMode::ECB)
3279 .Authorization(TAG_NO_AUTH_REQUIRED)
3277 .Padding(PaddingMode::PKCS7))); 3280 .Padding(PaddingMode::PKCS7)));
3278 3281
3279 for (size_t i = 0; i < 32; ++i) { 3282 for (size_t i = 0; i < 32; ++i) {
@@ -3296,6 +3299,7 @@ TEST_F(EncryptionOperationsTest, TripleDesEcbNoPaddingKeyWithPkcs7Padding) {
3296 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder() 3299 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
3297 .TripleDesEncryptionKey(168) 3300 .TripleDesEncryptionKey(168)
3298 .BlockMode(BlockMode::ECB) 3301 .BlockMode(BlockMode::ECB)
3302 .Authorization(TAG_NO_AUTH_REQUIRED)
3299 .Padding(PaddingMode::NONE))); 3303 .Padding(PaddingMode::NONE)));
3300 for (size_t i = 0; i < 32; ++i) { 3304 for (size_t i = 0; i < 32; ++i) {
3301 auto inParams = 3305 auto inParams =
@@ -3313,6 +3317,7 @@ TEST_F(EncryptionOperationsTest, TripleDesEcbPkcs7PaddingCorrupted) {
3313 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder() 3317 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
3314 .TripleDesEncryptionKey(168) 3318 .TripleDesEncryptionKey(168)
3315 .BlockMode(BlockMode::ECB) 3319 .BlockMode(BlockMode::ECB)
3320 .Authorization(TAG_NO_AUTH_REQUIRED)
3316 .Padding(PaddingMode::PKCS7))); 3321 .Padding(PaddingMode::PKCS7)));
3317 3322
3318 string message = "a"; 3323 string message = "a";
@@ -3443,6 +3448,7 @@ TEST_F(EncryptionOperationsTest, TripleDesCbcRoundTripSuccess) {
3443 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder() 3448 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
3444 .TripleDesEncryptionKey(168) 3449 .TripleDesEncryptionKey(168)
3445 .BlockMode(BlockMode::CBC) 3450 .BlockMode(BlockMode::CBC)
3451 .Authorization(TAG_NO_AUTH_REQUIRED)
3446 .Padding(PaddingMode::NONE))); 3452 .Padding(PaddingMode::NONE)));
3447 // Two-block message. 3453 // Two-block message.
3448 string message = "1234567890123456"; 3454 string message = "1234567890123456";
@@ -3471,6 +3477,7 @@ TEST_F(EncryptionOperationsTest, TripleDesCallerIv) {
3471 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder() 3477 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
3472 .TripleDesEncryptionKey(168) 3478 .TripleDesEncryptionKey(168)
3473 .BlockMode(BlockMode::CBC) 3479 .BlockMode(BlockMode::CBC)
3480 .Authorization(TAG_NO_AUTH_REQUIRED)
3474 .Authorization(TAG_CALLER_NONCE) 3481 .Authorization(TAG_CALLER_NONCE)
3475 .Padding(PaddingMode::NONE))); 3482 .Padding(PaddingMode::NONE)));
3476 string message = "1234567890123456"; 3483 string message = "1234567890123456";
@@ -3505,6 +3512,7 @@ TEST_F(EncryptionOperationsTest, TripleDesCallerNonceProhibited) {
3505 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder() 3512 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
3506 .TripleDesEncryptionKey(168) 3513 .TripleDesEncryptionKey(168)
3507 .BlockMode(BlockMode::CBC) 3514 .BlockMode(BlockMode::CBC)
3515 .Authorization(TAG_NO_AUTH_REQUIRED)
3508 .Padding(PaddingMode::NONE))); 3516 .Padding(PaddingMode::NONE)));
3509 3517
3510 string message = "12345678901234567890123456789012"; 3518 string message = "12345678901234567890123456789012";
@@ -3536,6 +3544,7 @@ TEST_F(EncryptionOperationsTest, TripleDesCbcNotAuthorized) {
3536 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder() 3544 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
3537 .TripleDesEncryptionKey(168) 3545 .TripleDesEncryptionKey(168)
3538 .BlockMode(BlockMode::ECB) 3546 .BlockMode(BlockMode::ECB)
3547 .Authorization(TAG_NO_AUTH_REQUIRED)
3539 .Padding(PaddingMode::NONE))); 3548 .Padding(PaddingMode::NONE)));
3540 // Two-block message. 3549 // Two-block message.
3541 string message = "1234567890123456"; 3550 string message = "1234567890123456";
@@ -3553,6 +3562,7 @@ TEST_F(EncryptionOperationsTest, TripleDesCbcNoPaddingWrongInputSize) {
3553 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder() 3562 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
3554 .TripleDesEncryptionKey(168) 3563 .TripleDesEncryptionKey(168)
3555 .BlockMode(BlockMode::CBC) 3564 .BlockMode(BlockMode::CBC)
3565 .Authorization(TAG_NO_AUTH_REQUIRED)
3556 .Padding(PaddingMode::NONE))); 3566 .Padding(PaddingMode::NONE)));
3557 // Message is slightly shorter than two blocks. 3567 // Message is slightly shorter than two blocks.
3558 string message = "123456789012345"; 3568 string message = "123456789012345";
@@ -3574,6 +3584,7 @@ TEST_F(EncryptionOperationsTest, TripleDesCbcPkcs7Padding) {
3574 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder() 3584 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
3575 .TripleDesEncryptionKey(168) 3585 .TripleDesEncryptionKey(168)
3576 .BlockMode(BlockMode::CBC) 3586 .BlockMode(BlockMode::CBC)
3587 .Authorization(TAG_NO_AUTH_REQUIRED)
3577 .Padding(PaddingMode::PKCS7))); 3588 .Padding(PaddingMode::PKCS7)));
3578 3589
3579 // Try various message lengths; all should work. 3590 // Try various message lengths; all should work.
@@ -3596,6 +3607,7 @@ TEST_F(EncryptionOperationsTest, TripleDesCbcNoPaddingKeyWithPkcs7Padding) {
3596 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder() 3607 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
3597 .TripleDesEncryptionKey(168) 3608 .TripleDesEncryptionKey(168)
3598 .BlockMode(BlockMode::CBC) 3609 .BlockMode(BlockMode::CBC)
3610 .Authorization(TAG_NO_AUTH_REQUIRED)
3599 .Padding(PaddingMode::NONE))); 3611 .Padding(PaddingMode::NONE)));
3600 3612
3601 // Try various message lengths; all should fail. 3613 // Try various message lengths; all should fail.
@@ -3615,6 +3627,7 @@ TEST_F(EncryptionOperationsTest, TripleDesCbcPkcs7PaddingCorrupted) {
3615 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder() 3627 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
3616 .TripleDesEncryptionKey(168) 3628 .TripleDesEncryptionKey(168)
3617 .BlockMode(BlockMode::CBC) 3629 .BlockMode(BlockMode::CBC)
3630 .Authorization(TAG_NO_AUTH_REQUIRED)
3618 .Padding(PaddingMode::PKCS7))); 3631 .Padding(PaddingMode::PKCS7)));
3619 3632
3620 string message = "a"; 3633 string message = "a";
@@ -3645,6 +3658,7 @@ TEST_F(EncryptionOperationsTest, TripleDesCbcIncrementalNoPadding) {
3645 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder() 3658 ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
3646 .TripleDesEncryptionKey(168) 3659 .TripleDesEncryptionKey(168)
3647 .BlockMode(BlockMode::CBC) 3660 .BlockMode(BlockMode::CBC)
3661 .Authorization(TAG_NO_AUTH_REQUIRED)
3648 .Padding(PaddingMode::NONE))); 3662 .Padding(PaddingMode::NONE)));
3649 3663
3650 int increment = 7; 3664 int increment = 7;